diff options
-rw-r--r-- | gemato/compression.py | 9 | ||||
-rw-r--r-- | tests/test_compression.py | 13 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gemato/compression.py b/gemato/compression.py index 023f308..2c810a2 100644 --- a/gemato/compression.py +++ b/gemato/compression.py @@ -108,3 +108,12 @@ def open_potentially_compressed_path(path, mode, **kwargs): raise return fs + + +def get_potential_compressed_names(path): + """ + Get a list of all possible variants of @path with supported + compressions (including the uncompressed path). + """ + + return [path + x for x in ('', '.gz', '.bz2', '.lzma', '.xz')] diff --git a/tests/test_compression.py b/tests/test_compression.py index 13c7835..820f23d 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -495,3 +495,16 @@ class NoCompressionTest(unittest.TestCase): cf.write(TEST_STRING.decode('utf8')) self.assertEqual(rf.read(), UTF16_TEST_STRING) + + +class OtherUtilityTests(unittest.TestCase): + def test_get_potential_compressed_names(self): + self.assertSetEqual(frozenset(gemato.compression + .get_potential_compressed_names('test')), + frozenset([ + 'test', + 'test.gz', + 'test.bz2', + 'test.lzma', + 'test.xz', + ])) |