14
14
import os
15
15
import re
16
16
import shutil
17
- import subprocess
18
17
import sys
19
18
import tempfile
20
19
import zlib
28
27
DATA = b'This is a simple test with gzip_ng'
29
28
COMPRESSED_DATA = gzip .compress (DATA )
30
29
TEST_FILE = str ((Path (__file__ ).parent / "data" / "test.fastq.gz" ))
31
- PYPY = sys .implementation .name == "pypy"
32
-
33
-
34
- def run_gzip_ng (* args , stdin = None ):
35
- """Calling gzip_ng externally seems to solve some issues on PyPy where
36
- files would not be written properly when gzip_ng.main() was called. This is
37
- probably due to some out of order execution that PyPy tries to pull.
38
- Running the process externally is detrimental to the coverage report,
39
- so this is only done for PyPy."""
40
- process = subprocess .Popen (["python" , "-m" , "zlib_ng.gzip_ng" , * args ],
41
- stdout = subprocess .PIPE ,
42
- stderr = subprocess .PIPE ,
43
- stdin = subprocess .PIPE )
44
-
45
- return process .communicate (stdin )
46
30
47
31
48
32
def test_repr ():
@@ -121,12 +105,9 @@ def test_decompress_infile_outfile(tmp_path, capsysbinary):
121
105
def test_compress_infile_outfile (tmp_path , capsysbinary ):
122
106
test_file = tmp_path / "test"
123
107
test_file .write_bytes (DATA )
124
- if PYPY :
125
- out , err = run_gzip_ng (str (test_file ))
126
- else :
127
- sys .argv = ['' , str (test_file )]
128
- gzip_ng .main ()
129
- out , err = capsysbinary .readouterr ()
108
+ sys .argv = ['' , str (test_file )]
109
+ gzip_ng .main ()
110
+ out , err = capsysbinary .readouterr ()
130
111
out_file = test_file .with_suffix (".gz" )
131
112
assert err == b''
132
113
assert out == b''
@@ -189,12 +170,9 @@ def test_compress_infile_out_file(tmp_path, capsysbinary):
189
170
test .write_bytes (DATA )
190
171
out_file = tmp_path / "compressed.gz"
191
172
args = ['-o' , str (out_file ), str (test )]
192
- if PYPY :
193
- out , err = run_gzip_ng (* args )
194
- else :
195
- sys .argv = ['' , * args ]
196
- gzip_ng .main ()
197
- out , err = capsysbinary .readouterr ()
173
+ sys .argv = ['' , * args ]
174
+ gzip_ng .main ()
175
+ out , err = capsysbinary .readouterr ()
198
176
assert gzip .decompress (out_file .read_bytes ()) == DATA
199
177
assert err == b''
200
178
assert out == b''
@@ -206,12 +184,9 @@ def test_compress_infile_out_file_force(tmp_path, capsysbinary):
206
184
out_file = tmp_path / "compressed.gz"
207
185
out_file .touch ()
208
186
args = ['-f' , '-o' , str (out_file ), str (test )]
209
- if PYPY :
210
- out , err = run_gzip_ng (* args )
211
- else :
212
- sys .argv = ['' , * args ]
213
- gzip_ng .main ()
214
- out , err = capsysbinary .readouterr ()
187
+ sys .argv = ['' , * args ]
188
+ gzip_ng .main ()
189
+ out , err = capsysbinary .readouterr ()
215
190
assert gzip .decompress (out_file .read_bytes ()) == DATA
216
191
assert err == b''
217
192
assert out == b''
@@ -254,14 +229,11 @@ def test_compress_infile_out_file_inmplicit_name_prompt_accept(
254
229
test .write_bytes (DATA )
255
230
out_file = tmp_path / "test.gz"
256
231
out_file .touch ()
257
- if PYPY :
258
- out , err = run_gzip_ng (str (test ), stdin = b"y\n " )
259
- else :
260
- sys .argv = ['' , str (test )]
261
- mock_stdin = io .BytesIO (b"y" )
262
- sys .stdin = io .TextIOWrapper (mock_stdin )
263
- gzip_ng .main ()
264
- out , err = capsysbinary .readouterr ()
232
+ sys .argv = ['' , str (test )]
233
+ mock_stdin = io .BytesIO (b"y" )
234
+ sys .stdin = io .TextIOWrapper (mock_stdin )
235
+ gzip_ng .main ()
236
+ out , err = capsysbinary .readouterr ()
265
237
assert b"already exists; do you wish to overwrite" in out
266
238
assert err == b""
267
239
assert gzip .decompress (out_file .read_bytes ()) == DATA
@@ -271,13 +243,9 @@ def test_compress_infile_out_file_no_name(tmp_path, capsysbinary):
271
243
test = tmp_path / "test"
272
244
test .write_bytes (DATA )
273
245
out_file = tmp_path / "compressed.gz"
274
- args = ['-n' , '-o' , str (out_file ), str (test )]
275
- if PYPY :
276
- out , err = run_gzip_ng (* args )
277
- else :
278
- sys .argv = ['' , '-n' , '-o' , str (out_file ), str (test )]
279
- gzip_ng .main ()
280
- out , err = capsysbinary .readouterr ()
246
+ sys .argv = ['' , '-n' , '-o' , str (out_file ), str (test )]
247
+ gzip_ng .main ()
248
+ out , err = capsysbinary .readouterr ()
281
249
output = out_file .read_bytes ()
282
250
assert gzip .decompress (output ) == DATA
283
251
assert err == b''
0 commit comments