Skip to content

Commit 29db7f0

Browse files
committed
[3.12] pythongh-131219: Improve tests in test_lzma.py by adding more asserts (pythonGH-131220)
(cherry picked from commit f6c24a5) Co-authored-by: sobolevn <[email protected]>
1 parent 77ece5a commit 29db7f0

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

Lib/test/test_lzma.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,17 @@ class FileTestCase(unittest.TestCase):
538538

539539
def test_init(self):
540540
with LZMAFile(BytesIO(COMPRESSED_XZ)) as f:
541-
pass
541+
self.assertIsInstance(f, LZMAFile)
542+
self.assertEqual(f.mode, "rb")
542543
with LZMAFile(BytesIO(), "w") as f:
543-
pass
544+
self.assertIsInstance(f, LZMAFile)
545+
self.assertEqual(f.mode, "wb")
544546
with LZMAFile(BytesIO(), "x") as f:
545-
pass
547+
self.assertIsInstance(f, LZMAFile)
548+
self.assertEqual(f.mode, "wb")
546549
with LZMAFile(BytesIO(), "a") as f:
547-
pass
550+
self.assertIsInstance(f, LZMAFile)
551+
self.assertEqual(f.mode, "wb")
548552

549553
def test_init_with_PathLike_filename(self):
550554
filename = FakePath(TESTFN)
@@ -567,25 +571,32 @@ def test_init_with_filename(self):
567571

568572
def test_init_mode(self):
569573
with TempFile(TESTFN):
570-
with LZMAFile(TESTFN, "r"):
571-
pass
572-
with LZMAFile(TESTFN, "rb"):
573-
pass
574-
with LZMAFile(TESTFN, "w"):
575-
pass
576-
with LZMAFile(TESTFN, "wb"):
577-
pass
578-
with LZMAFile(TESTFN, "a"):
579-
pass
580-
with LZMAFile(TESTFN, "ab"):
581-
pass
574+
with LZMAFile(TESTFN, "r") as f:
575+
self.assertIsInstance(f, LZMAFile)
576+
self.assertEqual(f.mode, "rb")
577+
with LZMAFile(TESTFN, "rb") as f:
578+
self.assertIsInstance(f, LZMAFile)
579+
self.assertEqual(f.mode, "rb")
580+
with LZMAFile(TESTFN, "w") as f:
581+
self.assertIsInstance(f, LZMAFile)
582+
self.assertEqual(f.mode, "wb")
583+
with LZMAFile(TESTFN, "wb") as f:
584+
self.assertIsInstance(f, LZMAFile)
585+
self.assertEqual(f.mode, "wb")
586+
with LZMAFile(TESTFN, "a") as f:
587+
self.assertIsInstance(f, LZMAFile)
588+
self.assertEqual(f.mode, "wb")
589+
with LZMAFile(TESTFN, "ab") as f:
590+
self.assertIsInstance(f, LZMAFile)
591+
self.assertEqual(f.mode, "wb")
582592

583593
def test_init_with_x_mode(self):
584594
self.addCleanup(unlink, TESTFN)
585595
for mode in ("x", "xb"):
586596
unlink(TESTFN)
587597
with LZMAFile(TESTFN, mode) as f:
588-
pass
598+
self.assertIsInstance(f, LZMAFile)
599+
self.assertEqual(f.mode, 'wb')
589600
with self.assertRaises(FileExistsError):
590601
LZMAFile(TESTFN, mode)
591602

0 commit comments

Comments
 (0)