From 013e7a5bf896e3a1626bf40eebfd790821e94cf2 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Wed, 25 Oct 2017 22:43:02 +0200 Subject: test_compression: Check if .fileno() is passed through correctly --- tests/test_compression.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/test_compression.py') diff --git a/tests/test_compression.py b/tests/test_compression.py index 97b319a..13c7835 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -93,6 +93,20 @@ L0stUijJSFXISayqVEjJTwcAlGd4GBcAAAA= with gemato.compression.open_compressed_file('gz', rf, 'rb') as gz: self.assertEqual(gz.read(), UTF16_TEST_STRING) + def test_open_potentially_compressed_path_fileno_passthrough(self): + with tempfile.NamedTemporaryFile(suffix='.gz') as rf: + fs1 = gemato.compression.open_potentially_compressed_path( + rf.name, 'w', encoding='utf_16_be') + with fs1 as cf: + self.assertListEqual([f.fileno() for f in fs1.files], + [cf.fileno() for f in fs1.files]) + + fs2 = gemato.compression.open_potentially_compressed_path( + rf.name, 'r', encoding='utf_16_be') + with fs2 as cf: + self.assertListEqual([f.fileno() for f in fs2.files], + [cf.fileno() for f in fs2.files]) + class Bzip2CompressionTest(unittest.TestCase): BASE64 = b''' @@ -196,6 +210,20 @@ OxleaA== except gemato.exceptions.UnsupportedCompression: raise unittest.SkipTest('bz2 compression unsupported') + def test_open_potentially_compressed_path_fileno_passthrough(self): + with tempfile.NamedTemporaryFile(suffix='.gz') as rf: + fs1 = gemato.compression.open_potentially_compressed_path( + rf.name, 'w', encoding='utf_16_be') + with fs1 as cf: + self.assertListEqual([f.fileno() for f in fs1.files], + [cf.fileno() for f in fs1.files]) + + fs2 = gemato.compression.open_potentially_compressed_path( + rf.name, 'r', encoding='utf_16_be') + with fs2 as cf: + self.assertListEqual([f.fileno() for f in fs2.files], + [cf.fileno() for f in fs2.files]) + class LZMALegacyCompressionTest(unittest.TestCase): BASE64 = b''' @@ -310,6 +338,20 @@ ADUdSd6zBOkOpekGFH46zix9wE9VT65OVeV479//7uUAAA== except gemato.exceptions.UnsupportedCompression: raise unittest.SkipTest('lzma compression unsupported') + def test_open_potentially_compressed_path_fileno_passthrough(self): + with tempfile.NamedTemporaryFile(suffix='.gz') as rf: + fs1 = gemato.compression.open_potentially_compressed_path( + rf.name, 'w', encoding='utf_16_be') + with fs1 as cf: + self.assertListEqual([f.fileno() for f in fs1.files], + [cf.fileno() for f in fs1.files]) + + fs2 = gemato.compression.open_potentially_compressed_path( + rf.name, 'r', encoding='utf_16_be') + with fs2 as cf: + self.assertListEqual([f.fileno() for f in fs2.files], + [cf.fileno() for f in fs2.files]) + class XZCompressionTest(unittest.TestCase): BASE64 = b''' @@ -400,6 +442,20 @@ dGhlIGxhenkgZG9nAADjZCTmHjHqggABLxeBCEmxH7bzfQEAAAAABFla except gemato.exceptions.UnsupportedCompression: raise unittest.SkipTest('xz compression unsupported') + def test_open_potentially_compressed_path_fileno_passthrough(self): + with tempfile.NamedTemporaryFile(suffix='.gz') as rf: + fs1 = gemato.compression.open_potentially_compressed_path( + rf.name, 'w', encoding='utf_16_be') + with fs1 as cf: + self.assertListEqual([f.fileno() for f in fs1.files], + [cf.fileno() for f in fs1.files]) + + fs2 = gemato.compression.open_potentially_compressed_path( + rf.name, 'r', encoding='utf_16_be') + with fs2 as cf: + self.assertListEqual([f.fileno() for f in fs2.files], + [cf.fileno() for f in fs2.files]) + class NoCompressionTest(unittest.TestCase): """ -- cgit v1.2.3