diff options
| author | Arun Isaac | 2026-08-19 03:13:14 +0100 |
|---|---|---|
| committer | Arun Isaac | 2026-08-21 04:03:21 +0100 |
| commit | 44c75535f87b7db2f833b581c9c17671246631a9 (patch) | |
| tree | b467a9046008da63f60c3bc925a7d8078dbca744 | |
| parent | 715eb5918a3c8b9088a03e78fda64efce39c4daf (diff) | |
| download | domagi-44c75535f87b7db2f833b581c9c17671246631a9.tar.gz domagi-44c75535f87b7db2f833b581c9c17671246631a9.tar.lz domagi-44c75535f87b7db2f833b581c9c17671246631a9.zip | |
Build duckdb database only once in a setup fixture.
| -rw-r--r-- | tests/test_domagi.py | 255 |
1 files changed, 118 insertions, 137 deletions
diff --git a/tests/test_domagi.py b/tests/test_domagi.py index 61b8e0b..1134713 100644 --- a/tests/test_domagi.py +++ b/tests/test_domagi.py @@ -52,29 +52,53 @@ def assert_gfa_equal(expected, actual): assert read_gfa_file(expected) == read_gfa_file(actual) -@pytest.mark.parametrize("test_data_file, chop_to, expected_output", - [(Path("test-data/test3.gfa"), +def build_db(test_data_file, duckdb_path): + runner = CliRunner() + result = runner.invoke(main, ["build", + "--gfa", test_data_file, + "--out", duckdb_path]) + assert result.exit_code == 0 + return duckdb_path + +@pytest.fixture(scope="session") +def domagi_db_test1(tmp_path_factory): + return build_db(Path("test-data/test1.gfa"), + tmp_path_factory.mktemp("db") / "test1.db") + +@pytest.fixture(scope="session") +def domagi_db_test2(tmp_path_factory): + return build_db(Path("test-data/test2.gfa"), + tmp_path_factory.mktemp("db") / "test2.db") + +@pytest.fixture(scope="session") +def domagi_db_test3(tmp_path_factory): + return build_db(Path("test-data/test3.gfa"), + tmp_path_factory.mktemp("db") / "test3.db") + +@pytest.fixture(scope="session") +def domagi_db_testcrush(tmp_path_factory): + return build_db(Path("test-data/test-crush.gfa"), + tmp_path_factory.mktemp("db") / "test-crush.db") + +@pytest.mark.parametrize("domagi_db_name, chop_to, expected_output", + [("domagi_db_test3", 1, Path("test-data/expected-output/test3-chop-1.gfa")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", 2, Path("test-data/expected-output/test3-chop-2.gfa")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", 3, Path("test-data/expected-output/test3-chop-3.gfa")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", 4, Path("test-data/expected-output/test3-chop-4.gfa"))]) -def test_domagi_chop(tmp_path, test_data_file, chop_to, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" - output_duckdb_path = tmp_path / f"{test_data_file.stem}-output.db" +def test_domagi_chop(tmp_path, request, domagi_db_name, chop_to, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) + output_duckdb_path = tmp_path / f"{domagi_db.stem}-output.db" runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["chop", - "--db", duckdb_path, + "--db", domagi_db, "--chop-to", chop_to, "--out", output_duckdb_path]) assert result.exit_code == 0 @@ -85,46 +109,38 @@ def test_domagi_chop(tmp_path, test_data_file, chop_to, expected_output): with open(expected_output) as file: assert_gfa_equal(file, io.StringIO(result.stdout)) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test-crush.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_testcrush", Path("test-data/expected-output/test-crush.gfa"))]) -def test_domagi_crush(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" - crushed_duckdb_path = tmp_path / f"{test_data_file.stem}-crushed.db" +def test_domagi_crush(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) + output_duckdb_path = tmp_path / f"{domagi_db.stem}-output.db" runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["crush", - "--db", duckdb_path, - "--out", crushed_duckdb_path]) + "--db", domagi_db, + "--out", output_duckdb_path]) assert result.exit_code == 0 result = runner.invoke(main, ["view", "--to-gfa", - "--db", crushed_duckdb_path]) + "--db", output_duckdb_path]) assert result.exit_code == 0 with open(expected_output) as file: assert_gfa_equal(file, io.StringIO(result.stdout)) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-depth")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-depth")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-depth"))]) -def test_domagi_depth(tmp_path, test_data_file, expected_output): +def test_domagi_depth(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) expected = (pd.read_csv(expected_output, sep="\t") .sort_values(by="#path", ignore_index=True)) - duckdb_path = tmp_path / f"{test_data_file.stem}.db" runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["depth", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 assert_frame_equal(expected, pd.read_csv(io.StringIO(result.stdout), @@ -136,7 +152,7 @@ def test_domagi_depth(tmp_path, test_data_file, expected_output): per_path_expected = pd.DataFrame([row]).reset_index(drop=True) path = row["#path"] result = runner.invoke(main, ["depth", - "--db", duckdb_path, + "--db", domagi_db, "--path", path]) assert result.exit_code == 0 assert_frame_equal(per_path_expected, @@ -146,23 +162,19 @@ def test_domagi_depth(tmp_path, test_data_file, expected_output): ignore_index=True), check_dtype=False) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-depth-graph-depth")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-depth-graph-depth")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-depth-graph-depth"))]) -def test_domagi_depth_graph_depth(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_depth_graph_depth(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["depth", "--graph-depth-table", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 assert_frame_equal(pd.read_csv(expected_output, sep="\t") .sort_values(by="#node.id", @@ -173,51 +185,43 @@ def test_domagi_depth_graph_depth(tmp_path, test_data_file, expected_output): ignore_index=True), check_dtype=False) -@pytest.mark.parametrize("test_data_file, bed_windows, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, bed_windows, expected_output", + [("domagi_db_test1", Path("test-data/test1-bed-windows"), Path("test-data/expected-output/test1-depth-bed-windows")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/test2-bed-windows"), Path("test-data/expected-output/test2-depth-bed-windows")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/test3-bed-windows"), Path("test-data/expected-output/test3-depth-bed-windows"))]) -def test_domagi_depth_bed_windows(tmp_path, test_data_file, bed_windows, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_depth_bed_windows(tmp_path, request, domagi_db_name, bed_windows, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["depth", "--bed-input", bed_windows, - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 assert_frame_equal(pd.read_csv(expected_output, sep="\t"), pd.read_csv(io.StringIO(result.stdout), sep="\t"), check_dtype=False) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-matrix")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-matrix")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-matrix"))]) -def test_domagi_matrix(tmp_path, test_data_file, expected_output): +def test_domagi_matrix(tmp_path, request, domagi_db_name, expected_output): def read_matrix_file(file): return (file.readline().rstrip(), [line.rstrip() for line in sorted(file.readlines())]) - duckdb_path = tmp_path / f"{test_data_file.stem}.db" + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["matrix", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 with open(expected_output) as file: expected_header, expected_lines = read_matrix_file(file) @@ -226,25 +230,21 @@ def test_domagi_matrix(tmp_path, test_data_file, expected_output): assert expected_header == actual_header assert expected_lines == actual_lines -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-overlap")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-overlap")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-overlap"))]) -def test_domagi_overlap(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_overlap(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 - paths = [path for path, in (duckdb.connect(duckdb_path, True) + paths = [path for path, in (duckdb.connect(domagi_db, True) .execute("SELECT name FROM path") .fetchall())] result = runner.invoke(main, ["overlap", - "--db", duckdb_path, + "--db", domagi_db, *sum([["--path", path] for path in paths], [])]) assert result.exit_code == 0 @@ -262,7 +262,7 @@ def test_domagi_overlap(tmp_path, test_data_file, expected_output): for path in paths: print(path, file=file) result = runner.invoke(main, ["overlap", - "--db", duckdb_path, + "--db", domagi_db, "--paths", paths_file]) assert result.exit_code == 0 assert_frame_equal(pd.read_csv(expected_output, sep="\t") @@ -274,23 +274,19 @@ def test_domagi_overlap(tmp_path, test_data_file, expected_output): ignore_index=True), check_dtype=False) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-paths")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-paths")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-paths"))]) -def test_domagi_paths(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_paths(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["paths", "--list-paths", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 assert_frame_equal(pd.read_csv(expected_output, sep="\t", header=None), pd.read_csv(io.StringIO(result.stdout), @@ -298,80 +294,65 @@ def test_domagi_paths(tmp_path, test_data_file, expected_output): header=None), check_dtype=False) -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1.fa")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2.fa")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3.fa"))]) -def test_domagi_paths_fasta(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_paths_fasta(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["paths", "--fasta", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 with open(expected_output) as file: assert result.stdout == file.read() -@pytest.mark.parametrize("test_data_file, expected_output", - [(Path("test-data/test1.gfa"), +@pytest.mark.parametrize("domagi_db_name, expected_output", + [("domagi_db_test1", Path("test-data/expected-output/test1-stats")), - (Path("test-data/test2.gfa"), + ("domagi_db_test2", Path("test-data/expected-output/test2-stats")), - (Path("test-data/test3.gfa"), + ("domagi_db_test3", Path("test-data/expected-output/test3-stats"))]) -def test_domagi_stats(tmp_path, test_data_file, expected_output): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_domagi_stats(tmp_path, request, domagi_db_name, expected_output): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["stats", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 assert_frame_equal(pd.read_csv(expected_output, sep="\t"), pd.read_csv(io.StringIO(result.stdout), sep="\t"), check_dtype=False) -@pytest.mark.parametrize("test_data_file", - [Path("test-data/test1.gfa"), - Path("test-data/test2.gfa"), - Path("test-data/test3.gfa")]) -def test_domagi_view(tmp_path, test_data_file): - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +@pytest.mark.parametrize("domagi_db_name, original_gfa_file", + [("domagi_db_test1", + Path("test-data/test1.gfa")), + ("domagi_db_test2", + Path("test-data/test2.gfa")), + ("domagi_db_test3", + Path("test-data/test3.gfa"))]) +def test_domagi_view(tmp_path, request, domagi_db_name, original_gfa_file): + domagi_db = request.getfixturevalue(domagi_db_name) runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["view", "--to-gfa", - "--db", duckdb_path]) + "--db", domagi_db]) assert result.exit_code == 0 - with open(test_data_file) as expected: + with open(original_gfa_file) as expected: assert_gfa_equal(expected, io.StringIO(result.stdout)) -def test_error_on_missing_paths(tmp_path): - test_data_file = Path("test-data/test1.gfa") - duckdb_path = tmp_path / f"{test_data_file.stem}.db" +def test_error_on_missing_paths(tmp_path, domagi_db_test1): runner = CliRunner() - result = runner.invoke(main, ["build", - "--gfa", test_data_file, - "--out", duckdb_path]) - assert result.exit_code == 0 result = runner.invoke(main, ["depth", - "--db", duckdb_path, + "--db", domagi_db_test1, "--path", "xx"]) assert result.exit_code == 1 and result.output == "Paths ['xx'] not found\n" result = runner.invoke(main, ["overlap", - "--db", duckdb_path, + "--db", domagi_db_test1, "--path", "xx"]) assert result.exit_code == 1 and result.output == "Paths ['xx'] not found\n" |
