mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 17:14:20 +01:00
ext/python: Workaround to file permission error
To get more info see: https://github.com/tursodatabase/limbo/actions/runs/14039536389/job/39312362848
This commit is contained in:
@@ -12,27 +12,41 @@ def setup_database():
|
|||||||
db_wal_path = "tests/database.db-wal"
|
db_wal_path = "tests/database.db-wal"
|
||||||
|
|
||||||
# Ensure the database file is created fresh for each test
|
# Ensure the database file is created fresh for each test
|
||||||
if os.path.exists(db_path):
|
try:
|
||||||
os.remove(db_path)
|
if os.path.exists(db_path):
|
||||||
if os.path.exists(db_wal_path):
|
os.remove(db_path)
|
||||||
os.remove(db_wal_path)
|
if os.path.exists(db_wal_path):
|
||||||
|
os.remove(db_wal_path)
|
||||||
|
except PermissionError as e:
|
||||||
|
print(f"Failed to clean up: {e}")
|
||||||
|
|
||||||
# Create a new database file
|
# Create a new database file
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("CREATE TABLE users (id INT PRIMARY KEY, username TEXT)")
|
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, username TEXT)")
|
||||||
cursor.execute("INSERT INTO users VALUES (1, 'alice')")
|
cursor.execute("""
|
||||||
cursor.execute("INSERT INTO users VALUES (2, 'bob')")
|
INSERT INTO users (id, username)
|
||||||
|
SELECT 1, 'alice'
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = 1)
|
||||||
|
""")
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO users (id, username)
|
||||||
|
SELECT 2, 'bob'
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = 2)
|
||||||
|
""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
yield db_path
|
yield db_path
|
||||||
|
|
||||||
# Cleanup after the test
|
# Cleanup after the test
|
||||||
if os.path.exists(db_path):
|
try:
|
||||||
os.remove(db_path)
|
if os.path.exists(db_path):
|
||||||
if os.path.exists(db_wal_path):
|
os.remove(db_path)
|
||||||
os.remove(db_wal_path)
|
if os.path.exists(db_wal_path):
|
||||||
|
os.remove(db_wal_path)
|
||||||
|
except PermissionError as e:
|
||||||
|
print(f"Failed to clean up: {e}")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
@@ -148,7 +162,6 @@ def test_commit(provider):
|
|||||||
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
@pytest.mark.parametrize("provider", ["sqlite3", "limbo"])
|
||||||
def test_with_statement(provider):
|
def test_with_statement(provider):
|
||||||
with connect(provider, "tests/database.db") as conn:
|
with connect(provider, "tests/database.db") as conn:
|
||||||
conn = connect(provider, "tests/database.db")
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT MAX(id) FROM users")
|
cursor.execute("SELECT MAX(id) FROM users")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user