mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #19201: Add support for the 'x' mode to the lzma module.
Patch by Tim Heaney and Vajrasky Kok.
This commit is contained in:
parent
c516815353
commit
42ca98217c
5 changed files with 51 additions and 13 deletions
|
|
@ -362,6 +362,8 @@ class FileTestCase(unittest.TestCase):
|
|||
pass
|
||||
with LZMAFile(BytesIO(), "w") as f:
|
||||
pass
|
||||
with LZMAFile(BytesIO(), "x") as f:
|
||||
pass
|
||||
with LZMAFile(BytesIO(), "a") as f:
|
||||
pass
|
||||
|
||||
|
|
@ -389,13 +391,29 @@ class FileTestCase(unittest.TestCase):
|
|||
with LZMAFile(TESTFN, "ab"):
|
||||
pass
|
||||
|
||||
def test_init_with_x_mode(self):
|
||||
self.addCleanup(unlink, TESTFN)
|
||||
for mode in ("x", "xb"):
|
||||
unlink(TESTFN)
|
||||
with LZMAFile(TESTFN, mode):
|
||||
pass
|
||||
with self.assertRaises(FileExistsError):
|
||||
with LZMAFile(TESTFN, mode):
|
||||
pass
|
||||
|
||||
def test_init_bad_mode(self):
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), (3, "x"))
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "")
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "x")
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "xt")
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "x+")
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "rx")
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "wx")
|
||||
with self.assertRaises(ValueError):
|
||||
LZMAFile(BytesIO(COMPRESSED_XZ), "rt")
|
||||
with self.assertRaises(ValueError):
|
||||
|
|
@ -1021,8 +1039,6 @@ class OpenTestCase(unittest.TestCase):
|
|||
# Test invalid parameter combinations.
|
||||
with self.assertRaises(ValueError):
|
||||
lzma.open(TESTFN, "")
|
||||
with self.assertRaises(ValueError):
|
||||
lzma.open(TESTFN, "x")
|
||||
with self.assertRaises(ValueError):
|
||||
lzma.open(TESTFN, "rbt")
|
||||
with self.assertRaises(ValueError):
|
||||
|
|
@ -1072,6 +1088,16 @@ class OpenTestCase(unittest.TestCase):
|
|||
with lzma.open(bio, "rt", newline="\r") as f:
|
||||
self.assertEqual(f.readlines(), [text])
|
||||
|
||||
def test_x_mode(self):
|
||||
self.addCleanup(unlink, TESTFN)
|
||||
for mode in ("x", "xb", "xt"):
|
||||
unlink(TESTFN)
|
||||
with lzma.open(TESTFN, mode):
|
||||
pass
|
||||
with self.assertRaises(FileExistsError):
|
||||
with lzma.open(TESTFN, mode):
|
||||
pass
|
||||
|
||||
|
||||
class MiscellaneousTestCase(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue