1515
1616from pathlib import Path
1717
18+ from pyfakefs .fake_filesystem import FakeFilesystem as FFS
19+
1820from incremental import clean_builddir_if_stale , update_module_hash
1921
2022_BUILD = Path ("/build" )
2123_MODULE = Path ("/MODULE.bazel" )
2224_LOCK = Path ("/MODULE.bazel.lock" )
2325
2426
25- def _simulate_old_state (fs , warnings : str | None ) -> None :
27+ def _simulate_old_state (fs : FFS , warnings : str | None ) -> None :
2628 """Helper function to set up a build directory with an old hash and warnings."""
2729
2830 fs .create_dir (_BUILD )
@@ -33,7 +35,9 @@ def _simulate_old_state(fs, warnings: str | None) -> None:
3335 fs .create_file (_BUILD / "warnings.txt" , contents = warnings )
3436
3537
36- def test_clean_removes_build_dir_when_previous_build_had_warnings (fs ) -> None :
38+ def test_clean_removes_build_dir_when_previous_build_had_warnings (
39+ fs : FFS ,
40+ ) -> None :
3741 """If warnings.txt exists and is not empty, the build dir is removed."""
3842
3943 _simulate_old_state (fs , warnings = "WARNING: something went wrong" )
@@ -43,7 +47,7 @@ def test_clean_removes_build_dir_when_previous_build_had_warnings(fs) -> None:
4347 assert not _BUILD .exists ()
4448
4549
46- def test_clean_keeps_build_dir_when_warnings_txt_is_empty (fs ) -> None :
50+ def test_clean_keeps_build_dir_when_warnings_txt_is_empty (fs : FFS ) -> None :
4751 """If warnings.txt exists and is empty, the build dir is kept."""
4852
4953 _simulate_old_state (fs , warnings = "" )
@@ -53,7 +57,7 @@ def test_clean_keeps_build_dir_when_warnings_txt_is_empty(fs) -> None:
5357 assert _BUILD .exists ()
5458
5559
56- def test_clean_is_noop_when_warnings_txt_is_absent (fs ) -> None :
60+ def test_clean_is_noop_when_warnings_txt_is_absent (fs : FFS ) -> None :
5761 """If warnings.txt does not exist, the build dir is kept (no error)."""
5862
5963 _simulate_old_state (fs , warnings = None )
@@ -63,13 +67,15 @@ def test_clean_is_noop_when_warnings_txt_is_absent(fs) -> None:
6367 assert _BUILD .exists ()
6468
6569
66- def test_clean_is_noop_when_build_dir_is_absent (fs ) -> None :
70+ def test_clean_is_noop_when_build_dir_is_absent (fs : FFS ) -> None :
6771 fs .create_file (_MODULE , contents = "stable" )
6872
6973 clean_builddir_if_stale (_BUILD , [_MODULE ])
7074
7175
72- def test_module_changed_removes_build_dir_when_one_sentinel_file_changed (fs ) -> None :
76+ def test_module_changed_removes_build_dir_when_one_sentinel_file_changed (
77+ fs : FFS ,
78+ ) -> None :
7379 _simulate_old_state (fs , warnings = None )
7480
7581 _LOCK .write_bytes (b"new lock" )
@@ -78,15 +84,17 @@ def test_module_changed_removes_build_dir_when_one_sentinel_file_changed(fs) ->
7884 assert not _BUILD .exists ()
7985
8086
81- def test_module_changed_keeps_build_dir_when_all_sentinel_files_unchanged (fs ) -> None :
87+ def test_module_changed_keeps_build_dir_when_all_sentinel_files_unchanged (
88+ fs : FFS ,
89+ ) -> None :
8290 _simulate_old_state (fs , warnings = None )
8391
8492 clean_builddir_if_stale (_BUILD , [_MODULE , _LOCK ])
8593
8694 assert _BUILD .exists ()
8795
8896
89- def test_module_change_after_successful_build_forces_clean (fs ) -> None :
97+ def test_module_change_after_successful_build_forces_clean (fs : FFS ) -> None :
9098 _simulate_old_state (fs , warnings = None )
9199
92100 _MODULE .write_bytes (b"version 2" )
@@ -95,7 +103,7 @@ def test_module_change_after_successful_build_forces_clean(fs) -> None:
95103 assert not _BUILD .exists ()
96104
97105
98- def test_missing_hash_file_triggers_clean (fs ) -> None :
106+ def test_missing_hash_file_triggers_clean (fs : FFS ) -> None :
99107 """If _build/ exists but hash file is absent, treat as stale (e.g. upgrade from old version)."""
100108 fs .create_dir (_BUILD )
101109 fs .create_file (_MODULE , contents = "stable" )
0 commit comments