|
1 | 1 | """Test core archival features.""" |
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | | - |
| 4 | +import pytest |
5 | 5 |
|
6 | 6 | from emmet.archival.core import FileArchive, _get_path_relative_to_parent |
| 7 | +from emmet.archival.utils import CompressionType |
7 | 8 |
|
8 | 9 |
|
9 | | -def test_file_archiver(tmp_dir): |
| 10 | +@pytest.mark.parametrize("compressor", ["ZSTD", "GZIP"]) |
| 11 | +def test_file_archiver(tmp_dir, compressor): |
10 | 12 |
|
11 | 13 | lorem = [ |
12 | 14 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", |
@@ -48,21 +50,22 @@ def test_file_archiver(tmp_dir): |
48 | 50 | ) |
49 | 51 |
|
50 | 52 | # Now archive this |
51 | | - archiver = FileArchive.from_directory("root", depth=None) |
| 53 | + archiver = FileArchive.from_directory("root", depth=None, compression=compressor) |
52 | 54 | archiver.to_archive("lorem.h5") |
53 | 55 |
|
54 | 56 | # extract and compare extracted file structure + data to original |
55 | | - output_path = Path("lorem").absolute() |
56 | | - archiver.extract("lorem.h5", output_dir=output_path) |
57 | | - extracted = { |
58 | | - str(_get_path_relative_to_parent(p, output_path)): p.read_text() |
59 | | - for p in output_path.glob("**/*.txt") |
60 | | - } |
61 | | - |
62 | 57 | orig = { |
63 | 58 | str(_get_path_relative_to_parent(p, Path("root").absolute())): p.read_text() |
64 | 59 | for p in fs |
65 | 60 | } |
66 | 61 |
|
67 | | - assert set(extracted) == set(orig) |
68 | | - assert all(v == extracted[k] for k, v in orig.items()) |
| 62 | + output_path = Path("lorem").absolute() |
| 63 | + for compression in (CompressionType.AUTO_DETECT, compressor): |
| 64 | + archiver.extract("lorem.h5", output_dir=output_path, compression=compression) |
| 65 | + extracted = { |
| 66 | + str(_get_path_relative_to_parent(p, output_path)): p.read_text() |
| 67 | + for p in output_path.glob("**/*.txt") |
| 68 | + } |
| 69 | + |
| 70 | + assert set(extracted) == set(orig) |
| 71 | + assert all(v == extracted[k] for k, v in orig.items()) |
0 commit comments