kevinschoon commented on code in PR #2035: URL: https://github.com/apache/buildstream/pull/2035#discussion_r2204716331
########## tests/frontend/inspect.py: ########## @@ -0,0 +1,96 @@ +# +# 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 dataclasses import dataclass + +from buildstream._testing import cli # pylint: disable=unused-import + + +DATA_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), +) + +# check to see if a source exists in an element +@dataclass +class _Source: + name: str # element name + kind: str + version: str + +def _element_by_name(elements, name): + for element in elements: + if element["name"] == name: + return element + +def _assert_has_elements(elements, expected): + n_elements = len(elements) + n_expected = len(expected) + if len(elements) != len(expected): + raise Exception(f"Expected {n_expected} elements, got {n_elements}") + for expected_name in expected: + if _element_by_name(elements, expected_name) is None: + raise Exception(f"Element {expected_name} is missing") + +def _assert_has_source(elements, expected: _Source): + element = _element_by_name(elements, expected.name) + if element is None: + raise Exception(f"Cannot find element {expected.name}") + if "sources" in element: + for source in element["sources"]: + kind = source["kind"] + version = source["version"] + if kind == expected.kind and version == expected.version: + return + raise Exception(f"Element {expected.name} does not contain the expected source") + + +@pytest.mark.parametrize( + "flags,elements", + [ + ([], ["import-dev.bst", "import-bin.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]), + (["*.bst", "**/*.bst"], ["import-dev.bst", "import-bin.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]), + (["--state"], ["import-dev.bst", "import-bin.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]), + (["--state", "--deps", "all"], ["import-dev.bst", "import-bin.bst", "compose-all.bst", "target.bst", "subdir/target.bst"]), + (["subdir/*.bst"], ["import-dev.bst", "subdir/target.bst"]) + ], +) +@pytest.mark.datafiles(os.path.join(DATA_DIR, "simple")) Review Comment: I've included a new sub-directory with some basic test data. -- 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: commits-unsubscr...@buildstream.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org