mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-43316: gzip: CLI uses non-zero return code on error. (GH-24647)
Exit code is now 1 instead of 0. A message is printed to stderr instead of stdout. This is the proper behaviour for a tool that can be used in scripts.
This commit is contained in:
parent
70f8ebe503
commit
cc3df6368d
3 changed files with 8 additions and 6 deletions
|
@ -583,8 +583,7 @@ def main():
|
||||||
g = sys.stdout.buffer
|
g = sys.stdout.buffer
|
||||||
else:
|
else:
|
||||||
if arg[-3:] != ".gz":
|
if arg[-3:] != ".gz":
|
||||||
print("filename doesn't end in .gz:", repr(arg))
|
sys.exit("filename doesn't end in .gz:", repr(arg))
|
||||||
continue
|
|
||||||
f = open(arg, "rb")
|
f = open(arg, "rb")
|
||||||
g = builtins.open(arg[:-3], "wb")
|
g = builtins.open(arg[:-3], "wb")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -774,10 +774,10 @@ class TestCommandLine(unittest.TestCase):
|
||||||
self.assertEqual(err, b'')
|
self.assertEqual(err, b'')
|
||||||
|
|
||||||
def test_decompress_infile_outfile_error(self):
|
def test_decompress_infile_outfile_error(self):
|
||||||
rc, out, err = assert_python_ok('-m', 'gzip', '-d', 'thisisatest.out')
|
rc, out, err = assert_python_failure('-m', 'gzip', '-d', 'thisisatest.out')
|
||||||
self.assertIn(b"filename doesn't end in .gz:", out)
|
self.assertIn(b"filename doesn't end in .gz:", err)
|
||||||
self.assertEqual(rc, 0)
|
self.assertEqual(rc, 1)
|
||||||
self.assertEqual(err, b'')
|
self.assertEqual(out, b'')
|
||||||
|
|
||||||
@create_and_remove_directory(TEMPDIR)
|
@create_and_remove_directory(TEMPDIR)
|
||||||
def test_compress_stdin_outfile(self):
|
def test_compress_stdin_outfile(self):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
The ``python -m gzip`` command line application now properly fails when
|
||||||
|
detecting an unsupported extension. It exits with a non-zero exit code and
|
||||||
|
prints an error message to stderr.
|
Loading…
Add table
Add a link
Reference in a new issue