diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-18 13:35:37 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-18 13:35:37 (GMT) |
commit | 53ad0cd2842b7327bde4ca04ee11c544e522ff43 (patch) | |
tree | 97d5acc0e56305606306bbb0eed10a155d6c9aac /Lib/test/test_tarfile.py | |
parent | af69fe2311c184a64e1dbfae75646d5d6c268d32 (diff) | |
download | cpython-53ad0cd2842b7327bde4ca04ee11c544e522ff43.zip cpython-53ad0cd2842b7327bde4ca04ee11c544e522ff43.tar.gz cpython-53ad0cd2842b7327bde4ca04ee11c544e522ff43.tar.bz2 |
Issue #20245: The open functions in the tarfile module now correctly handle empty mode.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 18dd390..6986fc0 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -41,6 +41,7 @@ class TarTest: tarname = tarname suffix = '' open = io.FileIO + taropen = tarfile.TarFile.taropen @property def mode(self): @@ -51,18 +52,21 @@ class GzipTest: tarname = gzipname suffix = 'gz' open = gzip.GzipFile if gzip else None + taropen = tarfile.TarFile.gzopen @support.requires_bz2 class Bz2Test: tarname = bz2name suffix = 'bz2' open = bz2.BZ2File if bz2 else None + taropen = tarfile.TarFile.bz2open @support.requires_lzma class LzmaTest: tarname = xzname suffix = 'xz' open = lzma.LZMAFile if lzma else None + taropen = tarfile.TarFile.xzopen class ReadTest(TarTest): @@ -287,6 +291,16 @@ class MiscReadTestBase(CommonReadTest): with tarfile.open(fileobj=fobj, mode=self.mode) as tar: self.assertEqual(tar.name, None) + def test_illegal_mode_arg(self): + with open(tmpname, 'wb'): + pass + with self.assertRaisesRegex(ValueError, 'mode must be '): + tar = self.taropen(tmpname, 'q') + with self.assertRaisesRegex(ValueError, 'mode must be '): + tar = self.taropen(tmpname, 'rw') + with self.assertRaisesRegex(ValueError, 'mode must be '): + tar = self.taropen(tmpname, '') + def test_fileobj_with_offset(self): # Skip the first member and store values from the second member # of the testtar. |