Skip to content

Commit

Permalink
add cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
endast committed Nov 14, 2023
1 parent fa645a5 commit fd05001
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 4 deletions.
6 changes: 3 additions & 3 deletions assets/images/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion fake_vcf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def main(


if __name__ == "__main__":
app()
app() # pragma: no cover
108 changes: 108 additions & 0 deletions tests/test_example/test_vcf_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import pytest
from typer.testing import CliRunner

from fake_vcf import version
from fake_vcf.__main__ import app
from tests.test_example.test_vcf_fake import NR_NON_SAMPLE_COL

runner = CliRunner()


def test_app_no_input():
result = runner.invoke(app, [])
assert result.exit_code == 0
assert "source=VCFake" in result.stdout


def test_app_no_compression_output(tmp_path):
output_file = tmp_path / "example.vcf"
result = runner.invoke(app, ["-o", output_file])
assert result.exit_code == 0
assert output_file.exists()
assert "No compression" in result.stdout


def test_app_compression(tmp_path):
output_file = tmp_path / "example.vcf.gz"
result = runner.invoke(app, ["-o", output_file])
assert result.exit_code == 0
assert output_file.exists()
assert "Using compression" in result.stdout


def test_app_seed_same(tmp_path):
result_1 = runner.invoke(app, ["--seed", "42"])
result_2 = runner.invoke(app, ["--seed", "42"])
assert result_1.exit_code == 0
assert result_2.exit_code == 0
assert result_1.stdout == result_2.stdout


def test_app_seed_differ(tmp_path):
result_1 = runner.invoke(app, ["--seed", "42"])
result_2 = runner.invoke(app, ["--seed", "1337"])
assert result_1.exit_code == 0
assert result_2.exit_code == 0
assert result_1.stdout != result_2.stdout


def test_app_version(tmp_path):
result = runner.invoke(app, ["-v"])
assert result.exit_code == 0
assert version in result.stdout


@pytest.mark.parametrize(
("chr",),
[
*[(f"chr{c}",) for c in range(1, 22)],
],
)
def test_app_chr_flag(chr):
result = runner.invoke(app, ["-c", chr])
assert result.exit_code == 0
assert chr in result.stdout


@pytest.mark.parametrize(
("prefix",),
[
("BAM",),
("SAM",),
("MAM",),
("wham",),
("tapir",),
],
)
def test_app_sample_prefix_flag(prefix):
result = runner.invoke(app, ["-p", prefix])
assert result.exit_code == 0
assert f"{prefix}0000" in result.stdout


@pytest.mark.parametrize(
("expected_rows",),
[
*[(r,) for r in range(1, 100, 10)],
],
)
def test_app_nr_rows(expected_rows):
result = runner.invoke(app, ["-r", f"{expected_rows}"])
row_count = len([r for r in result.stdout.split("\n") if r.startswith("chr1")])
assert result.exit_code == 0
assert row_count == expected_rows


@pytest.mark.parametrize(
("expected_sample_count",),
[
*[(r,) for r in range(1, 100, 10)],
],
)
def test_app_nr_samples(expected_sample_count):
result = runner.invoke(app, ["-s", f"{expected_sample_count}"])
sample_count = len(
[r for r in result.stdout.split("\n") if r.startswith("chr1")][0].split("\t")
)
assert result.exit_code == 0
assert sample_count == expected_sample_count + NR_NON_SAMPLE_COL

0 comments on commit fd05001

Please sign in to comment.