Skip to content

Commit

Permalink
TST: added test fo closing AlignDb
Browse files Browse the repository at this point in the history
[CHANGED] remove effort to better handle garbage collection
    error as it was invalid
  • Loading branch information
GavinHuttley committed Jan 17, 2025
1 parent 19a8128 commit 3818b4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/ensembl_tui/_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ def get_distinct(self, field: str) -> list[str]:
def num_records(self) -> int:
return self.conn.sql(f"SELECT COUNT(*) from {self._tables[0]}").fetchone()[0]

def close(self) -> None:
"""closes duckdb and h5py storage"""
if self.gap_store:
self.gap_store.close()
self.conn.close()


def get_alignment(
align_db: AlignDb,
Expand Down
2 changes: 0 additions & 2 deletions src/ensembl_tui/_storage_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ def close(self) -> None:
"""closes the hdf5 file"""
# hdf5 dumps content to stdout if resource already closed, so
# we trap that here, and capture expected exceptions raised in the process
if "open" not in locals():
return
with (
open(os.devnull, "w") as devnull, # noqa: PTH123
contextlib.redirect_stderr(devnull),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,9 @@ def test_aligndb_post_init_failure(tmp_path):
outfile.write_text("blah")
with pytest.raises(OSError):
eti_align.AlignDb(source="/non/existent/directory")


def test_aligndb_close(db_align):
db_align.close()
with pytest.raises(duckdb.duckdb.ConnectionException):
db_align.num_records()

0 comments on commit 3818b4a

Please sign in to comment.