Skip to content

Commit cad0c41

Browse files
committed
Cli tests
1 parent fbb0d79 commit cad0c41

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

bio2zarr/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ def explode(vcfs, out_path, verbose, worker_processes, column_chunk_size):
8484
@click.option("-n", "--target_num_partitions", type=int, required=True)
8585
@verbose
8686
@worker_processes
87-
def explode_init(vcfs, out_path, num_partitions, verbose, worker_processes):
87+
def explode_init(vcfs, out_path, target_num_partitions, verbose, worker_processes):
8888
"""
8989
Initial step for parallel conversion of VCF(s) to columnar intermediate format
9090
"""
9191
setup_logging(verbose)
9292
vcf.explode_init(
9393
vcfs,
9494
out_path,
95-
num_partitions=num_partitions,
95+
target_num_partitions=target_num_partitions,
9696
worker_processes=worker_processes,
9797
show_progress=True,
9898
)

bio2zarr/vcf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,17 +1108,17 @@ def explode(
11081108
)
11091109
return PickleChunkedVcf.load(out_path)
11101110

1111-
def explode_init(vcfs, out_path, *, num_partitions=1, worker_processes=1, show_progress=False):
1111+
def explode_init(vcfs, out_path, *, target_num_partitions=1, worker_processes=1, show_progress=False):
11121112
out_path = pathlib.Path(out_path)
11131113
if out_path.exists():
11141114
shutil.rmtree(out_path)
11151115
# Error if num_parts less than number of files
1116-
if num_partitions < len(vcfs):
1116+
if target_num_partitions < len(vcfs):
11171117
raise ValueError("num_partitions must be greater than or equal to the number of input VCFs")
11181118
return PickleChunkedVcf.convert_init(
11191119
vcfs,
11201120
out_path,
1121-
num_partitions=num_partitions,
1121+
num_partitions=target_num_partitions,
11221122
worker_processes=worker_processes,
11231123
show_progress=show_progress,
11241124
)

tests/test_cli.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ def test_vcf_explode(self, mocked):
2626
show_progress=True,
2727
)
2828

29+
def test_vcf_explode_init(self):
30+
runner = ct.CliRunner(mix_stderr=False)
31+
with mock.patch("bio2zarr.vcf.explode_init") as mocked:
32+
result = runner.invoke(
33+
cli.vcf2zarr, ["explode-init", "source", "dest", "-n", "5"], catch_exceptions=False
34+
)
35+
assert result.exit_code == 0
36+
assert len(result.stdout) == 0
37+
assert len(result.stderr) == 0
38+
mocked.assert_called_once_with(
39+
("source",),
40+
"dest",
41+
target_num_partitions=5,
42+
worker_processes=1,
43+
show_progress=True,
44+
)
45+
46+
def test_vcf_explode_partition_count(self):
47+
runner = ct.CliRunner(mix_stderr=False)
48+
with mock.patch("bio2zarr.vcf.explode_partition_count", return_value=5) as mocked:
49+
result = runner.invoke(
50+
cli.vcf2zarr, ["explode-partition-count", "path"], catch_exceptions=False
51+
)
52+
assert result.exit_code == 0
53+
assert result.stdout == "5\n"
54+
assert len(result.stderr) == 0
55+
mocked.assert_called_once_with("path")
56+
57+
def test_vcf_explode_slice(self):
58+
runner = ct.CliRunner(mix_stderr=False)
59+
with mock.patch("bio2zarr.vcf.explode_slice") as mocked:
60+
result = runner.invoke(
61+
cli.vcf2zarr, ["explode-slice", "path", "-s", "1", "-e", "2"], catch_exceptions=False
62+
)
63+
assert result.exit_code == 0
64+
assert len(result.stdout) == 0
65+
assert len(result.stderr) == 0
66+
mocked.assert_called_once_with(
67+
"path",
68+
1,
69+
2,
70+
column_chunk_size=64,
71+
worker_processes=1,
72+
show_progress=True,
73+
)
74+
75+
def test_vcf_explode_finalise(self):
76+
runner = ct.CliRunner(mix_stderr=False)
77+
with mock.patch("bio2zarr.vcf.explode_finalise") as mocked:
78+
result = runner.invoke(
79+
cli.vcf2zarr, ["explode-finalise", "path"], catch_exceptions=False
80+
)
81+
assert result.exit_code == 0
82+
assert len(result.stdout) == 0
83+
assert len(result.stderr) == 0
84+
mocked.assert_called_once_with("path")
85+
2986
@mock.patch("bio2zarr.vcf.inspect")
3087
def test_inspect(self, mocked):
3188
runner = ct.CliRunner(mix_stderr=False)

0 commit comments

Comments
 (0)