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 1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
3
+ import gzip
3
4
import 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
13
6
14
7
15
8
def gunzip (filename ):
@@ -19,17 +12,13 @@ def gunzip(filename):
19
12
----------
20
13
filename : str
21
14
Fully qualified path of the file to decompress.
15
+
22
16
Returns
23
17
-------
24
18
filename : str
25
19
Name of the decompressed file (or input filename if gzip is not
26
20
available).
27
21
"""
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
33
22
34
23
# ".fz" denotes RICE rather than gzip compression
35
24
if not filename .endswith ('.fz' ):
Original file line number Diff line number Diff line change 1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
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
16
4
17
5
from ..system_tools import gunzip
18
6
19
7
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'
27
10
# First create a gzip file
28
11
content = b"Bla"
29
12
with gzip .open (filename , "wb" ) as f :
30
13
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