mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] gh-131219: Improve tests in test_lzma.py
by adding more asserts (GH-131220) (#131231)
gh-131219: Improve tests in `test_lzma.py` by adding more asserts (GH-131220)
(cherry picked from commit f6c24a5c89
)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
6c10767232
commit
7d498aae2c
1 changed files with 28 additions and 18 deletions
|
@ -538,13 +538,17 @@ class FileTestCase(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
with LZMAFile(BytesIO(COMPRESSED_XZ)) as f:
|
||||
pass
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "rb")
|
||||
with LZMAFile(BytesIO(), "w") as f:
|
||||
pass
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
with LZMAFile(BytesIO(), "x") as f:
|
||||
pass
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
with LZMAFile(BytesIO(), "a") as f:
|
||||
pass
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
|
||||
def test_init_with_PathLike_filename(self):
|
||||
filename = FakePath(TESTFN)
|
||||
|
@ -573,26 +577,32 @@ class FileTestCase(unittest.TestCase):
|
|||
|
||||
def test_init_mode(self):
|
||||
with TempFile(TESTFN):
|
||||
with LZMAFile(TESTFN, "r"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "rb"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "w"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "wb"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "a"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "ab"):
|
||||
pass
|
||||
with LZMAFile(TESTFN, "r") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "rb")
|
||||
with LZMAFile(TESTFN, "rb") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "rb")
|
||||
with LZMAFile(TESTFN, "w") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
with LZMAFile(TESTFN, "wb") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
with LZMAFile(TESTFN, "a") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
with LZMAFile(TESTFN, "ab") as f:
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, "wb")
|
||||
|
||||
def test_init_with_x_mode(self):
|
||||
self.addCleanup(unlink, TESTFN)
|
||||
for mode in ("x", "xb"):
|
||||
unlink(TESTFN)
|
||||
with LZMAFile(TESTFN, mode) as f:
|
||||
pass
|
||||
self.assertEqual(f.mode, 'wb')
|
||||
self.assertIsInstance(f, LZMAFile)
|
||||
self.assertEqual(f.mode, 'wb')
|
||||
with self.assertRaises(FileExistsError):
|
||||
LZMAFile(TESTFN, mode)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue