summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2020-05-13 14:22:01 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2020-05-13 14:22:01 +0000
commit0769103ca25f113ab8e64bafb264781199a4dcac (patch)
tree6e81c0cdeec60e67a6e11542ba729a1d8268e1cc
parentbe45827bd4521eba286c8f8c5786c1d9a4ff83b4 (diff)
parent39cf9be3b7e6905e293fe24192f539744a6da27a (diff)
downloadbuildstream-0769103ca25f113ab8e64bafb264781199a4dcac.tar.gz
Merge branch 'tristan/plugin-min-version-fault-tolerance' into 'master'
Improve fault tolerance for plugin defined BST_MIN_VERSION See merge request BuildStream/buildstream!1928
-rw-r--r--src/buildstream/utils.py8
-rw-r--r--tests/plugins/loading.py7
-rw-r--r--tests/plugins/loading/plugins/elements/malformedminversion/badstring.py (renamed from tests/plugins/loading/plugins/elements/malformedminversion/malformedminversion.py)0
-rw-r--r--tests/plugins/loading/plugins/elements/malformedminversion/dict.py11
-rw-r--r--tests/plugins/loading/plugins/elements/malformedminversion/list.py11
-rw-r--r--tests/plugins/loading/plugins/elements/malformedminversion/number.py11
-rw-r--r--tests/plugins/loading/plugins/sources/malformedminversion/badstring.py (renamed from tests/plugins/loading/plugins/sources/malformedminversion/malformedminversion.py)0
-rw-r--r--tests/plugins/loading/plugins/sources/malformedminversion/dict.py11
-rw-r--r--tests/plugins/loading/plugins/sources/malformedminversion/list.py11
-rw-r--r--tests/plugins/loading/plugins/sources/malformedminversion/number.py11
10 files changed, 74 insertions, 7 deletions
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 9f7690f7f..29b3bf484 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -1598,14 +1598,14 @@ def _is_single_threaded():
#
def _parse_version(version: str) -> Tuple[int, int]:
- versions = version.split(".")
try:
+ versions = version.split(".")
major = int(versions[0])
minor = int(versions[1])
- except (IndexError, ValueError):
- raise UtilError("Malformed version string: {}".format(version),)
+ except (IndexError, ValueError, AttributeError) as e:
+ raise UtilError("Malformed version string: {}".format(version),) from e
- return (major, minor)
+ return major, minor
# _get_bst_api_version():
diff --git a/tests/plugins/loading.py b/tests/plugins/loading.py
index 13d787b0e..bbb6c7e4d 100644
--- a/tests/plugins/loading.py
+++ b/tests/plugins/loading.py
@@ -166,7 +166,8 @@ def test_missing_min_version(cli, datafiles, plugin_type):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("plugin_type", [("elements"), ("sources")])
-def test_malformed_min_version(cli, datafiles, plugin_type):
+@pytest.mark.parametrize("plugin", [("badstring"), ("number"), ("dict"), ("list")])
+def test_malformed_min_version(cli, datafiles, plugin_type, plugin):
project = str(datafiles)
update_project(
@@ -176,12 +177,12 @@ def test_malformed_min_version(cli, datafiles, plugin_type):
{
"origin": "local",
"path": os.path.join("plugins", plugin_type, "malformedminversion"),
- plugin_type: ["malformedminversion"],
+ plugin_type: [plugin],
}
]
},
)
- setup_element(project, plugin_type, "malformedminversion")
+ setup_element(project, plugin_type, plugin)
result = cli.run(project=project, args=["show", "element.bst"])
result.assert_main_error(ErrorDomain.PLUGIN, "malformed-min-version")
diff --git a/tests/plugins/loading/plugins/elements/malformedminversion/malformedminversion.py b/tests/plugins/loading/plugins/elements/malformedminversion/badstring.py
index 5f96c1897..5f96c1897 100644
--- a/tests/plugins/loading/plugins/elements/malformedminversion/malformedminversion.py
+++ b/tests/plugins/loading/plugins/elements/malformedminversion/badstring.py
diff --git a/tests/plugins/loading/plugins/elements/malformedminversion/dict.py b/tests/plugins/loading/plugins/elements/malformedminversion/dict.py
new file mode 100644
index 000000000..1ee2e52f4
--- /dev/null
+++ b/tests/plugins/loading/plugins/elements/malformedminversion/dict.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Element
+
+
+class MalformedMinVersion(Element):
+
+ BST_MIN_VERSION = {"major": 2, "minor": 0}
+
+
+def setup():
+ return MalformedMinVersion
diff --git a/tests/plugins/loading/plugins/elements/malformedminversion/list.py b/tests/plugins/loading/plugins/elements/malformedminversion/list.py
new file mode 100644
index 000000000..c92224969
--- /dev/null
+++ b/tests/plugins/loading/plugins/elements/malformedminversion/list.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Element
+
+
+class MalformedMinVersion(Element):
+
+ BST_MIN_VERSION = [2, 0]
+
+
+def setup():
+ return MalformedMinVersion
diff --git a/tests/plugins/loading/plugins/elements/malformedminversion/number.py b/tests/plugins/loading/plugins/elements/malformedminversion/number.py
new file mode 100644
index 000000000..154f16d33
--- /dev/null
+++ b/tests/plugins/loading/plugins/elements/malformedminversion/number.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Element
+
+
+class MalformedMinVersion(Element):
+
+ BST_MIN_VERSION = 2.0
+
+
+def setup():
+ return MalformedMinVersion
diff --git a/tests/plugins/loading/plugins/sources/malformedminversion/malformedminversion.py b/tests/plugins/loading/plugins/sources/malformedminversion/badstring.py
index 90474597c..90474597c 100644
--- a/tests/plugins/loading/plugins/sources/malformedminversion/malformedminversion.py
+++ b/tests/plugins/loading/plugins/sources/malformedminversion/badstring.py
diff --git a/tests/plugins/loading/plugins/sources/malformedminversion/dict.py b/tests/plugins/loading/plugins/sources/malformedminversion/dict.py
new file mode 100644
index 000000000..4df4d5297
--- /dev/null
+++ b/tests/plugins/loading/plugins/sources/malformedminversion/dict.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Source
+
+
+class MalformedMinVersion(Source):
+
+ BST_MIN_VERSION = {"major": 2, "minor": 0}
+
+
+def setup():
+ return MalformedMinVersion
diff --git a/tests/plugins/loading/plugins/sources/malformedminversion/list.py b/tests/plugins/loading/plugins/sources/malformedminversion/list.py
new file mode 100644
index 000000000..a3bcf1928
--- /dev/null
+++ b/tests/plugins/loading/plugins/sources/malformedminversion/list.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Source
+
+
+class MalformedMinVersion(Source):
+
+ BST_MIN_VERSION = [2, 0]
+
+
+def setup():
+ return MalformedMinVersion
diff --git a/tests/plugins/loading/plugins/sources/malformedminversion/number.py b/tests/plugins/loading/plugins/sources/malformedminversion/number.py
new file mode 100644
index 000000000..1d1517945
--- /dev/null
+++ b/tests/plugins/loading/plugins/sources/malformedminversion/number.py
@@ -0,0 +1,11 @@
+# Plugins are required to specify the BST_MIN_VERSION
+from buildstream import Source
+
+
+class MalformedMinVersion(Source):
+
+ BST_MIN_VERSION = 2.0
+
+
+def setup():
+ return MalformedMinVersion