@@ -75,6 +75,10 @@ def dummy_count_free_space(entry_self: EntryPoint) -> float: # noqa
7575 monkeypatch .setattr ("mac_cleanup.config.Config.__init__" , dummy_config_init )
7676 monkeypatch .setattr ("mac_cleanup.config.Config.__call__" , dummy_config_call )
7777
78+ # Create EntryPoint and mock it
79+ mock_entry_point = EntryPoint ()
80+ monkeypatch .setattr (EntryPoint , "__new__" , lambda : mock_entry_point )
81+
7882 # Simulate count_free_space results
7983 monkeypatch .setattr (EntryPoint , "count_free_space" , dummy_count_free_space )
8084
@@ -86,7 +90,7 @@ def dummy_count_free_space(entry_self: EntryPoint) -> float: # noqa
8690 ]
8791
8892 # Simulate execution list in BaseCollector
89- monkeypatch .setattr (EntryPoint .base_collector , "_execute_list" , dummy_execute_list )
93+ monkeypatch .setattr (mock_entry_point .base_collector , "_execute_list" , dummy_execute_list )
9094
9195 # Call entrypoint
9296 main ()
@@ -128,8 +132,12 @@ def dummy_config_call(config_path_: Pathlib, configuration_prompted: bool) -> No
128132 monkeypatch .setattr ("mac_cleanup.config.Config.__init__" , dummy_config_init )
129133 monkeypatch .setattr ("mac_cleanup.config.Config.__call__" , dummy_config_call )
130134
135+ # Create EntryPoint and mock it
136+ mock_entry_point = EntryPoint ()
137+ monkeypatch .setattr (EntryPoint , "__new__" , lambda : mock_entry_point )
138+
131139 # Simulate count_dry with predefined result
132- monkeypatch .setattr (EntryPoint .base_collector , "_count_dry" , dummy_count_dry )
140+ monkeypatch .setattr (mock_entry_point .base_collector , "_count_dry" , dummy_count_dry )
133141
134142 # Simulate empty cleanup
135143 monkeypatch .setattr (EntryPoint , "cleanup" , dummy_cleanup )
@@ -177,8 +185,12 @@ def dummy_input(*args: Any, **kwargs: Any) -> None: # noqa
177185 monkeypatch .setattr ("mac_cleanup.config.Config.__init__" , dummy_config_init )
178186 monkeypatch .setattr ("mac_cleanup.config.Config.__call__" , dummy_config_call )
179187
188+ # Create EntryPoint and mock it
189+ mock_entry_point = EntryPoint ()
190+ monkeypatch .setattr (EntryPoint , "__new__" , lambda : mock_entry_point )
191+
180192 # Simulate count_dry with predefined result
181- monkeypatch .setattr (EntryPoint .base_collector , "_count_dry" , dummy_count_dry )
193+ monkeypatch .setattr (mock_entry_point .base_collector , "_count_dry" , dummy_count_dry )
182194
183195 # Simulate dry run was prompted
184196 monkeypatch .setattr ("mac_cleanup.parser.Args.dry_run" , True )
@@ -196,3 +208,18 @@ def dummy_input(*args: Any, **kwargs: Any) -> None: # noqa
196208 # Check error message and exit message
197209 assert "Do not enter symbols that can't be decoded to UTF-8" in captured_stdout
198210 assert "Exiting..." in captured_stdout
211+
212+ @pytest .mark .parametrize ("xdg_env_set" , [True , False ])
213+ def test_config_home (self , xdg_env_set : bool , monkeypatch : MonkeyPatch ):
214+ """Test xdg and default config in :class:`mac_cleanup.main.EntryPoint`"""
215+
216+ expected_path : str
217+
218+ if xdg_env_set :
219+ monkeypatch .setenv ("XDG_CONFIG_HOME" , "config_home" )
220+ expected_path = "config_home/mac_cleanup_py/config.toml"
221+ else :
222+ monkeypatch .setattr ("pathlib.Path.home" , lambda : Pathlib ("home" ))
223+ expected_path = "home/.mac_cleanup_py"
224+
225+ assert str (EntryPoint ().config_path ) == expected_path
0 commit comments