Skip to content

Commit

Permalink
Add API test
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanWang-Amos committed Jan 22, 2024
1 parent 4991dfe commit a5e2485
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/python/grpcio_tests/tests/observability/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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"
)
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions src/python/grpcio_tests/tests/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a5e2485

Please sign in to comment.