Skip to content

Commit e199aea

Browse files
authored
Merge pull request #50 from pycompression/fixcli2
Patch CLI to not crash on non .gz filename
2 parents e9c0c0f + 9a29676 commit e199aea

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 0.6.1
11+
-----------------
12+
+ Fix a crash that occurs when opening a file that did not end in ``.gz`` while
13+
outputting to stdout using ``python -m isal.igzip``.
14+
1015
version 0.6.0
1116
-----------------
1217
+ ``python -m gzip``'s behaviour has been changed since fixing bug:

src/isal/igzip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ def main():
294294
in_file = IGzipFile(mode="rb", fileobj=sys.stdin.buffer)
295295
elif not args.compress and args.file is not None:
296296
base, extension = os.path.splitext(args.file)
297-
if extension != ".gz":
298-
sys.exit(f"filename doesn't end in .gz: {args.file!r}")
297+
if extension != ".gz" and not args.stdout:
298+
sys.exit(f"filename doesn't end in .gz: {args.file!r}. "
299+
f"Cannot determine output filename.")
299300
in_file = open(args.file, "rb")
300301

301302
# Determine output file

tests/test_gzip_compliance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ def test_decompress_infile_outfile(self):
823823
def test_decompress_infile_outfile_error(self):
824824
rc, out, err = assert_python_failure('-m', 'isal.igzip', '-d',
825825
'thisisatest.out')
826-
self.assertEqual(b"filename doesn't end in .gz: 'thisisatest.out'",
826+
self.assertEqual(b"filename doesn't end in .gz: 'thisisatest.out'. "
827+
b"Cannot determine output filename.",
827828
err.strip())
828829
self.assertEqual(rc, 1)
829830
self.assertEqual(out, b'')

tests/test_igzip.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ def test_decompress_infile_outfile_error(capsysbinary):
118118
assert out == b''
119119

120120

121+
def test_decompress_infile_stdout_noerror(capsysbinary, tmp_path):
122+
test_file = tmp_path / "test"
123+
test_file.write_bytes(COMPRESSED_DATA)
124+
sys.argv = ['', '-cd', str(tmp_path / 'test')]
125+
igzip.main()
126+
result = capsysbinary.readouterr()
127+
assert DATA == result.out
128+
129+
121130
def test_decompress_infile_stdout(capsysbinary, tmp_path):
122131
test_gz = tmp_path / "test.gz"
123132
test_gz.write_bytes(gzip.compress(DATA))

0 commit comments

Comments
 (0)