@@ -136,6 +136,86 @@ def test_config_print_path():
136136 cmd ('config --system --print-path' )
137137
138138
139+ TEST_CASES_CONFIG_LIST_PATHS = [
140+ # (flag, env_var)
141+ ('--local' , 'WEST_CONFIG_LOCAL' ),
142+ ('--system' , 'WEST_CONFIG_SYSTEM' ),
143+ ('--global' , 'WEST_CONFIG_GLOBAL' ),
144+ ]
145+
146+
147+ @pytest .mark .parametrize ("test_case" , TEST_CASES_CONFIG_LIST_PATHS )
148+ def test_config_list_paths (test_case ):
149+ flag , env_var = test_case
150+
151+ # no config is listed (since it does not exist)
152+ stdout = cmd (f'config { flag } --list-paths' )
153+ assert '' == stdout .rstrip ()
154+
155+ # create the config
156+ cmd (f'config { flag } pytest.key val' )
157+
158+ # check that the config is listed now
159+ stdout = cmd (f'config { flag } --list-paths' )
160+ config_path = pathlib .Path (os .environ [env_var ])
161+ assert f'{ config_path } ' == stdout .rstrip ()
162+
163+
164+ def test_config_list_paths_extended ():
165+ WEST_CONFIG_LOCAL = os .environ ['WEST_CONFIG_LOCAL' ]
166+ WEST_CONFIG_GLOBAL = os .environ ['WEST_CONFIG_GLOBAL' ]
167+ WEST_CONFIG_SYSTEM = os .environ ['WEST_CONFIG_SYSTEM' ]
168+
169+ # create the configs
170+ cmd ('config --local pytest.key val' )
171+ cmd ('config --global pytest.key val' )
172+ cmd ('config --system pytest.key val' )
173+
174+ # list the configs
175+ stdout = cmd ('config --list-paths' )
176+ assert (
177+ stdout .splitlines ()
178+ == textwrap .dedent (f'''\
179+ { WEST_CONFIG_GLOBAL }
180+ { WEST_CONFIG_SYSTEM }
181+ { WEST_CONFIG_LOCAL }
182+ ''' ).splitlines ()
183+ )
184+
185+ # create some dropins files
186+ dropin_files = [
187+ pathlib .Path (WEST_CONFIG_GLOBAL + '.d' ) / 'a.conf' ,
188+ pathlib .Path (WEST_CONFIG_GLOBAL + '.d' ) / 'z.conf' ,
189+ pathlib .Path (WEST_CONFIG_SYSTEM + '.d' ) / 'a.conf' ,
190+ pathlib .Path (WEST_CONFIG_SYSTEM + '.d' ) / 'z.conf' ,
191+ pathlib .Path (WEST_CONFIG_LOCAL + '.d' ) / 'a.conf' ,
192+ pathlib .Path (WEST_CONFIG_LOCAL + '.d' ) / 'z.conf' ,
193+ ]
194+ for dropin_file in dropin_files :
195+ dropin_file .parent .mkdir (exist_ok = True )
196+ dropin_file .touch ()
197+
198+ # list the configs
199+ stdout = cmd ('config --list-paths' )
200+ assert (
201+ stdout .splitlines ()
202+ == textwrap .dedent (f'''\
203+ { dropin_files [0 ]}
204+ { dropin_files [1 ]}
205+ { WEST_CONFIG_GLOBAL }
206+ { dropin_files [2 ]}
207+ { dropin_files [3 ]}
208+ { WEST_CONFIG_SYSTEM }
209+ { dropin_files [4 ]}
210+ { dropin_files [5 ]}
211+ { WEST_CONFIG_LOCAL }
212+ ''' ).splitlines ()
213+ )
214+
215+ # print nothing if local config does not exist (exit code 0)
216+ del os .environ ['WEST_CONFIG_LOCAL' ]
217+
218+
139219def test_config_local ():
140220 # test_config_system for local variables.
141221 cmd ('config --local pytest.local foo' )
0 commit comments