mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 17:14:20 +01:00
tests/python/writes: use tempfile instead of permanent file
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
from cli_tests.test_limbo_cli import TestLimboShell
|
from cli_tests.test_limbo_cli import TestLimboShell
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from cli_tests import console
|
from cli_tests import console
|
||||||
@@ -14,7 +15,7 @@ class InsertTest(BaseModel):
|
|||||||
blob_size: int = 1024**2
|
blob_size: int = 1024**2
|
||||||
vals: int = 100
|
vals: int = 100
|
||||||
has_blob: bool = True
|
has_blob: bool = True
|
||||||
db_path: str = "testing/writes.db"
|
db_path: str = ""
|
||||||
|
|
||||||
def run(self, limbo: TestLimboShell):
|
def run(self, limbo: TestLimboShell):
|
||||||
zero_blob = "0" * self.blob_size * 2
|
zero_blob = "0" * self.blob_size * 2
|
||||||
@@ -135,21 +136,22 @@ def main():
|
|||||||
tests = blob_tests()
|
tests = blob_tests()
|
||||||
for test in tests:
|
for test in tests:
|
||||||
console.info(test)
|
console.info(test)
|
||||||
db_path = test.db_path
|
with tempfile.NamedTemporaryFile(suffix='.db') as tmp:
|
||||||
|
test.db_path = tmp.name
|
||||||
try:
|
try:
|
||||||
# Use with syntax to automatically close shell on error
|
# Use with syntax to automatically close shell on error
|
||||||
with TestLimboShell("") as limbo:
|
with TestLimboShell("") as limbo:
|
||||||
limbo.execute_dot(f".open {db_path}")
|
limbo.execute_dot(f".open {test.db_path}")
|
||||||
test.run(limbo)
|
test.run(limbo)
|
||||||
|
|
||||||
test.test_compat()
|
test.test_compat()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.error(f"Test FAILED: {e}")
|
console.error(f"Test FAILED: {e}")
|
||||||
cleanup(db_path)
|
cleanup(test.db_path)
|
||||||
exit(1)
|
exit(1)
|
||||||
# delete db after every compat test so we we have fresh db for next test
|
# delete db after every compat test so we we have fresh db for next test
|
||||||
cleanup(db_path)
|
cleanup(test.db_path)
|
||||||
console.info("All tests passed successfully.")
|
console.info("All tests passed successfully.")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user