Skip to content

Commit

Permalink
Run example pipelines via pytest instead and check abundance output
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Dec 20, 2024
1 parent bab5937 commit c4fc75c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,3 @@ jobs:
run: |
micromamba install pytest
pytest
- name: "Run example: full length"
run: |
python emu abundance example/full_length.fa
- name: "Run example: short-read fwd+rev"
run: |
python emu abundance --type sr example/short_read_f.fq example/short_read_r.fq
- name: "Run example: short-read fwd only"
run:
python emu abundance --type sr example/short_read_f.fq
48 changes: 48 additions & 0 deletions tests/test_emu_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
import subprocess
import os
import pandas as pd


@pytest.mark.parametrize(
"emu_command, abundance_file, expected_abundancies",
[
(
"./emu abundance --db emu_database --output-dir test_results example/full_length.fa",
"test_results/full_length_rel-abundance.tsv",
{
"Sphingobacterium puteale": 0.5,
"Mycobacterium saskatchewanense": 0.25,
"Streptococcus sobrinus": 0.25,
},
),
(
"./emu abundance --db emu_database --output-dir test_results --type sr example/short_read_f.fq",
"test_results/short_read_f_rel-abundance.tsv",
{
"Staphylococcus hominis": 1.0,
},
),
(
"./emu abundance --db emu_database --output-dir test_results --type sr example/short_read_f.fq example/short_read_r.fq",
"test_results/short_read_f-short_read_r_rel-abundance.tsv",
{
"Staphylococcus aureus": 1.0 / 3,
"Salmonella enterica": 1.0 / 3,
"Enterococcus columbae": 1.0 / 3,
},
),
],
)
def test_full_length_example(emu_command, abundance_file, expected_abundancies):
if os.path.exists(abundance_file):
os.remove(abundance_file)

subprocess.check_output(emu_command, shell=True)

assert os.path.exists(abundance_file)

df = abundance_df = pd.read_csv(abundance_file, sep="\t")

for species, expected_abundance in expected_abundancies.items():
assert df[df["species"] == species].iloc[0]["abundance"] == expected_abundance

0 comments on commit c4fc75c

Please sign in to comment.