summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-18 13:37:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-18 13:37:21 (GMT)
commitce644a09ac731830aa3a82e9a36e41bc022383c2 (patch)
tree575f918f7c21cc86d056ecca89628e68dadc6218 /Lib/test/test_tarfile.py
parent537d76076671368953465548687c360c8107ad10 (diff)
parent53ad0cd2842b7327bde4ca04ee11c544e522ff43 (diff)
downloadcpython-ce644a09ac731830aa3a82e9a36e41bc022383c2.zip
cpython-ce644a09ac731830aa3a82e9a36e41bc022383c2.tar.gz
cpython-ce644a09ac731830aa3a82e9a36e41bc022383c2.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.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 5bae9f4..72ae31a 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -43,6 +43,7 @@ class TarTest:
tarname = tarname
suffix = ''
open = io.FileIO
+ taropen = tarfile.TarFile.taropen
@property
def mode(self):
@@ -53,18 +54,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):
@@ -289,6 +293,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.