-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2306 from eerovaher/refactor-systools
Refactor `astroquery/utils/system_tools.py` and its tests
- Loading branch information
Showing
2 changed files
with
11 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,18 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
|
||
try: | ||
import gzip | ||
|
||
HAS_GZIP = True | ||
except ImportError: | ||
HAS_GZIP = False | ||
|
||
import shutil | ||
import os | ||
from os.path import exists | ||
import tempfile | ||
|
||
import pytest | ||
import gzip | ||
|
||
from ..system_tools import gunzip | ||
|
||
|
||
@pytest.mark.skipif("not HAS_GZIP") | ||
def test_gunzip(): | ||
|
||
temp_dir = tempfile.mkdtemp() | ||
filename = f"{temp_dir}{os.sep}test_gunzip.txt.gz" | ||
unziped_filename = filename.rsplit(".", 1)[0] | ||
|
||
def test_gunzip(tmp_path): | ||
filename = tmp_path / 'test_gunzip.txt.gz' | ||
# First create a gzip file | ||
content = b"Bla" | ||
with gzip.open(filename, "wb") as f: | ||
f.write(content) | ||
|
||
try: | ||
# Then test our gunzip command works and creates an unziped file | ||
gunzip(filename) | ||
assert exists(unziped_filename) | ||
|
||
# Check content is the same | ||
with open(unziped_filename, "rb") as f: | ||
new_content = f.read() | ||
assert new_content == content | ||
|
||
finally: | ||
# Clean | ||
shutil.rmtree(temp_dir) | ||
# Then test our gunzip command works | ||
gunzip(str(filename)) | ||
with open(filename.with_suffix(''), "rb") as f: | ||
new_content = f.read() | ||
assert new_content == content |