99from typing import Any
1010
1111import pytest
12- from conftest import cmd , cmd_raises , update_env
12+ from conftest import chdir , cmd , cmd_raises , update_env
1313
1414from west import configuration as config
15- from west .util import PathType
15+ from west .util import PathType , WestNotFound
1616
1717SYSTEM = config .ConfigFile .SYSTEM
1818GLOBAL = config .ConfigFile .GLOBAL
@@ -125,6 +125,10 @@ def test_config_list_paths():
125125 WEST_CONFIG_GLOBAL = os .environ ['WEST_CONFIG_GLOBAL' ]
126126 WEST_CONFIG_SYSTEM = os .environ ['WEST_CONFIG_SYSTEM' ]
127127
128+ # Fixture is pristine?
129+ stdout = cmd ('config --list-paths' )
130+ assert stdout .splitlines () == []
131+
128132 # create the configs
129133 cmd ('config --local pytest.key val' )
130134 cmd ('config --global pytest.key val' )
@@ -149,9 +153,11 @@ def test_config_list_paths():
149153 stdout = cmd ('config --list-paths' )
150154 assert stdout .splitlines () == []
151155
152- # list local config as it exists (determined from filesystem , not from env)
156+ # list local config as it exists (default value , not overriden by fixture env)
153157 del os .environ ['WEST_CONFIG_LOCAL' ]
154158 default_config = pathlib .Path ('.west' ) / 'config'
159+ defconfig_abs_str = str (default_config .absolute ())
160+ # Cheap fake workspace, enough to fool west for this test
155161 default_config .parent .mkdir ()
156162 default_config .write_text (
157163 textwrap .dedent ('''\
@@ -161,7 +167,26 @@ def test_config_list_paths():
161167 ''' )
162168 )
163169 stdout = cmd ('config --list-paths' )
164- assert stdout .splitlines () == [str (default_config .absolute ())]
170+ assert stdout .splitlines () == [defconfig_abs_str ]
171+
172+ # Now point a relative WEST_CONFIG_x to the same file and check it
173+ # is anchored to the west topdir (referring to the same file twice
174+ # could break other west features but must not break the low-level
175+ # --list-paths)
176+ assert not default_config .is_absolute ()
177+ os .mkdir ('sub0' )
178+ for e in ['WEST_CONFIG_GLOBAL' , 'WEST_CONFIG_SYSTEM' ]:
179+ with update_env ({e : str (default_config )}):
180+ for d in ['.' , 'sub0' , '.west' ]:
181+ with chdir (d ):
182+ stdout = cmd ('config --list-paths' )
183+ assert stdout .splitlines () == [defconfig_abs_str , defconfig_abs_str ]
184+
185+ # Leave the fake west workspace
186+ with chdir ('..' ):
187+ with pytest .raises (WestNotFound ) as WNE :
188+ stdout = cmd ('config --list-paths' )
189+ assert 'topdir' in str (WNE )
165190
166191
167192def test_config_local ():
0 commit comments