diff --git a/src/python/grpcio_tests/tests/observability/BUILD.bazel b/src/python/grpcio_tests/tests/observability/BUILD.bazel index 29bd6a90e6090..465fb7c2b8dc9 100644 --- a/src/python/grpcio_tests/tests/observability/BUILD.bazel +++ b/src/python/grpcio_tests/tests/observability/BUILD.bazel @@ -18,6 +18,11 @@ py_library( srcs = ["_test_server.py"], ) +py_library( + name = "_from_observability_import_star", + srcs = ["_from_observability_import_star.py"], +) + py_test( name = "_observability_test", size = "small", @@ -45,3 +50,16 @@ py_test( "//src/python/grpcio_tests/tests/testing", ], ) + +py_test( + name = "_observability_api_test", + size = "small", + srcs = ["_observability_api_test.py"], + imports = ["../../"], + main = "_observability_api_test.py", + deps = [ + ":_from_observability_import_star", + "//src/python/grpcio_observability/grpc_observability:pyobservability", + "//src/python/grpcio_tests/tests/testing", + ], +) diff --git a/src/python/grpcio_tests/tests/observability/_from_observability_import_star.py b/src/python/grpcio_tests/tests/observability/_from_observability_import_star.py new file mode 100644 index 0000000000000..e218c49cdb231 --- /dev/null +++ b/src/python/grpcio_tests/tests/observability/_from_observability_import_star.py @@ -0,0 +1,25 @@ +# Copyright 2024 gRPC authors. +# +# 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. + +_BEFORE_IMPORT = tuple(globals()) + +from grpc_observability import * # pylint: disable=wildcard-import,unused-wildcard-import + +_AFTER_IMPORT = tuple(globals()) + +GRPC_OBSERVABILITY_ELEMENTS = tuple( + element + for element in _AFTER_IMPORT + if element not in _BEFORE_IMPORT and element != "_BEFORE_IMPORT" +) diff --git a/src/python/grpcio_tests/tests/observability/_observability_api_test.py b/src/python/grpcio_tests/tests/observability/_observability_api_test.py new file mode 100644 index 0000000000000..3d5fb093d6b4e --- /dev/null +++ b/src/python/grpcio_tests/tests/observability/_observability_api_test.py @@ -0,0 +1,39 @@ +# Copyright 2024 gRPC authors. +# +# 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. +"""Test of gRPC Python Observability's application-layer API.""" + +import logging +import unittest + +import grpc_observability + +from tests.observability import _from_observability_import_star + + +class AllTest(unittest.TestCase): + def testAll(self): + expected_observability_code_elements = ( + "OpenTelemetryObservability", + "OpenTelemetryPlugin", + ) + + self.assertCountEqual( + expected_observability_code_elements, + _from_observability_import_star.GRPC_OBSERVABILITY_ELEMENTS, + ) + + +if __name__ == "__main__": + logging.basicConfig() + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/tests.json b/src/python/grpcio_tests/tests/tests.json index 7ba494ac5b611..f0974c125db73 100644 --- a/src/python/grpcio_tests/tests/tests.json +++ b/src/python/grpcio_tests/tests/tests.json @@ -10,6 +10,7 @@ "tests.interop._insecure_intraop_test.InsecureIntraopTest", "tests.interop._secure_intraop_test.SecureIntraopTest", "tests.observability._observability_test.ObservabilityTest", + "tests.observability._observability_api_test.AllTest", "tests.observability._open_telemetry_observability_test.OpenTelemetryObservabilityTest", "tests.protoc_plugin._python_plugin_test.ModuleMainTest", "tests.protoc_plugin._python_plugin_test.PythonPluginTest",