# Path: google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py
#     HAS_OPENTELEMETRY_INSTALLED = True
#     HAS_OPENTELEMETRY_INSTALLED = False
# def trace_call(name, extra_attributes=None):
# 
# Path: test/_helpers.py
# class OpenTelemetryBase(fixtures.TestBase):
#     @classmethod
#     def setup_class(cls):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             use_test_ot_exporter()
#             cls.ot_exporter = get_test_ot_exporter()
# 
#     def teardown(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             self.ot_exporter.clear()
# 
#     def assertNoSpans(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             span_list = self.ot_exporter.get_finished_spans()
#             self.assertEqual(len(span_list), 0)
# 
#     def assertSpanAttributes(
#         self, name, status=StatusCode.OK, attributes=None, span=None
#     ):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             if not span:
#                 span_list = self.ot_exporter.get_finished_spans()
#                 self.assertEqual(len(span_list), 1)
#                 span = span_list[0]
# 
#             self.assertEqual(span.name, name)
#             self.assertEqual(span.status.status_code, status)
#             self.assertEqual(dict(span.attributes), attributes)
# 
# HAS_OPENTELEMETRY_INSTALLED = True


import importlib
import mock
import pytest
import sys
    import grpc
    from opentelemetry import trace as trace_api
    from opentelemetry.trace.status import StatusCode
from google.api_core.exceptions import GoogleAPICallError
from google.cloud.spanner_v1 import SpannerClient
from google.cloud.sqlalchemy_spanner import _opentelemetry_tracing
from test._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED
                    from google.api_core.exceptions import InvalidArgument


try:
except ImportError:
    pass



def _make_rpc_error(error_cls, trailing_metadata=None):

    grpc_error = mock.create_autospec(grpc.Call, instance=True)
    grpc_error.trailing_metadata.return_value = trailing_metadata
    return error_cls("error", errors=(grpc_error,))


# Skip all of these tests if we don't have OpenTelemetry
if HAS_OPENTELEMETRY_INSTALLED:

    class TestNoTracing(OpenTelemetryBase):
        def setup(self):
            self._temp_opentelemetry = sys.modules["opentelemetry"]

            sys.modules["opentelemetry"] = None
            importlib.reload(_opentelemetry_tracing)

        def teardown(self):
            sys.modules["opentelemetry"] = self._temp_opentelemetry
            importlib.reload(_opentelemetry_tracing)

        def test_no_trace_call(self):

# Path: google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py
#     HAS_OPENTELEMETRY_INSTALLED = True
#     HAS_OPENTELEMETRY_INSTALLED = False
# def trace_call(name, extra_attributes=None):
# 
# Path: test/_helpers.py
# class OpenTelemetryBase(fixtures.TestBase):
#     @classmethod
#     def setup_class(cls):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             use_test_ot_exporter()
#             cls.ot_exporter = get_test_ot_exporter()
# 
#     def teardown(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             self.ot_exporter.clear()
# 
#     def assertNoSpans(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             span_list = self.ot_exporter.get_finished_spans()
#             self.assertEqual(len(span_list), 0)
# 
#     def assertSpanAttributes(
#         self, name, status=StatusCode.OK, attributes=None, span=None
#     ):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             if not span:
#                 span_list = self.ot_exporter.get_finished_spans()
#                 self.assertEqual(len(span_list), 1)
#                 span = span_list[0]
# 
#             self.assertEqual(span.name, name)
#             self.assertEqual(span.status.status_code, status)
#             self.assertEqual(dict(span.attributes), attributes)
# 
# HAS_OPENTELEMETRY_INSTALLED = True


# Path: test/unit/test_opentelemetry_tracing.py
import importlib
import mock
import pytest
import sys
    import grpc
    from opentelemetry import trace as trace_api
    from opentelemetry.trace.status import StatusCode
from google.api_core.exceptions import GoogleAPICallError
from google.cloud.spanner_v1 import SpannerClient
from google.cloud.sqlalchemy_spanner import _opentelemetry_tracing
from test._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED
                    from google.api_core.exceptions import InvalidArgument



try:
except ImportError:
    pass



def _make_rpc_error(error_cls, trailing_metadata=None):

    grpc_error = mock.create_autospec(grpc.Call, instance=True)
    grpc_error.trailing_metadata.return_value = trailing_metadata
    return error_cls("error", errors=(grpc_error,))


# Skip all of these tests if we don't have OpenTelemetry
if HAS_OPENTELEMETRY_INSTALLED:

    class TestNoTracing(OpenTelemetryBase):
        def setup(self):
            self._temp_opentelemetry = sys.modules["opentelemetry"]

            sys.modules["opentelemetry"] = None
            importlib.reload(_opentelemetry_tracing)

        def teardown(self):
            sys.modules["opentelemetry"] = self._temp_opentelemetry
            importlib.reload(_opentelemetry_tracing)

        def test_no_trace_call(self):

            with _opentelemetry_tracing.trace_call("Test") as no_span: