|
4 | 4 | import click.testing as ct
|
5 | 5 |
|
6 | 6 | from bio2zarr import cli
|
7 |
| -from bio2zarr import vcf |
8 | 7 | from bio2zarr import __main__ as main
|
9 | 8 | from bio2zarr import provenance
|
10 | 9 |
|
11 | 10 |
|
12 | 11 | class TestWithMocks:
|
13 |
| - def test_vcf_explode(self): |
| 12 | + @mock.patch("bio2zarr.vcf.explode") |
| 13 | + def test_vcf_explode(self, mocked): |
14 | 14 | runner = ct.CliRunner(mix_stderr=False)
|
15 |
| - with mock.patch("bio2zarr.vcf.explode") as mocked: |
16 |
| - result = runner.invoke( |
17 |
| - cli.vcf2zarr, ["explode", "source", "dest"], catch_exceptions=False |
18 |
| - ) |
19 |
| - assert result.exit_code == 0 |
20 |
| - assert len(result.stdout) == 0 |
21 |
| - assert len(result.stderr) == 0 |
22 |
| - mocked.assert_called_once_with( |
23 |
| - ("source",), |
24 |
| - "dest", |
25 |
| - column_chunk_size=64, |
26 |
| - worker_processes=1, |
27 |
| - show_progress=True, |
28 |
| - ) |
| 15 | + result = runner.invoke( |
| 16 | + cli.vcf2zarr, ["explode", "source", "dest"], catch_exceptions=False |
| 17 | + ) |
| 18 | + assert result.exit_code == 0 |
| 19 | + assert len(result.stdout) == 0 |
| 20 | + assert len(result.stderr) == 0 |
| 21 | + mocked.assert_called_once_with( |
| 22 | + ("source",), |
| 23 | + "dest", |
| 24 | + column_chunk_size=64, |
| 25 | + worker_processes=1, |
| 26 | + show_progress=True, |
| 27 | + ) |
29 | 28 |
|
30 |
| - def test_inspect(self): |
| 29 | + @mock.patch("bio2zarr.vcf.inspect") |
| 30 | + def test_inspect(self, mocked): |
31 | 31 | runner = ct.CliRunner(mix_stderr=False)
|
32 |
| - with mock.patch("bio2zarr.vcf.inspect", return_value={}) as mocked: |
33 |
| - result = runner.invoke( |
34 |
| - cli.vcf2zarr, ["inspect", "path"], catch_exceptions=False |
35 |
| - ) |
36 |
| - assert result.exit_code == 0 |
37 |
| - assert result.stdout == "\n" |
38 |
| - assert len(result.stderr) == 0 |
39 |
| - mocked.assert_called_once_with("path") |
| 32 | + result = runner.invoke( |
| 33 | + cli.vcf2zarr, ["inspect", "path"], catch_exceptions=False |
| 34 | + ) |
| 35 | + assert result.exit_code == 0 |
| 36 | + assert result.stdout == "\n" |
| 37 | + assert len(result.stderr) == 0 |
| 38 | + mocked.assert_called_once_with("path") |
40 | 39 |
|
41 |
| - def test_mkschema(self): |
| 40 | + @mock.patch("bio2zarr.vcf.mkschema") |
| 41 | + def test_mkschema(self, mocked): |
42 | 42 | runner = ct.CliRunner(mix_stderr=False)
|
43 |
| - with mock.patch("bio2zarr.vcf.mkschema") as mocked: |
44 |
| - result = runner.invoke( |
45 |
| - cli.vcf2zarr, ["mkschema", "path"], catch_exceptions=False |
46 |
| - ) |
47 |
| - assert result.exit_code == 0 |
48 |
| - assert len(result.stdout) == 0 |
49 |
| - assert len(result.stderr) == 0 |
50 |
| - # TODO figure out how to test that we call it with stdout from |
51 |
| - # the CliRunner |
52 |
| - # mocked.assert_called_once_with("path", stdout) |
53 |
| - mocked.assert_called_once() |
54 |
| - |
55 |
| - # @mock.patch.object(vcf, "encode", spec=vcf.encode) |
56 |
| - @mock.patch("bio2zarr.cli.vcf.encode") |
| 43 | + result = runner.invoke( |
| 44 | + cli.vcf2zarr, ["mkschema", "path"], catch_exceptions=False |
| 45 | + ) |
| 46 | + assert result.exit_code == 0 |
| 47 | + assert len(result.stdout) == 0 |
| 48 | + assert len(result.stderr) == 0 |
| 49 | + # TODO figure out how to test that we call it with stdout from |
| 50 | + # the CliRunner |
| 51 | + # mocked.assert_called_once_with("path", stdout) |
| 52 | + mocked.assert_called_once() |
| 53 | + |
| 54 | + @mock.patch("bio2zarr.vcf.encode") |
57 | 55 | def test_encode(self, mocked):
|
58 |
| - # print("vcf", vcf) |
59 |
| - # print(vcf.encode) |
60 | 56 | runner = ct.CliRunner(mix_stderr=False)
|
61 | 57 | result = runner.invoke(
|
62 | 58 | cli.vcf2zarr, ["encode", "if_path", "zarr_path"], catch_exceptions=False
|
63 | 59 | )
|
64 |
| - # assert result.exit_code == 0 |
65 |
| - # assert len(result.stdout) == 0 |
66 |
| - # assert len(result.stderr) == 0 |
67 |
| - # mocked.assert_called_once_with( |
68 |
| - # "if_path", |
69 |
| - # "zarr_path", |
70 |
| - # None, |
71 |
| - # variants_chunk_size=None, |
72 |
| - # samples_chunk_size=None, |
73 |
| - # max_v_chunks=None, |
74 |
| - # worker_processes=1, |
75 |
| - # max_memory=None, |
76 |
| - # show_progress=True, |
77 |
| - # ) |
| 60 | + assert result.exit_code == 0 |
| 61 | + assert len(result.stdout) == 0 |
| 62 | + assert len(result.stderr) == 0 |
| 63 | + mocked.assert_called_once_with( |
| 64 | + "if_path", |
| 65 | + "zarr_path", |
| 66 | + None, |
| 67 | + variants_chunk_size=None, |
| 68 | + samples_chunk_size=None, |
| 69 | + max_v_chunks=None, |
| 70 | + worker_processes=1, |
| 71 | + max_memory=None, |
| 72 | + show_progress=True, |
| 73 | + ) |
78 | 74 |
|
79 |
| - def test_convert_vcf(self): |
| 75 | + @mock.patch("bio2zarr.vcf.convert") |
| 76 | + def test_convert_vcf(self, mocked): |
80 | 77 | runner = ct.CliRunner(mix_stderr=False)
|
81 |
| - with mock.patch("bio2zarr.vcf.convert") as mocked: |
82 |
| - result = runner.invoke( |
83 |
| - cli.vcf2zarr, |
84 |
| - ["convert", "vcf_path", "zarr_path"], |
85 |
| - catch_exceptions=False, |
86 |
| - ) |
87 |
| - assert result.exit_code == 0 |
88 |
| - assert len(result.stdout) == 0 |
89 |
| - assert len(result.stderr) == 0 |
90 |
| - mocked.assert_called_once_with( |
91 |
| - ("vcf_path",), |
92 |
| - "zarr_path", |
93 |
| - variants_chunk_size=None, |
94 |
| - samples_chunk_size=None, |
95 |
| - worker_processes=1, |
96 |
| - show_progress=True, |
97 |
| - ) |
| 78 | + result = runner.invoke( |
| 79 | + cli.vcf2zarr, |
| 80 | + ["convert", "vcf_path", "zarr_path"], |
| 81 | + catch_exceptions=False, |
| 82 | + ) |
| 83 | + assert result.exit_code == 0 |
| 84 | + assert len(result.stdout) == 0 |
| 85 | + assert len(result.stderr) == 0 |
| 86 | + mocked.assert_called_once_with( |
| 87 | + ("vcf_path",), |
| 88 | + "zarr_path", |
| 89 | + variants_chunk_size=None, |
| 90 | + samples_chunk_size=None, |
| 91 | + worker_processes=1, |
| 92 | + show_progress=True, |
| 93 | + ) |
98 | 94 |
|
99 |
| - def test_validate(self): |
| 95 | + @mock.patch("bio2zarr.vcf.validate") |
| 96 | + def test_validate(self, mocked): |
100 | 97 | runner = ct.CliRunner(mix_stderr=False)
|
101 |
| - with mock.patch("bio2zarr.vcf.validate") as mocked: |
102 |
| - result = runner.invoke( |
103 |
| - cli.vcf2zarr, |
104 |
| - ["validate", "vcf_path", "zarr_path"], |
105 |
| - catch_exceptions=False, |
106 |
| - ) |
107 |
| - assert result.exit_code == 0 |
108 |
| - assert len(result.stdout) == 0 |
109 |
| - assert len(result.stderr) == 0 |
110 |
| - mocked.assert_called_once_with( |
111 |
| - "vcf_path", |
112 |
| - "zarr_path", |
113 |
| - show_progress=True, |
114 |
| - ) |
| 98 | + result = runner.invoke( |
| 99 | + cli.vcf2zarr, |
| 100 | + ["validate", "vcf_path", "zarr_path"], |
| 101 | + catch_exceptions=False, |
| 102 | + ) |
| 103 | + assert result.exit_code == 0 |
| 104 | + assert len(result.stdout) == 0 |
| 105 | + assert len(result.stderr) == 0 |
| 106 | + mocked.assert_called_once_with( |
| 107 | + "vcf_path", |
| 108 | + "zarr_path", |
| 109 | + show_progress=True, |
| 110 | + ) |
115 | 111 |
|
116 |
| - def test_convert_plink(self): |
| 112 | + @mock.patch("bio2zarr.plink.convert") |
| 113 | + def test_convert_plink(self, mocked): |
117 | 114 | runner = ct.CliRunner(mix_stderr=False)
|
118 |
| - with mock.patch("bio2zarr.plink.convert") as mocked: |
119 |
| - result = runner.invoke( |
120 |
| - cli.plink2zarr, ["convert", "in", "out"], catch_exceptions=False |
121 |
| - ) |
122 |
| - assert result.exit_code == 0 |
123 |
| - assert len(result.stdout) == 0 |
124 |
| - assert len(result.stderr) == 0 |
125 |
| - mocked.assert_called_once_with( |
126 |
| - "in", |
127 |
| - "out", |
128 |
| - worker_processes=1, |
129 |
| - samples_chunk_size=None, |
130 |
| - variants_chunk_size=None, |
131 |
| - show_progress=True, |
132 |
| - ) |
133 |
| - |
| 115 | + result = runner.invoke( |
| 116 | + cli.plink2zarr, ["convert", "in", "out"], catch_exceptions=False |
| 117 | + ) |
| 118 | + assert result.exit_code == 0 |
| 119 | + assert len(result.stdout) == 0 |
| 120 | + assert len(result.stderr) == 0 |
| 121 | + mocked.assert_called_once_with( |
| 122 | + "in", |
| 123 | + "out", |
| 124 | + worker_processes=1, |
| 125 | + samples_chunk_size=None, |
| 126 | + variants_chunk_size=None, |
| 127 | + show_progress=True, |
| 128 | + ) |
134 | 129 |
|
135 | 130 |
|
136 | 131 | class TestVcfPartition:
|
|
0 commit comments