diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-10-04 17:41:20 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-10-04 17:41:20 (GMT) |
commit | 5f59ddddcd7020bdd3a87b50fe3a8aa0c8e3e689 (patch) | |
tree | 2eb8f39bcb64475a23d0081139a35190c1a57a88 /Lib/test/test_lzma.py | |
parent | db8d6265fa86a7cb9d7c5e4d60e3b342edc90176 (diff) | |
download | cpython-5f59ddddcd7020bdd3a87b50fe3a8aa0c8e3e689.zip cpython-5f59ddddcd7020bdd3a87b50fe3a8aa0c8e3e689.tar.gz cpython-5f59ddddcd7020bdd3a87b50fe3a8aa0c8e3e689.tar.bz2 |
Issue #28229: lzma module now supports pathlib
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r-- | Lib/test/test_lzma.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index 228db66..fdc8e11 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -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): |