Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6c24a5

Browse files
authored
gh-131219: Improve tests in test_lzma.py by adding more asserts (#131220)
1 parent 6b932ed commit f6c24a5

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Lib/test/test_lzma.py

+28-18
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)
@@ -573,26 +577,32 @@ def test_init_with_filename(self):
573577

574578
def test_init_mode(self):
575579
with TempFile(TESTFN):
576-
with LZMAFile(TESTFN, "r"):
577-
pass
578-
with LZMAFile(TESTFN, "rb"):
579-
pass
580-
with LZMAFile(TESTFN, "w"):
581-
pass
582-
with LZMAFile(TESTFN, "wb"):
583-
pass
584-
with LZMAFile(TESTFN, "a"):
585-
pass
586-
with LZMAFile(TESTFN, "ab"):
587-
pass
580+
with LZMAFile(TESTFN, "r") as f:
581+
self.assertIsInstance(f, LZMAFile)
582+
self.assertEqual(f.mode, "rb")
583+
with LZMAFile(TESTFN, "rb") as f:
584+
self.assertIsInstance(f, LZMAFile)
585+
self.assertEqual(f.mode, "rb")
586+
with LZMAFile(TESTFN, "w") as f:
587+
self.assertIsInstance(f, LZMAFile)
588+
self.assertEqual(f.mode, "wb")
589+
with LZMAFile(TESTFN, "wb") as f:
590+
self.assertIsInstance(f, LZMAFile)
591+
self.assertEqual(f.mode, "wb")
592+
with LZMAFile(TESTFN, "a") as f:
593+
self.assertIsInstance(f, LZMAFile)
594+
self.assertEqual(f.mode, "wb")
595+
with LZMAFile(TESTFN, "ab") as f:
596+
self.assertIsInstance(f, LZMAFile)
597+
self.assertEqual(f.mode, "wb")
588598

589599
def test_init_with_x_mode(self):
590600
self.addCleanup(unlink, TESTFN)
591601
for mode in ("x", "xb"):
592602
unlink(TESTFN)
593603
with LZMAFile(TESTFN, mode) as f:
594-
pass
595-
self.assertEqual(f.mode, 'wb')
604+
self.assertIsInstance(f, LZMAFile)
605+
self.assertEqual(f.mode, 'wb')
596606
with self.assertRaises(FileExistsError):
597607
LZMAFile(TESTFN, mode)
598608

0 commit comments

Comments
 (0)