diff --git a/src/buildstream/node.pyx b/src/buildstream/node.pyx index 41599b0e8..20fe70c8b 100644 --- a/src/buildstream/node.pyx +++ b/src/buildstream/node.pyx @@ -306,8 +306,8 @@ cdef class ScalarNode(Node): cpdef bint as_bool(self) except *: """Get the value of the node as a boolean. - .. note:: BuildStream treats the values 'True' and 'true' as True, - and the values 'False' and 'false' as False. Any other + .. note:: BuildStream treats the values 'True', 'true' and '1' as True, + and the values 'False', 'false' and '0' as False. Any other string values (such as the valid YAML 'TRUE' or 'FALSE' will be considered as an error) @@ -322,15 +322,15 @@ cdef class ScalarNode(Node): return self.value # Don't coerce strings to booleans, this makes "False" strings evaluate to True - if self.value in ('True', 'true'): + if self.value in ('True', 'true', '1'): return True - elif self.value in ('False', 'false'): + elif self.value in ('False', 'false', '0'): return False else: provenance = self.get_provenance() path = provenance._toplevel._find(self)[-1] - raise LoadError("{}: Value of '{}' is not of the expected type '{}'" - .format(provenance, path, bool.__name__, self.value), + raise LoadError("{}: Value of '{}' is not of the expected type 'boolean'" + .format(provenance, path), LoadErrorReason.INVALID_DATA) cpdef object as_enum(self, object constraint): diff --git a/tests/format/option-exports/element.bst b/tests/format/option-exports/element.bst index 4d7f70266..b7da48061 100644 --- a/tests/format/option-exports/element.bst +++ b/tests/format/option-exports/element.bst @@ -1 +1,5 @@ -kind: manual +kind: config + +config: + animal: "%{exported-enum}" + sleepy: "%{exported-bool}" diff --git a/tests/format/option-exports/plugins/config.py b/tests/format/option-exports/plugins/config.py new file mode 100644 index 000000000..cc1e7baae --- /dev/null +++ b/tests/format/option-exports/plugins/config.py @@ -0,0 +1,26 @@ +from buildstream import Element, FastEnum + + +class AnimalEnum(FastEnum): + PONY = "pony" + HORSY = "horsy" + ZEBRY = "zebry" + + +class Config(Element): + BST_MIN_VERSION = "2.0" + + def configure(self, node): + self.animal = node.get_enum("animal", AnimalEnum) + self.sleepy = node.get_bool("sleepy") + + def preflight(self): + pass + + def get_unique_key(self): + return {} + + +# Plugin entry point +def setup(): + return Config diff --git a/tests/format/option-exports/project.conf b/tests/format/option-exports/project.conf index e208536c7..4b10898ec 100644 --- a/tests/format/option-exports/project.conf +++ b/tests/format/option-exports/project.conf @@ -1,6 +1,12 @@ name: test min-version: 2.0 +plugins: + - origin: local + path: plugins + elements: + - config + options: bool_export: diff --git a/tests/integration/pullbuildtrees.py b/tests/integration/pullbuildtrees.py index 2d7cd91fb..a5fe18c7b 100644 --- a/tests/integration/pullbuildtrees.py +++ b/tests/integration/pullbuildtrees.py @@ -179,7 +179,7 @@ def test_pullbuildtrees(cli2, tmpdir, datafiles): # Ensure that only valid pull-buildtrees boolean options make it through the loading # process. -@pytest.mark.parametrize("value,success", [(True, True), (False, True), ("pony", False), ("1", False)]) +@pytest.mark.parametrize("value,success", [(True, True), (False, True), ("pony", False), ("2", False), ("1", True)]) @pytest.mark.datafiles(DATA_DIR) def test_invalid_cache_pullbuildtrees(cli, datafiles, value, success): project = str(datafiles)