summaryrefslogtreecommitdiff
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
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 5bae9f474f..72ae31adda 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.