From: Benedikt Niedermayr <
benedikt....@siemens.com>
These additional test cases check if the env section
can:
- export variables with their default value
- add variables with 'None' assigned only to
BB_ENV_PASSTHROUGH_ADDITIONS or to the deprecated
BB_ENV_EXTRAWHITE
The BB_ENV_EXTRAWHITE variable is still present, so a test case has also
been added for this.
tests/test_environment_variables.py | 52 +++++++++++++++++++
tests/test_environment_variables/test_env.yml | 9 ++++
2 files changed, 61 insertions(+)
create mode 100644 tests/test_environment_variables/test_env.yml
diff --git a/tests/test_environment_variables.py b/tests/test_environment_variables.py
index d965f7a..b2318af 100644
--- a/tests/test_environment_variables.py
+++ b/tests/test_environment_variables.py
@@ -1,5 +1,6 @@
import os
import shutil
+import pathlib
from kas import kas
@@ -28,3 +29,54 @@ def test_build_dir_can_be_specified_by_environment_variable(changedir, tmpdir):
del os.environ['KAS_BUILD_DIR']
assert os.path.exists(os.path.join(build_dir, 'conf'))
+
+
+def _test_env_section_export(changedir, tmpdir, bb_env_var):
+ conf_dir = str(tmpdir.mkdir('test_env_variables'))
+ build_dir = str(tmpdir.mkdir('test_build_dir'))
+ env_out = pathlib.Path(build_dir) / 'env_out'
+ init_build_env = pathlib.Path(conf_dir) / 'oe-init-build-env'
+
+ shutil.rmtree(conf_dir, ignore_errors=True)
+ shutil.rmtree(build_dir, ignore_errors=True)
+ shutil.copytree('tests/test_environment_variables', conf_dir)
+ os.chdir(conf_dir)
+
+ # Overwrite oe-init-build-env script
+ # BB_ENV_EXTRAWHITE or BB_ENV_PASSTHROUGH_ADDITIONS is only exported by
+ # kas when it has already been exported in the buildenv script
+ script = """#!/bin/sh
+ export %s="FOO"
+ """ % bb_env_var
+ init_build_env.unlink()
+ init_build_env.write_text(script)
+ init_build_env.chmod(0o775)
+
+ os.environ['KAS_BUILD_DIR'] = build_dir
+ kas.kas(['shell', '-c', f'env >{env_out}', 'test_env.yml'])
+ del os.environ['KAS_BUILD_DIR']
+
+ test_env = {}
+ with env_out.open() as f:
+ for line in f.readlines():
+ key, val = line.split("=", 1)
+ test_env[key] = val.strip()
+
+ # Variables with 'None' assigned should not be added to environment
+ try:
+ _ = test_env["TESTVAR_ONLY_WHITELIST"]
+ assert False
+ except KeyError:
+ assert True
+
+ assert test_env["TESTVAR_DEFAULT_VAL"] == "BAR"
+ assert "TESTVAR_ONLY_WHITELIST" in test_env[bb_env_var]
+
+
+# BB_ENV_EXTRAWHITE is deprecated but may still be used
+def test_env_section_export_bb_extra_white(changedir, tmpdir):
+ _test_env_section_export(changedir, tmpdir, "BB_ENV_EXTRAWHITE")
+
+
+def test_env_section_export_bb_env_passthrough_additions(changedir, tmpdir):
+ _test_env_section_export(changedir, tmpdir, "BB_ENV_PASSTHROUGH_ADDITIONS")
diff --git a/tests/test_environment_variables/test_env.yml b/tests/test_environment_variables/test_env.yml
new file mode 100644
index 0000000..6ab9b41
--- /dev/null
+++ b/tests/test_environment_variables/test_env.yml
@@ -0,0 +1,9 @@
+header:
+ version: 13
+
+env:
+ TESTVAR_DEFAULT_VAL: "BAR"
+ TESTVAR_ONLY_WHITELIST:
+
+repos:
+ this:
--
2.25.1