File tree Expand file tree Collapse file tree 2 files changed +11
-48
lines changed Expand file tree Collapse file tree 2 files changed +11
-48
lines changed Original file line number Diff line number Diff line change 11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
3+ import gzip
34import os
4-
5- # Import DEVNULL for py3 or py3
6- try :
7- from subprocess import DEVNULL
8- except ImportError :
9- DEVNULL = open (os .devnull , 'wb' )
10-
11- # Check availability of some system tools
12- # Exceptions are raised if not found
5+ import shutil
136
147
158def gunzip (filename ):
@@ -19,17 +12,13 @@ def gunzip(filename):
1912 ----------
2013 filename : str
2114 Fully qualified path of the file to decompress.
15+
2216 Returns
2317 -------
2418 filename : str
2519 Name of the decompressed file (or input filename if gzip is not
2620 available).
2721 """
28- import shutil
29- import gzip
30-
31- # system-wide 'gzip' was removed, Python gzip used instead.
32- # See #1538 : https://github.com/astropy/astroquery/issues/1538
3322
3423 # ".fz" denotes RICE rather than gzip compression
3524 if not filename .endswith ('.fz' ):
Original file line number Diff line number Diff line change 11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
3- try :
4- import gzip
5-
6- HAS_GZIP = True
7- except ImportError :
8- HAS_GZIP = False
9-
10- import shutil
11- import os
12- from os .path import exists
13- import tempfile
14-
15- import pytest
3+ import gzip
164
175from ..system_tools import gunzip
186
197
20- @pytest .mark .skipif ("not HAS_GZIP" )
21- def test_gunzip ():
22-
23- temp_dir = tempfile .mkdtemp ()
24- filename = f"{ temp_dir } { os .sep } test_gunzip.txt.gz"
25- unziped_filename = filename .rsplit ("." , 1 )[0 ]
26-
8+ def test_gunzip (tmp_path ):
9+ filename = tmp_path / 'test_gunzip.txt.gz'
2710 # First create a gzip file
2811 content = b"Bla"
2912 with gzip .open (filename , "wb" ) as f :
3013 f .write (content )
31-
32- try :
33- # Then test our gunzip command works and creates an unziped file
34- gunzip (filename )
35- assert exists (unziped_filename )
36-
37- # Check content is the same
38- with open (unziped_filename , "rb" ) as f :
39- new_content = f .read ()
40- assert new_content == content
41-
42- finally :
43- # Clean
44- shutil .rmtree (temp_dir )
14+ # Then test our gunzip command works
15+ gunzip (str (filename ))
16+ with open (filename .with_suffix ('' ), "rb" ) as f :
17+ new_content = f .read ()
18+ assert new_content == content
You can’t perform that action at this time.
0 commit comments