mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Coalesce system test variables
Provide a single point of access to all the variables used by tests. Use a custom dict-like structure to access the underlying data without making a copy. This allows the individual modules to update the contents at runtime, which is used for some variables.
This commit is contained in:
@@ -276,11 +276,12 @@ def control_port(ports):
|
||||
@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
|
||||
|
||||
|
||||
|
@@ -9,10 +9,43 @@
|
||||
# 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)
|
||||
|
Reference in New Issue
Block a user