From a64c04a128d5060326b2ba8c711d745c589b73c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 7 Aug 2026 05:07:28 +0800 Subject: [PATCH] Run the tests on an in-memory store and dispose the engine afterwards Co-Authored-By: Claude Opus 5 (1M context) --- tools/tests/test_build_db.py | 7 ++++--- tools/tests/test_export_llm_input.py | 4 ++-- tools/tests/test_fetch_artists.py | 4 ++-- tools/tests/test_fetch_lyrics.py | 4 ++-- tools/tests/test_models.py | 1 + tools/tests/test_tally_codings.py | 4 ++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/tests/test_build_db.py b/tools/tests/test_build_db.py index 69095d2..d7f2510 100644 --- a/tools/tests/test_build_db.py +++ b/tools/tests/test_build_db.py @@ -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( diff --git a/tools/tests/test_export_llm_input.py b/tools/tests/test_export_llm_input.py index 37dd094..f5c6cf2 100644 --- a/tools/tests/test_export_llm_input.py +++ b/tools/tests/test_export_llm_input.py @@ -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() diff --git a/tools/tests/test_fetch_artists.py b/tools/tests/test_fetch_artists.py index 8441d05..827836f 100644 --- a/tools/tests/test_fetch_artists.py +++ b/tools/tests/test_fetch_artists.py @@ -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", diff --git a/tools/tests/test_fetch_lyrics.py b/tools/tests/test_fetch_lyrics.py index daa5af4..c645350 100644 --- a/tools/tests/test_fetch_lyrics.py +++ b/tools/tests/test_fetch_lyrics.py @@ -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)] diff --git a/tools/tests/test_models.py b/tools/tests/test_models.py index dbfd27d..c36fbb4 100644 --- a/tools/tests/test_models.py +++ b/tools/tests/test_models.py @@ -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) diff --git a/tools/tests/test_tally_codings.py b/tools/tests/test_tally_codings.py index 15f5fb0..2576676 100644 --- a/tools/tests/test_tally_codings.py +++ b/tools/tests/test_tally_codings.py @@ -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()