@@ -88,28 +88,43 @@ def test_macos(mocker: MockerFixture, params: dict[str, Any], func: str) -> None
8888)
8989@pytest .mark .parametrize ("multipath" , [pytest .param (True , id = "multipath" ), pytest .param (False , id = "singlepath" )])
9090def test_macos_homebrew (mocker : MockerFixture , params : dict [str , Any ], multipath : bool , site_func : str ) -> None :
91- mocker .patch ("sys.prefix" , "/opt/homebrew/opt/python" )
92-
93- result = getattr (MacOS (multipath = multipath , ** params ), site_func )
94-
95- home = str (Path ("~" ).expanduser ())
96- suffix_elements = tuple (params [i ] for i in ("appname" , "version" ) if i in params )
97- suffix = os .sep .join (("" , * suffix_elements )) if suffix_elements else "" # noqa: PTH118
98-
99- expected_path_map = {
100- "site_cache_path" : Path (f"/opt/homebrew/var/cache{ suffix } " ),
101- "site_data_path" : Path (f"/opt/homebrew/share{ suffix } " ),
102- }
103- expected_map = {
104- "site_data_dir" : f"/opt/homebrew/share{ suffix } " ,
105- "site_config_dir" : f"/opt/homebrew/share{ suffix } " ,
106- "site_cache_dir" : f"/opt/homebrew/var/cache{ suffix } " ,
107- "site_runtime_dir" : f"{ home } /Library/Caches/TemporaryItems{ suffix } " ,
108- }
109- if multipath :
110- expected_map ["site_data_dir" ] += f":/Library/Application Support{ suffix } "
111- expected_map ["site_config_dir" ] += f":/Library/Application Support{ suffix } "
112- expected_map ["site_cache_dir" ] += f":/Library/Caches{ suffix } "
113- expected = expected_path_map [site_func ] if site_func .endswith ("_path" ) else expected_map [site_func ]
114-
115- assert result == expected
91+ test_data = [
92+ {
93+ "sys_prefix" :
"/opt/homebrew/opt/[email protected] /Frameworks/Python.framework/Versions/3.13" ,
94+ "homebrew_prefix" : "/opt/homebrew" ,
95+ },
96+ {
97+ "sys_prefix" :
"/usr/local/opt/[email protected] /Frameworks/Python.framework/Versions/3.13" ,
98+ "homebrew_prefix" : "/usr/local" ,
99+ },
100+ {
101+ "sys_prefix" :
"/myown/arbitrary/prefix/opt/[email protected] /Frameworks/Python.framework/Versions/3.13" ,
102+ "homebrew_prefix" : "/myown/arbitrary/prefix" ,
103+ },
104+ ]
105+ for prefix in test_data :
106+ mocker .patch ("sys.prefix" , prefix ["sys_prefix" ])
107+
108+ result = getattr (MacOS (multipath = multipath , ** params ), site_func )
109+
110+ home = str (Path ("~" ).expanduser ())
111+ suffix_elements = tuple (params [i ] for i in ("appname" , "version" ) if i in params )
112+ suffix = os .sep .join (("" , * suffix_elements )) if suffix_elements else "" # noqa: PTH118
113+
114+ expected_path_map = {
115+ "site_cache_path" : Path (f"{ prefix ['homebrew_prefix' ]} /var/cache{ suffix } " ),
116+ "site_data_path" : Path (f"{ prefix ['homebrew_prefix' ]} /share{ suffix } " ),
117+ }
118+ expected_map = {
119+ "site_data_dir" : f"{ prefix ['homebrew_prefix' ]} /share{ suffix } " ,
120+ "site_config_dir" : f"{ prefix ['homebrew_prefix' ]} /share{ suffix } " ,
121+ "site_cache_dir" : f"{ prefix ['homebrew_prefix' ]} /var/cache{ suffix } " ,
122+ "site_runtime_dir" : f"{ home } /Library/Caches/TemporaryItems{ suffix } " ,
123+ }
124+ if multipath :
125+ expected_map ["site_data_dir" ] += f":/Library/Application Support{ suffix } "
126+ expected_map ["site_config_dir" ] += f":/Library/Application Support{ suffix } "
127+ expected_map ["site_cache_dir" ] += f":/Library/Caches{ suffix } "
128+ expected = expected_path_map [site_func ] if site_func .endswith ("_path" ) else expected_map [site_func ]
129+
130+ assert result == expected
0 commit comments