@pytest.fixture(scope="module")
def env(ports):
"""Dictionary containing environment variables for the test."""
- env = os.environ.copy()
+ env = dict(isctest.vars.ALL)
for portname, portnum in ports.items():
env[portname] = str(portnum)
env["builddir"] = f"{env['TOP_BUILDDIR']}/{SYSTEM_TEST_DIR_GIT_PATH}"
env["srcdir"] = f"{env['TOP_SRCDIR']}/{SYSTEM_TEST_DIR_GIT_PATH}"
+ os.environ.update(env)
return env
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
+from collections import ChainMap
+
# pylint: disable=import-error
from .autoconf import AC_VARS # type: ignore
# pylint: enable=import-error
from .basic import BASIC_VARS
-ALL = {**AC_VARS, **BASIC_VARS}
+
+class VarLookup(ChainMap):
+ """A dictionary-like structure to coalesce the variables from different
+ modules without making a copy (which would prevent updating these values
+ from inside the modules)."""
+
+ def __init__(self, *maps):
+ keys = set()
+ for m in maps:
+ overlap = keys.intersection(m.keys())
+ if overlap:
+ raise RuntimeError(f"key(s) are defined multiple times: {overlap}")
+ keys = keys.union(m.keys())
+ super().__init__(*maps)
+
+ def __setitem__(self, *args, **kwargs):
+ raise RuntimeError("read-only structure")
+
+ def keys(self):
+ result = set()
+ for m in self.maps:
+ for key, val in m.items():
+ if val is None: # treat None as unset
+ continue
+ result.add(key)
+ return list(result)
+
+ def __iter__(self):
+ return iter(self.keys())
+
+
+ALL = VarLookup(AC_VARS, BASIC_VARS)