mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #20245: The open functions in the tarfile module now correctly handle empty mode.
This commit is contained in:
commit
ce644a09ac
3 changed files with 25 additions and 7 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue