@@ -103,6 +103,89 @@ def test_config_print_path():
103103 stdout = cmd ('config --system --print-path' )
104104 assert os .environ ["WEST_CONFIG_SYSTEM" ] == stdout .rstrip ()
105105
106+ # print nothing if local config does not exist (exit code 0)
107+ del os .environ ['WEST_CONFIG_LOCAL' ]
108+ stdout = cmd ('config --local --print-path' )
109+ assert "" == stdout .rstrip ()
110+
111+
112+ TEST_CASES_CONFIG_LIST_PATHS = [
113+ # (flag, env_var)
114+ ('--local' , 'WEST_CONFIG_LOCAL' ),
115+ ('--system' , 'WEST_CONFIG_SYSTEM' ),
116+ ('--global' , 'WEST_CONFIG_GLOBAL' ),
117+ ]
118+
119+
120+ @pytest .mark .parametrize ("test_case" , TEST_CASES_CONFIG_LIST_PATHS )
121+ def test_config_list_paths (test_case ):
122+ flag , env_var = test_case
123+
124+ # no config is listed (since it does not exist)
125+ stdout = cmd (f'config { flag } --list-paths' )
126+ assert '' == stdout .rstrip ()
127+
128+ # create the config
129+ cmd (f'config { flag } pytest.key val' )
130+
131+ # check that the config is listed now
132+ stdout = cmd (f'config { flag } --list-paths' )
133+ config_path = pathlib .Path (os .environ [env_var ])
134+ assert f'{ config_path } ' == stdout .rstrip ()
135+
136+
137+ def test_config_list_paths_extended ():
138+ WEST_CONFIG_LOCAL = os .environ ['WEST_CONFIG_LOCAL' ]
139+ WEST_CONFIG_GLOBAL = os .environ ['WEST_CONFIG_GLOBAL' ]
140+ WEST_CONFIG_SYSTEM = os .environ ['WEST_CONFIG_SYSTEM' ]
141+
142+ # create the configs
143+ cmd ('config --local pytest.key val' )
144+ cmd ('config --global pytest.key val' )
145+ cmd ('config --system pytest.key val' )
146+
147+ # list the configs
148+ stdout = cmd ('config --list-paths' )
149+ assert (
150+ stdout .splitlines ()
151+ == textwrap .dedent (f'''\
152+ { WEST_CONFIG_GLOBAL }
153+ { WEST_CONFIG_SYSTEM }
154+ { WEST_CONFIG_LOCAL }
155+ ''' ).splitlines ()
156+ )
157+
158+ # create some dropins files
159+ dropin_files = [
160+ pathlib .Path (WEST_CONFIG_GLOBAL + '.d' ) / 'a.conf' ,
161+ pathlib .Path (WEST_CONFIG_GLOBAL + '.d' ) / 'z.conf' ,
162+ pathlib .Path (WEST_CONFIG_SYSTEM + '.d' ) / 'a.conf' ,
163+ pathlib .Path (WEST_CONFIG_SYSTEM + '.d' ) / 'z.conf' ,
164+ pathlib .Path (WEST_CONFIG_LOCAL + '.d' ) / 'a.conf' ,
165+ pathlib .Path (WEST_CONFIG_LOCAL + '.d' ) / 'z.conf' ,
166+ ]
167+ for dropin_file in dropin_files :
168+ dropin_file .parent .mkdir (exist_ok = True )
169+ dropin_file .touch ()
170+
171+ # list the configs
172+ stdout = cmd ('config --list-paths' )
173+ assert (
174+ stdout .splitlines ()
175+ == textwrap .dedent (f'''\
176+ { dropin_files [0 ]}
177+ { dropin_files [1 ]}
178+ { WEST_CONFIG_GLOBAL }
179+ { dropin_files [2 ]}
180+ { dropin_files [3 ]}
181+ { WEST_CONFIG_SYSTEM }
182+ { dropin_files [4 ]}
183+ { dropin_files [5 ]}
184+ { WEST_CONFIG_LOCAL }
185+ ''' ).splitlines ()
186+ )
187+
188+ # print nothing if local config does not exist (exit code 0)
106189 del os .environ ['WEST_CONFIG_LOCAL' ]
107190 stdout = cmd ('config --local --print-path' )
108191 assert "" == stdout .rstrip ()
0 commit comments