summaryrefslogtreecommitdiff
path: root/tests/test_compression.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-26 23:28:47 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-26 23:35:57 +0200
commit9b7f95fe5a159aee6602fc37e34bba4581175f7b (patch)
tree614ea6bf65f2b389dd38a520f97b01d9f32f2e62 /tests/test_compression.py
parentc97ee87d2e374c39944ae943c906978d2f182206 (diff)
downloadgemato-9b7f95fe5a159aee6602fc37e34bba4581175f7b.tar.gz
compression: Fix opening files in text mode without encoding
Diffstat (limited to 'tests/test_compression.py')
-rw-r--r--tests/test_compression.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_compression.py b/tests/test_compression.py
index cdb8c59..5f614d3 100644
--- a/tests/test_compression.py
+++ b/tests/test_compression.py
@@ -84,6 +84,15 @@ L0stUijJSFXISayqVEjJTwcAlGd4GBcAAAA=
wf.name, 'r', encoding='utf_16_be') as cf:
self.assertEqual(cf.read(), TEST_STRING.decode('utf8'))
+ def test_open_potentially_compressed_path_write_with_unicode(self):
+ with tempfile.NamedTemporaryFile(suffix='.gz') as rf:
+ with gemato.compression.open_potentially_compressed_path(
+ rf.name, 'w') as cf:
+ cf.write(TEST_STRING.decode('utf8'))
+
+ with gemato.compression.open_compressed_file('gz', rf, 'rb') as gz:
+ self.assertEqual(gz.read(), TEST_STRING)
+
def test_open_potentially_compressed_path_write_with_encoding(self):
with tempfile.NamedTemporaryFile(suffix='.gz') as rf:
with gemato.compression.open_potentially_compressed_path(
@@ -209,6 +218,18 @@ OxleaA==
except gemato.exceptions.UnsupportedCompression:
raise unittest.SkipTest('bz2 compression unsupported')
+ def test_open_potentially_compressed_path_write_with_unicode(self):
+ with tempfile.NamedTemporaryFile(suffix='.bz2') as rf:
+ try:
+ with gemato.compression.open_potentially_compressed_path(
+ rf.name, 'w') as cf:
+ cf.write(TEST_STRING.decode('utf8'))
+
+ with gemato.compression.open_compressed_file('bz2', rf, 'rb') as bz2:
+ self.assertEqual(bz2.read(), TEST_STRING)
+ except gemato.exceptions.UnsupportedCompression:
+ raise unittest.SkipTest('bz2 compression unsupported')
+
def test_open_potentially_compressed_path_write_with_encoding(self):
with tempfile.NamedTemporaryFile(suffix='.bz2') as rf:
try:
@@ -354,6 +375,18 @@ ADUdSd6zBOkOpekGFH46zix9wE9VT65OVeV479//7uUAAA==
except gemato.exceptions.UnsupportedCompression:
raise unittest.SkipTest('lzma compression unsupported')
+ def test_open_potentially_compressed_path_write_with_unicode(self):
+ with tempfile.NamedTemporaryFile(suffix='.lzma') as rf:
+ try:
+ with gemato.compression.open_potentially_compressed_path(
+ rf.name, 'w') as cf:
+ cf.write(TEST_STRING.decode('utf8'))
+
+ with gemato.compression.open_compressed_file('lzma', rf, 'rb') as lzma:
+ self.assertEqual(lzma.read(), TEST_STRING)
+ except gemato.exceptions.UnsupportedCompression:
+ raise unittest.SkipTest('lzma compression unsupported')
+
def test_open_potentially_compressed_path_write_with_encoding(self):
with tempfile.NamedTemporaryFile(suffix='.lzma') as rf:
try:
@@ -500,6 +533,18 @@ dGhlIGxhenkgZG9nAADjZCTmHjHqggABLxeBCEmxH7bzfQEAAAAABFla
except gemato.exceptions.UnsupportedCompression:
raise unittest.SkipTest('xz compression unsupported')
+ def test_open_potentially_compressed_path_write_with_unicode(self):
+ with tempfile.NamedTemporaryFile(suffix='.xz') as rf:
+ try:
+ with gemato.compression.open_potentially_compressed_path(
+ rf.name, 'w') as cf:
+ cf.write(TEST_STRING.decode('utf8'))
+
+ with gemato.compression.open_compressed_file('xz', rf, 'rb') as xz:
+ self.assertEqual(xz.read(), TEST_STRING)
+ except gemato.exceptions.UnsupportedCompression:
+ raise unittest.SkipTest('xz compression unsupported')
+
def test_open_potentially_compressed_path_write_with_encoding(self):
with tempfile.NamedTemporaryFile(suffix='.xz') as rf:
try:
@@ -575,6 +620,14 @@ class NoCompressionTest(unittest.TestCase):
wf.name, 'r', encoding='utf_16_be') as cf:
self.assertEqual(cf.read(), TEST_STRING.decode('utf8'))
+ def test_open_potentially_compressed_path_write_with_unicode(self):
+ with tempfile.NamedTemporaryFile() as rf:
+ with gemato.compression.open_potentially_compressed_path(
+ rf.name, 'w') as cf:
+ cf.write(TEST_STRING.decode('utf8'))
+
+ self.assertEqual(rf.read(), TEST_STRING)
+
def test_open_potentially_compressed_path_write_with_encoding(self):
with tempfile.NamedTemporaryFile() as rf:
with gemato.compression.open_potentially_compressed_path(