8000 gh-131219: Improve tests in `test_lzma.py` by adding more asserts by sobolevn · Pull Request #131220 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-131219: Improve tests in test_lzma.py by adding more asserts #131220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-131219: Improve tests in test_lzma.py by adding more asserts
  • Loading branch information
sobolevn committed Mar 14, 2025
commit f9c32dff19707d2c7654ce1eef8da7206317dc9d
44 changes: 27 additions & 17 deletions Lib/test/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -573,25 +577,31 @@ def test_init_with_filename(self):

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.assertIsInstance(f, LZMAFile)
self.assertEqual(f.mode, 'wb')
with self.assertRaises(FileExistsError):
LZMAFile(TESTFN, mode)
Expand Down
Loading
0