Skip to content

Commit df3475a

Browse files
erwanpbsipocz
authored andcommitted
rewrote test_gunzip to use a tempfolder instead of a tempfile, hoping it will fix Permission Errors on Travis Windows
also added a comment on the 'fz' format
1 parent 8e800fe commit df3475a

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

astroquery/utils/system_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def gunzip(filename):
3131
# system-wide 'gzip' was removed, Python gzip used instead.
3232
# See #1538 : https://github.com/astropy/astroquery/issues/1538
3333

34+
# ".fz" denotes RICE rather than gzip compression
3435
if not filename.endswith('.fz'):
3536
with gzip.open(filename, 'rb') as f_in:
3637
with open(filename.rsplit(".", 1)[0], 'wb') as f_out:

astroquery/utils/tests/test_system_tools.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
try:
44
import gzip
5+
56
HAS_GZIP = True
67
except ImportError:
78
HAS_GZIP = False
89

10+
import shutil
911
import os
1012
from os.path import exists
1113
import tempfile
@@ -15,30 +17,28 @@
1517
from ..system_tools import gunzip
1618

1719

18-
@pytest.mark.skipif('not HAS_GZIP')
20+
@pytest.mark.skipif("not HAS_GZIP")
1921
def test_gunzip():
20-
filehandle = tempfile.NamedTemporaryFile(suffix='.txt.gz')
21-
filename = filehandle.name
22+
23+
temp_dir = tempfile.mkdtemp()
24+
filename = temp_dir + os.sep + "test_gunzip.txt.gz"
2225
unziped_filename = filename.rsplit(".", 1)[0]
23-
for f in [filename, unziped_filename]:
24-
if exists(f):
25-
os.remove(f)
2626

2727
# First create a gzip file
2828
content = b"Bla"
29-
with gzip.open(filename, 'wb') as f:
29+
with gzip.open(filename, "wb") as f:
3030
f.write(content)
3131

32-
# Then test our gunzip command works and creates an unziped file
33-
gunzip(filename)
34-
assert exists(unziped_filename)
32+
try:
33+
# Then test our gunzip command works and creates an unziped file
34+
gunzip(filename)
35+
assert exists(unziped_filename)
3536

36-
# Check content is the same
37-
with open(unziped_filename, 'rb') as f:
38-
new_content = f.read()
39-
assert new_content == content
37+
# Check content is the same
38+
with open(unziped_filename, "rb") as f:
39+
new_content = f.read()
40+
assert new_content == content
4041

41-
# Clean
42-
for f in [filename, unziped_filename]:
43-
if exists(f):
44-
os.remove(f)
42+
finally:
43+
# Clean
44+
shutil.rmtree(temp_dir)

0 commit comments

Comments
 (0)