You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/07/22 05:30:13 UTC

[buildstream] 01/02: tests/format/optionprojectroot.py: Test project root conditional resolution

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/resolve-conditionals-project-root
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 0d4d89b44eda9b79f6e374c41eff71f3ed213524
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Fri Jul 22 14:17:42 2022 +0900

    tests/format/optionprojectroot.py: Test project root conditional resolution
---
 tests/format/option-project-root/element.bst  |  1 +
 tests/format/option-project-root/project.conf | 19 ++++++++++++++++++
 tests/format/optionprojectroot.py             | 28 +++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/tests/format/option-project-root/element.bst b/tests/format/option-project-root/element.bst
new file mode 100644
index 000000000..4d7f70266
--- /dev/null
+++ b/tests/format/option-project-root/element.bst
@@ -0,0 +1 @@
+kind: manual
diff --git a/tests/format/option-project-root/project.conf b/tests/format/option-project-root/project.conf
new file mode 100644
index 000000000..eb254bc2c
--- /dev/null
+++ b/tests/format/option-project-root/project.conf
@@ -0,0 +1,19 @@
+name: test
+min-version: 2.0
+
+options:
+  animal:
+    type: enum
+    description: The kind of animal
+    values:
+    - pony
+    - horsy
+    default: pony
+
+(?):
+- animal == "pony":
+    variables:
+      result: "a pony"
+- animal == "horsy":
+    variables:
+      result: "a horsy"
diff --git a/tests/format/optionprojectroot.py b/tests/format/optionprojectroot.py
new file mode 100644
index 000000000..5ea3508ab
--- /dev/null
+++ b/tests/format/optionprojectroot.py
@@ -0,0 +1,28 @@
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+from buildstream import _yaml
+from buildstream.exceptions import ErrorDomain, LoadErrorReason
+from buildstream._testing.runcli import cli  # pylint: disable=unused-import
+
+# Project directory
+DATA_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+#
+# Test that project option conditionals can be resolved in the project root
+#
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("value,expected", [("pony", "a pony"), ("horsy", "a horsy")], ids=["pony", "horsy"])
+def test_resolve_project_root_conditional(cli, datafiles, value, expected):
+    project = os.path.join(datafiles.dirname, datafiles.basename, "option-project-root")
+    result = cli.run(
+        project=project,
+        silent=True,
+        args=["--option", "animal", value, "show", "--deps", "none", "--format", "%{vars}", "element.bst"],
+    )
+    result.assert_success()
+    loaded = _yaml.load_data(result.output)
+    assert loaded.get_str("result") == expected