|
6 | 6 |
|
7 | 7 | from mokelumne.util import file_transfer |
8 | 8 |
|
| 9 | +@pytest.fixture(scope="session") |
| 10 | +def manifest_source_path(tmpdir_factory): |
| 11 | + tmp_path = Path(tmpdir_factory.mktemp("manifest_source")) |
| 12 | + visible_file = tmp_path / "visible.tif" |
| 13 | + visible_file.write_text("hello", encoding="utf-8") |
| 14 | + |
| 15 | + hidden_file = tmp_path / ".hidden.txt" |
| 16 | + hidden_file.write_text("secret", encoding="utf-8") |
| 17 | + |
| 18 | + hidden_dir = tmp_path / ".hidden" |
| 19 | + hidden_dir.mkdir() |
| 20 | + hidden_dir_file = hidden_dir / "nested.txt" |
| 21 | + hidden_dir_file.write_text("nested", encoding="utf-8") |
| 22 | + |
| 23 | + ds_store = tmp_path / ".DS_Store" |
| 24 | + ds_store.write_text("folder metadata", encoding="utf-8") |
| 25 | + |
| 26 | + thumbs_db = tmp_path / "Thumbs.db" |
| 27 | + thumbs_db.write_text("thumbnail images db", encoding="utf-8") |
| 28 | + |
| 29 | + return tmp_path |
9 | 30 |
|
10 | 31 | class TestFileTransfer: |
11 | 32 | """Tests for the Mokelumne file transfer module.""" |
@@ -69,31 +90,25 @@ def test_build_manifest_includes_nested_files(self, tmp_path: Path): |
69 | 90 | } |
70 | 91 | assert len(result) == 2 |
71 | 92 |
|
72 | | - def test_build_manifest_excludes_hidden_and_excluded_files(self, tmp_path: Path): |
| 93 | + @pytest.mark.parametrize( |
| 94 | + "pattern,expected", |
| 95 | + [ |
| 96 | + pytest.param( |
| 97 | + None, {"visible.tif"}, id="with_default_regex" |
| 98 | + ), |
| 99 | + pytest.param( |
| 100 | + r"^(visible\.tif|\.(.*))$", {"Thumbs.db"}, id="with_custom_regex" |
| 101 | + ) |
| 102 | + ] |
| 103 | + ) |
| 104 | + def test_build_manifest_excludes_hidden_and_excluded_files(self, manifest_source_path, pattern, expected): |
73 | 105 | """Ensure that build_manifest skips hidden and system junk files.""" |
74 | | - visible_file = tmp_path / "visible.tif" |
75 | | - visible_file.write_text("hello", encoding="utf-8") |
76 | | - |
77 | | - hidden_file = tmp_path / ".hidden.txt" |
78 | | - hidden_file.write_text("secret", encoding="utf-8") |
79 | | - |
80 | | - hidden_dir = tmp_path / ".hidden" |
81 | | - hidden_dir.mkdir() |
82 | | - hidden_dir_file = hidden_dir / "nested.txt" |
83 | | - hidden_dir_file.write_text("nested", encoding="utf-8") |
84 | | - |
85 | | - ds_store = tmp_path / ".DS_Store" |
86 | | - ds_store.write_text("folder metadata", encoding="utf-8") |
87 | | - |
88 | | - thumbs_db = tmp_path / "Thumbs.db" |
89 | | - thumbs_db.write_text("thumbnail images db", encoding="utf-8") |
90 | | - |
91 | | - result = file_transfer.build_file_manifest(tmp_path) |
| 106 | + result = file_transfer.build_file_manifest(manifest_source_path, exclude_regex=pattern) |
92 | 107 |
|
93 | 108 | paths = {entry["path"] for entry in result["files"]} |
94 | 109 |
|
95 | | - assert paths == {"visible.tif"} |
96 | | - assert len(result["files"]) == 1 |
| 110 | + assert paths == expected |
| 111 | + assert len(result["files"]) == len(expected) |
97 | 112 |
|
98 | 113 | @pytest.mark.parametrize( |
99 | 114 | ("input_path", "expected_path"), |
|
0 commit comments