summaryrefslogtreecommitdiff
path: root/Lib/test/test_lzma.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-06 14:12:19 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-06 14:12:19 -0800
commit5b4df5813c20fe96f117d0201965b52e86a1a66d (patch)
treed991f61bc824ca1b1b92bf7fb16fe3dacd4b1335 /Lib/test/test_lzma.py
parent3e0bdff8a0793d305b972f4a653e4698d440b3ae (diff)
parent95b272b4e0d5438a12702e51e05d03f5a5a8e505 (diff)
downloadcpython-5b4df5813c20fe96f117d0201965b52e86a1a66d.tar.gz
Includes ensurepip and venv packages in nuget package.
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r--Lib/test/test_lzma.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
index b69da065e1..d7a8576d51 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
@@ -526,6 +527,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:
@@ -973,11 +984,11 @@ class FileTestCase(unittest.TestCase):
def test_decompress_limited(self):
"""Decompressed data buffering should be limited"""
- bomb = lzma.compress(bytes(int(2e6)), preset=6)
+ bomb = lzma.compress(b'\0' * int(2e6), preset=6)
self.assertLess(len(bomb), _compression.BUFFER_SIZE)
decomp = LZMAFile(BytesIO(bomb))
- self.assertEqual(bytes(1), decomp.read(1))
+ self.assertEqual(decomp.read(1), b'\0')
max_decomp = 1 + DEFAULT_BUFFER_SIZE
self.assertLessEqual(decomp._buffer.raw.tell(), max_decomp,
"Excessive amount of data was decompressed")
@@ -1218,6 +1229,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):