Run the tests on an in-memory store and dispose the engine afterwards

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-17 22:38:36 +08:00
co-authored by Claude Opus 5
parent c3e48aac56
commit a64c04a128
6 changed files with 13 additions and 11 deletions
+4 -3
View File
@@ -269,11 +269,11 @@ class TestBuildDB(unittest.TestCase):
self.__dir / "artists_wikidata.csv"
self.__codings: Path = self.__dir / "codings.csv"
self.__write_chart(self.CHART_CSV)
url: str = f"sqlite:///{self.__dir}/store.sqlite3"
config.set_settings(config.Settings(
SQLALCHEMY_DATABASE_URL=url,
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
patchers: list[Any] = [
mock.patch.object(build_db, "ds", self.__ds),
mock.patch.object(
@@ -540,7 +540,8 @@ class TestBuildDB(unittest.TestCase):
def test_first_run_on_fresh_store(self) -> None:
"""Test that a build on a fresh store creates the tables."""
self.assertFalse((self.__dir / "store.sqlite3").exists())
self.assertEqual(
sa.inspect(self.__ds.engine).get_table_names(), [])
self.assertEqual(self.__run_build()[0], 0)
session: Session = self.__session()
self.assertEqual(
+2 -2
View File
@@ -35,11 +35,11 @@ class TestExportLlmInput(unittest.TestCase):
self.addCleanup(tmp.cleanup)
self.__dir: Path = Path(tmp.name)
self.__output: Path = self.__dir / "llm-input.jsonl"
url: str = f"sqlite:///{self.__dir}/store.sqlite3"
config.set_settings(config.Settings(
SQLALCHEMY_DATABASE_URL=url,
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
patcher: Any = mock.patch.object(
export_llm_input, "ds", self.__ds)
patcher.start()
+2 -2
View File
@@ -38,11 +38,11 @@ class TestFetchArtists(unittest.TestCase):
self.__dir: Path = Path(tmp.name)
self.__snapshot: Path = \
self.__dir / "artists_wikidata.csv"
url: str = f"sqlite:///{self.__dir}/store.sqlite3"
config.set_settings(config.Settings(
SQLALCHEMY_DATABASE_URL=url,
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
patchers: list[Any] = [
mock.patch.object(fetch_artists, "ds", self.__ds),
mock.patch.object(fetch_artists, "SLEEP_SECONDS",
+2 -2
View File
@@ -43,11 +43,11 @@ class TestFetchLyrics(unittest.TestCase):
self.__lyrics: Path = self.__dir / "lyrics"
self.__provenance: Path = \
self.__dir / "lyrics-provenance.csv"
url: str = f"sqlite:///{self.__dir}/store.sqlite3"
config.set_settings(config.Settings(
SQLALCHEMY_DATABASE_URL=url,
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
patchers: list[Any] = [
mock.patch.object(fetch_lyrics, "ds", self.__ds),
mock.patch.object(fetch_lyrics, "SLEEP_SECONDS", 0.0)]
+1
View File
@@ -30,6 +30,7 @@ class TestModels(unittest.TestCase):
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
Base.metadata.create_all(self.__ds.engine)
self.__session: Session = self.__ds.get_db()
self.addCleanup(self.__session.close)
+2 -2
View File
@@ -38,11 +38,11 @@ class TestTallyCodings(unittest.TestCase):
self.__runs.append(run_dir)
self.__output_csv: Path \
= self.__dir / "results" / "codings.csv"
url: str = f"sqlite:///{self.__dir}/store.sqlite3"
config.set_settings(config.Settings(
SQLALCHEMY_DATABASE_URL=url,
SQLALCHEMY_DATABASE_URL="sqlite://",
ANTHROPIC_API_KEY="test-key"))
self.__ds: DataSource = DataSource()
self.addCleanup(self.__ds.engine.dispose)
patcher: Any = mock.patch.object(
tally_codings, "ds", self.__ds)
patcher.start()