18
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
# SOFTWARE.
20
20
21
+ """Tests for the igzip CLI. Uses pytest which works better than unittest for
22
+ these sort of tests. Meant to complement the gzip module compliance tests.
23
+ It should improve coverage as well."""
24
+
21
25
import gzip
22
26
import io
23
27
import sys
@@ -39,6 +43,7 @@ def test_decompress_stdin_stdout(capsysbinary, level):
39
43
sys .argv = ["" , "-d" ]
40
44
igzip .main ()
41
45
out , err = capsysbinary .readouterr ()
46
+ assert err == b''
42
47
assert out == DATA
43
48
44
49
@@ -49,21 +54,40 @@ def test_compress_stdin_stdout(capsysbinary, level):
49
54
sys .argv = ["" , f"-{ level } " ]
50
55
igzip .main ()
51
56
out , err = capsysbinary .readouterr ()
57
+ assert err == b''
52
58
assert gzip .decompress (out ) == DATA
53
59
54
60
55
- def test_decompress_infile_outfile (tmp_path ):
61
+ def test_decompress_infile_outfile (tmp_path , capsysbinary ):
56
62
test_file = tmp_path / "test"
57
63
compressed_temp = test_file .with_suffix (".gz" )
58
64
compressed_temp .write_bytes (gzip .compress (DATA ))
59
65
sys .argv = ['' , '-d' , str (compressed_temp )]
60
66
igzip .main ()
67
+ out , err = capsysbinary .readouterr ()
68
+ assert err == b''
69
+ assert out == b''
70
+ assert test_file .exists ()
61
71
assert test_file .read_bytes () == DATA
62
72
63
73
64
- def test_compress_infile_outfile (tmp_path ):
74
+ def test_compress_infile_outfile (tmp_path , capsysbinary ):
65
75
test_file = tmp_path / "test"
66
76
test_file .write_bytes (DATA )
67
77
sys .argv = ['' , str (test_file )]
68
78
igzip .main ()
69
- assert gzip .decompress (test_file .with_suffix (".gz" ).read_bytes ()) == DATA
79
+ out_file = test_file .with_suffix (".gz" )
80
+ out , err = capsysbinary .readouterr ()
81
+ assert err == b''
82
+ assert out == b''
83
+ assert out_file .exists ()
84
+ assert gzip .decompress (out_file .read_bytes ()) == DATA
85
+
86
+
87
+ def test_decompress_infile_outfile_error (capsysbinary ):
88
+ sys .argv = ['' , '-d' , 'thisisatest.out' ]
89
+ with pytest .raises (ValueError ) as error :
90
+ igzip .main ()
91
+ assert error .match ("filename doesn't end" )
92
+ out , err = capsysbinary .readouterr ()
93
+ assert out == b''
0 commit comments