From 53ad0cd2842b7327bde4ca04ee11c544e522ff43 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 18 Jan 2014 15:35:37 +0200 Subject: Issue #20245: The open functions in the tarfile module now correctly handle empty mode. --- Lib/test/test_tarfile.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Lib/test/test_tarfile.py') diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 18dd390730..6986fc00bd 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. -- cgit v1.2.1