Skip to content

Commit 96feec0

Browse files
committed
Patch CLI to not crash on non .gz filename
1 parent 755397a commit 96feec0

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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)