mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #28229: lzma module now supports pathlib
This commit is contained in:
parent
db8d6265fa
commit
5f59ddddcd
4 changed files with 47 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
import _compression
|
||||
from io import BytesIO, UnsupportedOperation, DEFAULT_BUFFER_SIZE
|
||||
import os
|
||||
import pathlib
|
||||
import pickle
|
||||
import random
|
||||
import unittest
|
||||
|
@ -488,6 +489,16 @@ class FileTestCase(unittest.TestCase):
|
|||
with LZMAFile(BytesIO(), "a") as f:
|
||||
pass
|
||||
|
||||
def test_init_with_PathLike_filename(self):
|
||||
filename = pathlib.Path(TESTFN)
|
||||
with TempFile(filename, COMPRESSED_XZ):
|
||||
with LZMAFile(filename) as f:
|
||||
self.assertEqual(f.read(), INPUT)
|
||||
with LZMAFile(filename, "a") as f:
|
||||
f.write(INPUT)
|
||||
with LZMAFile(filename) as f:
|
||||
self.assertEqual(f.read(), INPUT * 2)
|
||||
|
||||
def test_init_with_filename(self):
|
||||
with TempFile(TESTFN, COMPRESSED_XZ):
|
||||
with LZMAFile(TESTFN) as f:
|
||||
|
@ -1180,6 +1191,17 @@ class OpenTestCase(unittest.TestCase):
|
|||
with lzma.open(TESTFN, "rb") as f:
|
||||
self.assertEqual(f.read(), INPUT * 2)
|
||||
|
||||
def test_with_pathlike_filename(self):
|
||||
filename = pathlib.Path(TESTFN)
|
||||
with TempFile(filename):
|
||||
with lzma.open(filename, "wb") as f:
|
||||
f.write(INPUT)
|
||||
with open(filename, "rb") as f:
|
||||
file_data = lzma.decompress(f.read())
|
||||
self.assertEqual(file_data, INPUT)
|
||||
with lzma.open(filename, "rb") as f:
|
||||
self.assertEqual(f.read(), INPUT)
|
||||
|
||||
def test_bad_params(self):
|
||||
# Test invalid parameter combinations.
|
||||
with self.assertRaises(ValueError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue