kevinschoon commented on code in PR #2035: URL: https://github.com/apache/buildstream/pull/2035#discussion_r2194795610
########## 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 looked into doing this but because the inspect format appears to contain some localized information to the caller, for example: ```json "sources": [ { "kind": "remote", "url": "file:///home/kevin/repos/external/github.com/apache/buildstream/tests/frontend/source-fetch/files/bananas", "medium": "remote-file", "version-type": "sha256", "version": "e49295702f7da8670778e9b95a281b72b41b31cb16afa376034b45f59a18ea3f" } ] ``` It would not be possible to store the entire expected output of the inspect command. Instead of doing that I instead just tested for the existence of a few keys. If you think we should still test more though I'm open to trying a different approach. -- 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]
