Skip to content

Commit 79ac0dc

Browse files
committed
allow filenames with only .zip, .gz, etc suffix
1 parent 16ab14c commit 79ac0dc

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

hatanaka/general_compression.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ def get_decompressed_path(path: Union[Path, str]) -> Path:
130130
if parts[-1].lower() in ['z', 'gz', 'bz2', 'zip']:
131131
parts.pop()
132132
suffix = parts[-1]
133-
if re.fullmatch(r'\d\dd', suffix):
133+
if len(parts) == 1:
134+
return path.parent / (parts[0] + '.rnx')
135+
elif re.fullmatch(r'\d\dd', suffix):
134136
suffix = suffix[:2] + 'o'
135137
elif re.fullmatch(r'\d\dD', suffix):
136138
suffix = suffix[:2] + 'O'

hatanaka/test/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def get_data_path(fname):
1313
for x in ['.21d', '.crx']:
1414
fname = fname.replace(x.lower(), '.crx')
1515
fname = fname.replace(x.upper(), '.crx')
16+
m = re.fullmatch(r'sample\.(zip|gz|bz2)', fname)
17+
if m:
18+
fname = 'sample.crx.' + m.group(1)
1619
return files(hatanaka.test.data) / fname
1720

1821

hatanaka/test/test_general_compression.py

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
('.rnx.bz2', '.rnx'),
2828
('.21o', '.21o'),
2929
('.21o.gz', '.21o'),
30+
('.zip', '.rnx'),
31+
('.gz', '.rnx'),
32+
('.bz2', '.rnx'),
3033
]
3134

3235

@@ -60,6 +63,7 @@ def test_decompress_on_disk(tmp_path, crx_sample, rnx_bytes, input_suffix, expec
6063
out_path = decompress_on_disk(sample_path)
6164
# check
6265
assert out_path.exists()
66+
print(list(tmp_path.glob('*')))
6367
assert out_path == tmp_path / ('sample' + expected_suffix)
6468
assert clean(out_path.read_bytes()) == clean(rnx_bytes)
6569

0 commit comments

Comments
 (0)