|
| 1 | +import zipfile |
| 2 | +import shutil |
| 3 | +import subprocess |
| 4 | +import pytest |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def demo_run(tmp_path): |
| 10 | + repo_root = Path(__file__).parent.parent.resolve() |
| 11 | + zip_src = repo_root / "demo_data.zip" |
| 12 | + if not zip_src.exists(): |
| 13 | + pytest.skip("demo_data.zip not found") |
| 14 | + |
| 15 | + local_zip = tmp_path / "demo_data.zip" |
| 16 | + shutil.copy(zip_src, local_zip) |
| 17 | + with zipfile.ZipFile(local_zip, "r") as z: |
| 18 | + z.extractall(tmp_path) |
| 19 | + |
| 20 | + demo_data_dir = tmp_path / "demo_data" |
| 21 | + run_dir = tmp_path / "demo_run" |
| 22 | + run_dir.mkdir() |
| 23 | + (demo_data_dir / "kreports").rename(run_dir / "kreports") |
| 24 | + |
| 25 | + return {"run_dir": run_dir} |
| 26 | + |
| 27 | + |
| 28 | +def test_full_pipeline_end_to_end(demo_run): |
| 29 | + run_dir = demo_run["run_dir"] |
| 30 | + kreports_path = run_dir / "kreports" |
| 31 | + |
| 32 | + # 1. Run KrakenParser |
| 33 | + cmd = ["KrakenParser", "--complete", "-i", str(kreports_path)] |
| 34 | + result = subprocess.run(cmd, capture_output=True, text=True) |
| 35 | + assert result.returncode == 0, f"Pipeline failed:\n{result.stderr}" |
| 36 | + |
| 37 | + # 2. Assert each rank‐level CSV exists and is non‐empty |
| 38 | + ranks = ["phylum", "class", "order", "family", "genus", "species"] |
| 39 | + for rank in ranks: |
| 40 | + csv_path = run_dir / "counts" / "csv" / f"counts_{rank}.csv" |
| 41 | + assert csv_path.exists(), f"Missing counts_{rank}.csv" |
| 42 | + assert csv_path.stat().st_size > 0, f"counts_{rank}.csv is empty" |
| 43 | + |
| 44 | + # 3. Assert relative‐abundance CSVs exist and are non‐empty |
| 45 | + rel_dir = run_dir / "counts" / "csv_relabund" |
| 46 | + assert rel_dir.exists(), "csv_relabund directory is missing" |
| 47 | + rel_species = rel_dir / "counts_species.csv" |
| 48 | + assert rel_species.exists(), "Missing counts_species.csv in csv_relabund" |
| 49 | + assert rel_species.stat().st_size > 0, "counts_species.csv is empty" |
0 commit comments