shymega-ct commented on code in PR #2035:
URL: https://github.com/apache/buildstream/pull/2035#discussion_r2193348529
##########
src/buildstream/types.py:
##########
@@ -389,6 +389,40 @@ def new_from_node(cls, node: MappingNode) ->
"_SourceMirror":
return cls(name, aliases)
+# Used to indicate the state of a given element
+class _ElementState(FastEnum):
Review Comment:
I'm not sure about introducing another Enum just for this new functionality.
Can we re-use any existing Enum for state of Elements?
##########
tests/frontend/inspect.py:
##########
@@ -0,0 +1,61 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+import json
+
+from buildstream._testing import cli # pylint: disable=unused-import
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+)
+
+def _element_by_name(elements, name):
+ for element in elements:
+ if element["name"] == name:
+ return element
+
+
[email protected](os.path.join(DATA_DIR, "simple"))
+def test_inspect_basic(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect"])
+ result.assert_success()
+ output = json.loads(result.output)
+ assert(output["project"]["name"] == "test")
+ element = _element_by_name(output["elements"], "import-bin.bst")
+ source = element["sources"][0]
+ assert(source["kind"] == "local")
+ assert(source["url"] == "files/bin-files")
+
+
[email protected](os.path.join(DATA_DIR, "simple"))
+def test_inspect_element_glob(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect", "*.bst"])
+ result.assert_success()
+ json.loads(result.output)
Review Comment:
I would perform an assert between the result, and an 'expected' JSON result
stored in the project directory.
##########
tests/frontend/inspect.py:
##########
@@ -0,0 +1,61 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+import json
+
+from buildstream._testing import cli # pylint: disable=unused-import
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+)
+
+def _element_by_name(elements, name):
+ for element in elements:
+ if element["name"] == name:
+ return element
+
+
[email protected](os.path.join(DATA_DIR, "simple"))
+def test_inspect_basic(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect"])
+ result.assert_success()
+ output = json.loads(result.output)
+ assert(output["project"]["name"] == "test")
+ element = _element_by_name(output["elements"], "import-bin.bst")
+ source = element["sources"][0]
+ assert(source["kind"] == "local")
+ assert(source["url"] == "files/bin-files")
Review Comment:
suggestion: `assert` should report the reason if the assert fails.
##########
tests/frontend/inspect.py:
##########
@@ -0,0 +1,61 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+import json
+
+from buildstream._testing import cli # pylint: disable=unused-import
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+)
+
+def _element_by_name(elements, name):
+ for element in elements:
+ if element["name"] == name:
+ return element
+
+
[email protected](os.path.join(DATA_DIR, "simple"))
+def test_inspect_basic(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect"])
+ result.assert_success()
+ output = json.loads(result.output)
+ assert(output["project"]["name"] == "test")
+ element = _element_by_name(output["elements"], "import-bin.bst")
+ source = element["sources"][0]
+ assert(source["kind"] == "local")
+ assert(source["url"] == "files/bin-files")
+
+
[email protected](os.path.join(DATA_DIR, "simple"))
+def test_inspect_element_glob(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect", "*.bst"])
+ result.assert_success()
+ json.loads(result.output)
+
+
[email protected](os.path.join(DATA_DIR, "source-fetch"))
+def test_inspect_with_state(cli, datafiles):
+ project = str(datafiles)
+ result = cli.run(project=project, silent=True, args=["inspect", "--state",
"--deps", "all"])
+ result.assert_success()
+ json.loads(result.output)
Review Comment:
Same comment as above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]