sadpandajoe commented on code in PR #45393: URL: https://github.com/apache/superset/pull/45393#discussion_r4318083321
########## superset-core/tests/semantic_layers/test_registration.py: ########## @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +from typing import get_type_hints + +import pyarrow as pa +import pytest +from superset_core.semantic_layers import decorators +from superset_core.semantic_layers.errors import ( + SemanticQueryErrorCode, + SemanticQueryRejectedError, +) +from superset_core.semantic_layers.layer import ConfigT, SemanticLayer +from superset_core.semantic_layers.types import Dimension + +pytest_plugins: list[str] = ["superset_core.semantic_layers.testing"] + + +def test_configuration_is_part_of_the_typed_contract() -> None: + """Providers expose their parsed settings under the host's public accessor.""" + assert get_type_hints(SemanticLayer)["configuration"] is ConfigT + + +def test_sdk_only_provider(semantic_layer_registration: None) -> None: + """Import the decorated provider only after the registration fixture starts.""" + from example_provider import ExampleLayer, ExampleView + + layer: ExampleLayer = ExampleLayer.from_configuration({"label": "Example"}) + assert layer.configuration.label == "Example" + assert layer.get_configuration_schema()["properties"]["label"]["type"] == "string" + assert layer.get_runtime_schema(layer.configuration) == { + "type": "object", + "properties": {}, + } + view: ExampleView = layer.get_semantic_view("example", {}) + assert view.uid() == "example" + assert view.get_values(next(iter(view.get_dimensions()))).results.to_pydict() == { + "category": ["A", "B"] + } + assert view.metadata_cache_token is None + + +def test_registration_remains_host_owned() -> None: Review Comment: This test never activates the fixture itself, so it only proves the SDK stub raises `NotImplementedError` — it passes identically if the fixture failed to restore the decorator, whenever it is run alone, first, or on a different xdist worker than the fixture users. Could the activation and the post-teardown check live in one controlled lifecycle (e.g. a `pytester` run, or capturing `decorators.semantic_layer` before and asserting identity after)? ########## superset-core/tests/semantic_layers/test_registration.py: ########## @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +from typing import get_type_hints + +import pyarrow as pa +import pytest +from superset_core.semantic_layers import decorators +from superset_core.semantic_layers.errors import ( + SemanticQueryErrorCode, + SemanticQueryRejectedError, +) +from superset_core.semantic_layers.layer import ConfigT, SemanticLayer +from superset_core.semantic_layers.types import Dimension + +pytest_plugins: list[str] = ["superset_core.semantic_layers.testing"] + + +def test_configuration_is_part_of_the_typed_contract() -> None: Review Comment: These tests never run in CI: the root `pytest.ini` only collects `tests`, and the Python unit workflow runs `./tests/common` and `./tests/unit_tests` only. So dropping the `configuration: ConfigT` declaration (or breaking the fixture) would leave every check green. Is there a plan to add an SDK-only pytest invocation for `superset-core/tests`, or is the manual command in the PR description the intended gate? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
