summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gzip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r--Lib/test/test_gzip.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index b072ce4..1e8b41f 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -12,7 +12,7 @@ import unittest
from subprocess import PIPE, Popen
from test import support
from test.support import _4G, bigmemtest
-from test.support.script_helper import assert_python_ok
+from test.support.script_helper import assert_python_ok, assert_python_failure
gzip = support.import_module('gzip')
@@ -746,10 +746,38 @@ class TestCommandLine(unittest.TestCase):
rc, out, err = assert_python_ok('-m', 'gzip', local_testgzip)
self.assertTrue(os.path.exists(gzipname))
- self.assertEqual(rc, 0)
self.assertEqual(out, b'')
self.assertEqual(err, b'')
+ @create_and_remove_directory(TEMPDIR)
+ def test_compress_infile_outfile(self):
+ for compress_level in ('--fast', '--best'):
+ with self.subTest(compress_level=compress_level):
+ local_testgzip = os.path.join(TEMPDIR, 'testgzip')
+ gzipname = local_testgzip + '.gz'
+ self.assertFalse(os.path.exists(gzipname))
+
+ with open(local_testgzip, 'wb') as fp:
+ fp.write(self.data)
+
+ rc, out, err = assert_python_ok('-m', 'gzip', compress_level, local_testgzip)
+
+ self.assertTrue(os.path.exists(gzipname))
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
+ os.remove(gzipname)
+ self.assertFalse(os.path.exists(gzipname))
+
+ def test_compress_fast_best_are_exclusive(self):
+ rc, out, err = assert_python_failure('-m', 'gzip', '--fast', '--best')
+ self.assertIn(b"error: argument --best: not allowed with argument --fast", err)
+ self.assertEqual(out, b'')
+
+ def test_decompress_cannot_have_flags_compression(self):
+ rc, out, err = assert_python_failure('-m', 'gzip', '--fast', '-d')
+ self.assertIn(b'error: argument -d/--decompress: not allowed with argument --fast', err)
+ self.assertEqual(out, b'')
+
def test_main(verbose=None):
support.run_unittest(TestGzip, TestOpen, TestCommandLine)