@@ -34,6 +34,36 @@ def test_cache_clear_all(
3434 repository_dirs : list [Path ],
3535 caches : list [FileCache [dict [str , str ]]],
3636 inputs : str ,
37+ ) -> None :
38+ exit_code = tester .execute ("cache clear --all" , inputs = inputs )
39+
40+ assert exit_code == 0
41+ assert tester .io .fetch_output () == ""
42+
43+ if inputs == "yes" :
44+ assert not repository_dirs [0 ].exists () or not any (repository_dirs [0 ].iterdir ())
45+ assert not repository_dirs [1 ].exists () or not any (repository_dirs [1 ].iterdir ())
46+ assert not caches [0 ].has ("cachy:0.1" )
47+ assert not caches [0 ].has ("cleo:0.2" )
48+ assert not caches [1 ].has ("cachy:0.1" )
49+ assert not caches [1 ].has ("cashy:0.2" )
50+ else :
51+ assert any ((repository_cache_dir / repositories [0 ]).iterdir ())
52+ assert any ((repository_cache_dir / repositories [1 ]).iterdir ())
53+ assert caches [0 ].has ("cachy:0.1" )
54+ assert caches [0 ].has ("cleo:0.2" )
55+ assert caches [1 ].has ("cachy:0.1" )
56+ assert caches [1 ].has ("cashy:0.2" )
57+
58+
59+ @pytest .mark .parametrize ("inputs" , ["yes" , "no" ])
60+ def test_cache_clear_all_one_cache (
61+ tester : ApplicationTester ,
62+ repository_cache_dir : Path ,
63+ repositories : list [str ],
64+ repository_dirs : list [Path ],
65+ caches : list [FileCache [dict [str , str ]]],
66+ inputs : str ,
3767) -> None :
3868 exit_code = tester .execute (f"cache clear { repositories [0 ]} --all" , inputs = inputs )
3969
@@ -54,6 +84,39 @@ def test_cache_clear_all(
5484 assert caches [1 ].has ("cashy:0.2" )
5585
5686
87+ def test_cache_clear_all_no_entries (tester : ApplicationTester ) -> None :
88+ exit_code = tester .execute ("cache clear --all" )
89+
90+ assert exit_code == 0
91+ assert tester .io .fetch_output ().strip () == "No cache entries"
92+
93+
94+ def test_cache_clear_all_one_cache_no_entries (
95+ tester : ApplicationTester ,
96+ repository_cache_dir : Path ,
97+ repositories : list [str ],
98+ ) -> None :
99+ exit_code = tester .execute (f"cache clear { repositories [0 ]} --all" )
100+
101+ assert exit_code == 0
102+
103+ assert tester .io .fetch_output ().strip () == f"No cache entries for { repositories [0 ]} "
104+
105+
106+ @pytest .mark .parametrize ("with_repo" , [False , True ])
107+ def test_cache_clear_missing_option (
108+ tester : ApplicationTester , repositories : list [str ], with_repo : bool
109+ ) -> None :
110+ command = f"cache clear { repositories [0 ]} " if with_repo else "cache clear"
111+ exit_code = tester .execute (command )
112+
113+ assert exit_code == 1
114+ assert (
115+ "Add the --all option if you want to clear all cache entries"
116+ in tester .io .fetch_error ()
117+ )
118+
119+
57120@pytest .mark .parametrize ("inputs" , ["yes" , "no" ])
58121@pytest .mark .parametrize ("package_name" , ["cachy" , "Cachy" ])
59122def test_cache_clear_pkg (
0 commit comments