1
1
import pathlib
2
- import re
3
2
from unittest import mock
4
3
5
4
import click .testing as ct
@@ -17,7 +16,7 @@ def vcz_path():
17
16
18
17
19
18
def test_version_header (vcz_path ):
20
- output = run_vcztools (f"view { vcz_path } " )
19
+ output , _ = run_vcztools (f"view { vcz_path } " )
21
20
assert output .find ("##vcztools_viewCommand=" ) >= 0
22
21
assert output .find ("Date=" ) >= 0
23
22
@@ -26,20 +25,22 @@ class TestOutput:
26
25
def test_view_unsupported_output (self , tmp_path , vcz_path ):
27
26
bad_output = tmp_path / "output.vcf.gz"
28
27
29
- with pytest . raises (
30
- ValueError ,
31
- match = re . escape (
32
- "Only uncompressed VCF output supported, suffix .gz not allowed"
33
- ),
34
- ):
35
- run_vcztools ( f"view --no-version { vcz_path } -o { bad_output } " )
28
+ _ , vcztools_error = run_vcztools (
29
+ f"view --no-version { vcz_path } -o { bad_output } " , expect_error = True
30
+ )
31
+ assert (
32
+ "Only uncompressed VCF output supported, suffix .gz not allowed"
33
+ in vcztools_error
34
+ )
36
35
37
36
@pytest .mark .parametrize ("suffix" , ["gz" , "bgz" , "bcf" ])
38
37
def test_view_unsupported_output_suffix (self , tmp_path , vcz_path , suffix ):
39
38
bad_output = tmp_path / f"output.vcf.{ suffix } "
40
39
41
- with pytest .raises (ValueError , match = f".{ suffix } not allowed" ):
42
- run_vcztools (f"view --no-version { vcz_path } -o { bad_output } " )
40
+ _ , vcztools_error = run_vcztools (
41
+ f"view --no-version { vcz_path } -o { bad_output } " , expect_error = True
42
+ )
43
+ assert f".{ suffix } not allowed" in vcztools_error
43
44
44
45
def test_view_good_path (self , tmp_path , vcz_path ):
45
46
output_path = tmp_path / "tmp.vcf"
@@ -78,12 +79,16 @@ def test_view_write_pipe(self, tmp_path, vcz_path):
78
79
79
80
def test_excluding_and_including_samples (vcz_path ):
80
81
samples_file_path = pathlib .Path ("tests/data/txt/samples.txt" )
81
- error_message = re . escape ( "vcztools does not support combining -s and -S" )
82
+ error_message = "vcztools does not support combining -s and -S"
82
83
83
- with pytest .raises (AssertionError , match = error_message ):
84
- run_vcztools (f"view { vcz_path } -s NA00001 -S ^{ samples_file_path } " )
85
- with pytest .raises (AssertionError , match = error_message ):
86
- run_vcztools (f"view { vcz_path } -s ^NA00001 -S { samples_file_path } " )
84
+ _ , vcztools_error = run_vcztools (
85
+ f"view { vcz_path } -s NA00001 -S ^{ samples_file_path } " , expect_error = True
86
+ )
87
+ assert error_message in vcztools_error
88
+ _ , vcztools_error = run_vcztools (
89
+ f"view { vcz_path } -s ^NA00001 -S { samples_file_path } " , expect_error = True
90
+ )
91
+ assert error_message in vcztools_error
87
92
88
93
89
94
@mock .patch ("sys.exit" )
@@ -104,7 +109,7 @@ def test_format_required(self, vcz_path):
104
109
f"query { vcz_path } " ,
105
110
catch_exceptions = False ,
106
111
)
107
- assert result .exit_code == 2
112
+ assert result .exit_code != 0
108
113
assert len (result .stdout ) == 0
109
114
assert len (result .stderr ) > 0
110
115
@@ -115,34 +120,34 @@ def test_path_required(self):
115
120
"query --format=POS " ,
116
121
catch_exceptions = False ,
117
122
)
118
- assert result .exit_code == 2
123
+ assert result .exit_code != 0
119
124
assert len (result .stdout ) == 0
120
125
assert len (result .stderr ) > 0
121
126
122
127
def test_list (self , vcz_path ):
123
- result = run_vcztools (f"query -l { vcz_path } " )
128
+ result , _ = run_vcztools (f"query -l { vcz_path } " )
124
129
assert list (result .splitlines ()) == ["NA00001" , "NA00002" , "NA00003" ]
125
130
126
131
def test_list_ignores_output (self , vcz_path , tmp_path ):
127
132
output = tmp_path / "tmp.txt"
128
- result = run_vcztools (f"query -l { vcz_path } -o { output } " )
133
+ result , _ = run_vcztools (f"query -l { vcz_path } -o { output } " )
129
134
assert list (result .splitlines ()) == ["NA00001" , "NA00002" , "NA00003" ]
130
135
assert not output .exists ()
131
136
132
137
def test_output (self , vcz_path , tmp_path ):
133
138
output = tmp_path / "tmp.txt"
134
- result = run_vcztools (f"query -f '%POS\n ' { vcz_path } -o { output } " )
139
+ result , _ = run_vcztools (f"query -f '%POS\n ' { vcz_path } -o { output } " )
135
140
assert list (result .splitlines ()) == []
136
141
assert output .exists ()
137
142
138
143
139
144
class TestIndex :
140
145
def test_stats (self , vcz_path ):
141
- result = run_vcztools (f"index -s { vcz_path } " )
146
+ result , _ = run_vcztools (f"index -s { vcz_path } " )
142
147
assert list (result .splitlines ()) == ["19\t .\t 2" , "20\t .\t 6" , "X\t .\t 1" ]
143
148
144
149
def test_nrecords (self , vcz_path ):
145
- result = run_vcztools (f"index -n { vcz_path } " )
150
+ result , _ = run_vcztools (f"index -n { vcz_path } " )
146
151
assert list (result .splitlines ()) == ["9" ]
147
152
148
153
def test_stats_and_nrecords (self , vcz_path ):
@@ -152,7 +157,7 @@ def test_stats_and_nrecords(self, vcz_path):
152
157
f"index -ns { vcz_path } " ,
153
158
catch_exceptions = False ,
154
159
)
155
- assert result .exit_code == 2
160
+ assert result .exit_code != 0
156
161
assert len (result .stdout ) == 0
157
162
assert len (result .stderr ) > 0
158
163
assert "Expected only one of --stats or --nrecords options" in result .stderr
@@ -164,7 +169,7 @@ def test_no_stats_or_nrecords(self, vcz_path):
164
169
f"index { vcz_path } " ,
165
170
catch_exceptions = False ,
166
171
)
167
- assert result .exit_code == 2
172
+ assert result .exit_code != 0
168
173
assert len (result .stdout ) == 0
169
174
assert len (result .stderr ) > 0
170
175
assert "Error: Building region indexes is not supported" in result .stderr
0 commit comments