Skip to content

Commit dca6d0f

Browse files
marc-hbpdgendt
authored andcommitted
tests: config: WEST_CONFIG_x are relative to topdir
Add test for #871 fixed in the previous commit. Signed-off-by: Marc Herbert <[email protected]>
1 parent 7570e23 commit dca6d0f

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tests/test_config.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from typing import Any
1010

1111
import pytest
12-
from conftest import cmd, cmd_raises, update_env
12+
from conftest import chdir, cmd, cmd_raises, update_env
1313

1414
from west import configuration as config
15-
from west.util import PathType
15+
from west.util import PathType, WestNotFound
1616

1717
SYSTEM = config.ConfigFile.SYSTEM
1818
GLOBAL = 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

167192
def test_config_local():

0 commit comments

Comments
 (0)