@@ -198,6 +198,86 @@ def test_config_list_paths():
198198 assert 'topdir' in str (WNE )
199199
200200
201+ def test_config_list_search_paths_all ():
202+ _ , err_msg = cmd_raises ('config --list-search-paths pytest.foo' , SystemExit )
203+ assert '--list-search-paths cannot be combined with name argument' in err_msg
204+
205+ WEST_CONFIG_SYSTEM = os .getenv ('WEST_CONFIG_SYSTEM' )
206+ WEST_CONFIG_GLOBAL = os .getenv ('WEST_CONFIG_GLOBAL' )
207+ WEST_CONFIG_LOCAL = os .getenv ('WEST_CONFIG_LOCAL' )
208+
209+ # one config file set via env variables
210+ stdout = cmd ('config --list-search-paths' )
211+ assert stdout .splitlines () == [WEST_CONFIG_SYSTEM , WEST_CONFIG_GLOBAL , WEST_CONFIG_LOCAL ]
212+
213+ # multiple config files are set via env variables
214+ conf_dir = (pathlib .Path ('some' ) / 'conf' ).resolve ()
215+ config_s1 = conf_dir / "s1"
216+ config_s2 = conf_dir / "s2"
217+ config_g1 = conf_dir / "g1"
218+ config_g2 = conf_dir / "g2"
219+ config_l1 = conf_dir / "l1"
220+ config_l2 = conf_dir / "l2"
221+ env = {
222+ 'WEST_CONFIG_SYSTEM' : f'{ config_s1 } { os .pathsep } { config_s2 } ' ,
223+ 'WEST_CONFIG_GLOBAL' : f'{ config_g1 } { os .pathsep } { config_g2 } ' ,
224+ 'WEST_CONFIG_LOCAL' : f'{ config_l1 } { os .pathsep } { config_l2 } ' ,
225+ }
226+ with update_env (env ):
227+ stdout = cmd ('config --list-search-paths' )
228+ search_paths = stdout .splitlines ()
229+ assert search_paths == [
230+ str (config_s1 ),
231+ str (config_s2 ),
232+ str (config_g1 ),
233+ str (config_g2 ),
234+ str (config_l1 ),
235+ str (config_l2 ),
236+ ]
237+
238+ # unset all west config env variables
239+ env = {
240+ 'WEST_CONFIG_SYSTEM' : None ,
241+ 'WEST_CONFIG_GLOBAL' : None ,
242+ 'WEST_CONFIG_LOCAL' : None ,
243+ }
244+ with update_env (env ):
245+ # outside west topdir: show system and global config search paths
246+ stdout = cmd ('config --list-search-paths' )
247+ search_paths = stdout .splitlines ()
248+ assert len (search_paths ) == 2
249+
250+ # inside west topdir: show system, global and local config search paths
251+ west_topdir = pathlib .Path ('.' )
252+ with tmp_west_topdir (west_topdir ):
253+ stdout = cmd ('config --list-search-paths' )
254+ search_paths = stdout .splitlines ()
255+ assert len (search_paths ) == 3
256+ local_path = (west_topdir / '.west' / 'config' ).resolve ()
257+ assert search_paths [2 ] == str (local_path )
258+
259+
260+ @pytest .mark .parametrize ("location" , [LOCAL , GLOBAL , SYSTEM ])
261+ def test_config_list_search_paths (location ):
262+ flag = '' if location == ALL else west_flag [location ]
263+ env_var = west_env [location ] if flag else None
264+
265+ west_topdir = pathlib .Path ('.' )
266+ config1 = (west_topdir / 'some' / 'config 1' ).resolve ()
267+ config2 = pathlib .Path ('relative' ) / 'c 2'
268+ config2_abs = config2 .resolve ()
269+ with tmp_west_topdir (west_topdir ):
270+ env = {env_var : f'{ config1 } { os .pathsep } { config2 } ' }
271+ # env variable contains two config files
272+ with update_env (env ):
273+ stdout = cmd (f'config { flag } --list-search-paths' )
274+ assert stdout .splitlines () == [str (config1 ), str (config2_abs )]
275+ # if no env var is set it should list one default search path
276+ with update_env ({env_var : None }):
277+ stdout = cmd (f'config { flag } --list-search-paths' )
278+ assert len (stdout .splitlines ()) == 1
279+
280+
201281def test_config_local ():
202282 # test_config_system for local variables.
203283 cmd ('config --local pytest.local foo' )
0 commit comments