diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-10-25 22:54:14 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-10-25 22:54:14 +0200 |
commit | b05e39d1fb283c9beff61f740e756e5a66922f0d (patch) | |
tree | 573734245a8c9733099006138a570edc4be23875 | |
parent | 013e7a5bf896e3a1626bf40eebfd790821e94cf2 (diff) | |
download | gemato-b05e39d1fb283c9beff61f740e756e5a66922f0d.tar.gz |
gemato.compression: Support getting potential compressed names
-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', + ])) |