From 0aa3185798b598827fc8a084ed0c131a499148ad Mon Sep 17 00:00:00 2001 From: Joachim Mortensen Date: Mon, 27 May 2024 12:33:03 +0200 Subject: [PATCH] Add conftest.py with environment setup for otherwise non-existent environment variables on CI machine. --- src/ab/configuration/yaml_constructors.py | 13 +++++++------ tests/conftest.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 tests/conftest.py diff --git a/src/ab/configuration/yaml_constructors.py b/src/ab/configuration/yaml_constructors.py index 3a559be..3f6723e 100644 --- a/src/ab/configuration/yaml_constructors.py +++ b/src/ab/configuration/yaml_constructors.py @@ -32,7 +32,7 @@ def resolve_wildcards(path: Path | str) -> Iterable[Path]: return Path(path.root).glob(str(Path(*parts))) -def path_constructor(loader: yaml.Loader, node: yaml.Node) -> Path | list[Path]: +def path_constructor(loader: yaml.Loader, node: yaml.Node) -> None | Path | list[Path]: """ The path constructor can work on two types of input: @@ -84,17 +84,18 @@ def path_constructor(loader: yaml.Loader, node: yaml.Node) -> Path | list[Path]: ) if isinstance(node, yaml.ScalarNode): - single: str = loader.construct_scalar(node) - resolved = list(resolve_wildcards(Path(single))) - + path: Path = Path(loader.construct_scalar(node)) else: # We use loader.construct_object, since there may be YAML aliases inside. # Any YAML alias is assumed to resolve into to a string. multiple: list[str | Path] = [loader.construct_object(v) for v in node.value] - resolved = list(resolve_wildcards(Path(*multiple))) + path = Path(*multiple) + + resolved = list(resolve_wildcards(path)) if not resolved: - raise EnvironmentError(f"Path {path!r} could not be resolved.") + # EnvironmentError(f"Path {path} could not be resolved.") + return None if len(resolved) > 1: return resolved diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..480faf5 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import os + +LOADGPS_setvar = ( + "C", + "DOC", + "PAN", + "MODEL", + "CONFIG", + "D", + "P", + "S", + "U", + "T", +) + +root = "__ab__" + +for env_var in LOADGPS_setvar: + os.environ[env_var] = os.path.join(root, env_var)