Skip to content

Commit 37d618a

Browse files
Merge pull request #36 from jeromekelleher/cli-testing
Start on cli testing
2 parents 258d83f + 313516d commit 37d618a

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

bio2zarr/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def explode(vcfs, out_path, verbose, worker_processes, column_chunk_size):
5050
@verbose
5151
def summarise(columnarised, verbose):
5252
setup_logging(verbose)
53-
pcvcf = vcf.PickleChunkedVcf.load(columnarised)
54-
data = pcvcf.summary_table()
53+
data = vcf.summarise(columnarised)
5554
click.echo(tabulate.tabulate(data, headers="keys"))
5655

5756

bio2zarr/vcf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ def explode(
879879
)
880880

881881

882+
def summarise(columnarised):
883+
pcvcf = vcf.PickleChunkedVcf.load(columnarised)
884+
return pcvcf.summary_table()
885+
886+
882887
@dataclasses.dataclass
883888
class ZarrColumnSpec:
884889
# TODO change to "variable_name"

tests/test_cli.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1+
from unittest import mock
2+
13
import click.testing as ct
24

35
from bio2zarr import cli
46

5-
# NOTE just putting things together here to see what works.
6-
# Probably want to mock the module functions here to
7-
# avoid testing any real functionality.
8-
def test_vcf_summarise():
9-
runner = ct.CliRunner()
10-
result = runner.invoke(cli.vcf2zarr, "summarise", "filename")
11-
# FIXME not testing anything!
7+
class TestWithMocks:
8+
9+
def test_vcf_explode(self):
10+
runner = ct.CliRunner(mix_stderr=False)
11+
with mock.patch("bio2zarr.vcf.explode") as mocked:
12+
result = runner.invoke(
13+
cli.vcf2zarr, ["explode", "source", "dest"], catch_exceptions=False
14+
15+
)
16+
assert result.exit_code == 0
17+
assert len(result.stdout) == 0
18+
assert len(result.stderr) == 0
19+
mocked.assert_called_once_with(
20+
("source",),
21+
"dest",
22+
column_chunk_size=64,
23+
worker_processes=1,
24+
show_progress=True,
25+
)
26+
27+
def test_summarise(self):
28+
runner = ct.CliRunner(mix_stderr=False)
29+
with mock.patch("bio2zarr.vcf.summarise", return_value={}) as mocked:
30+
result = runner.invoke(
31+
cli.vcf2zarr, ["summarise", "path"], catch_exceptions=False
32+
33+
)
34+
assert result.exit_code == 0
35+
assert result.stdout == "\n"
36+
assert len(result.stderr) == 0
37+
mocked.assert_called_once_with("path")
38+

0 commit comments

Comments
 (0)