Skip to content

Commit 05b8a1d

Browse files
Add sentinel to existing tests + add new test
1 parent 3e5a78c commit 05b8a1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

unit_test/main_commands_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def test_clean_cache_when_cache_exists(tmp_path, monkeypatch, capfd):
1515
fake_cache_dir.mkdir(parents=True, exist_ok=True)
1616
assert fake_cache_dir.exists()
1717

18+
cibw_sentinel = fake_cache_dir / ".cibuildwheel_cached"
19+
cibw_sentinel.write_text("# Created by cibuildwheel automatically", encoding="utf-8")
20+
1821
dummy_file = fake_cache_dir / "dummy.txt"
1922
dummy_file.write_text("hello")
2023

@@ -53,6 +56,9 @@ def test_clean_cache_with_error(tmp_path, monkeypatch, capfd):
5356
fake_cache_dir.mkdir(parents=True, exist_ok=True)
5457
assert fake_cache_dir.exists()
5558

59+
cibw_sentinel = fake_cache_dir / ".cibuildwheel_cached"
60+
cibw_sentinel.write_text("# Created by cibuildwheel automatically\n")
61+
5662
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"])
5763

5864
def fake_rmtree(path): # noqa: ARG001
@@ -68,3 +74,21 @@ def fake_rmtree(path): # noqa: ARG001
6874
out, err = capfd.readouterr()
6975
assert f"Clearing cache directory: {fake_cache_dir}" in out
7076
assert "Error clearing cache:" in err
77+
78+
79+
def test_clean_cache_without_sentinel(tmp_path, monkeypatch, capfd):
80+
fake_cache_dir = (tmp_path / "not_a_cache").resolve()
81+
monkeypatch.setattr(main_module, "CIBW_CACHE_PATH", fake_cache_dir)
82+
83+
fake_cache_dir.mkdir(parents=True, exist_ok=True)
84+
85+
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--clean-cache"])
86+
87+
with pytest.raises(SystemExit) as e:
88+
main()
89+
90+
assert e.value.code == 1
91+
92+
out, err = capfd.readouterr()
93+
assert "does not appear to be a cibuildwheel cache directory" in err
94+
assert fake_cache_dir.exists()

0 commit comments

Comments
 (0)