Skip to content

Commit 2d975fe

Browse files
committed
fix patches/mocks in test code
1 parent 13cf3de commit 2d975fe

File tree

10 files changed

+182
-64
lines changed

10 files changed

+182
-64
lines changed

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/logs/test_otlp_logs_exporter.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def test_otlp_headers_from_env(self):
292292
(("user-agent", "OTel-OTLP-Exporter-Python/" + __version__),),
293293
)
294294

295-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
295+
@patch(
296+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
297+
)
296298
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
297299
def test_unavailable(self, mock_sleep, mock_expo):
298300

@@ -306,7 +308,9 @@ def test_unavailable(self, mock_sleep, mock_expo):
306308
)
307309
mock_sleep.assert_called_with(1)
308310

309-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
311+
@patch(
312+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
313+
)
310314
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
311315
def test_unavailable_delay(self, mock_sleep, mock_expo):
312316

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def test_environ_to_compression(self):
6060
with self.assertRaises(InvalidCompressionValueException):
6161
environ_to_compression("test_invalid")
6262

63-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
63+
@patch(
64+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
65+
)
6466
def test_export_warning(self, mock_expo):
6567
mock_expo.configure_mock(**{"return_value": [0]})
6668

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure):
369369
mock_method.reset_mock()
370370

371371
# pylint: disable=no-self-use
372-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
372+
@patch(
373+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
374+
)
373375
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
374376
@patch.dict("os.environ", {OTEL_EXPORTER_OTLP_COMPRESSION: "gzip"})
375377
def test_otlp_exporter_otlp_compression_envvar(
@@ -405,7 +407,9 @@ def test_otlp_exporter_otlp_compression_unspecified(
405407
"localhost:4317", compression=Compression.NoCompression
406408
)
407409

408-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
410+
@patch(
411+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
412+
)
409413
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
410414
def test_unavailable(self, mock_sleep, mock_expo):
411415

@@ -420,7 +424,9 @@ def test_unavailable(self, mock_sleep, mock_expo):
420424
)
421425
mock_sleep.assert_called_with(1)
422426

423-
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator")
427+
@patch(
428+
"opentelemetry.exporter.otlp.proto.grpc.exporter._create_exp_backoff_generator"
429+
)
424430
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.sleep")
425431
def test_unavailable_delay(self, mock_sleep, mock_expo):
426432

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py

+139-47
Large diffs are not rendered by default.

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import requests
2424

25-
from opentelemetry.exporter.otlp.proto.common._internal import _create_exp_backoff_generator
25+
from opentelemetry.exporter.otlp.proto.common._internal import (
26+
_create_exp_backoff_generator,
27+
)
2628
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs
2729
from opentelemetry.sdk.environment_variables import (
2830
OTEL_EXPORTER_OTLP_CERTIFICATE,
@@ -56,6 +58,7 @@
5658
DEFAULT_LOGS_EXPORT_PATH = "v1/logs"
5759
DEFAULT_TIMEOUT = 10 # in seconds
5860

61+
5962
class OTLPLogExporter(LogExporter):
6063

6164
_MAX_RETRY_TIMEOUT = 64
@@ -134,7 +137,9 @@ def export(self, batch: Sequence[LogData]) -> LogExportResult:
134137

135138
serialized_data = encode_logs(batch).SerializeToString()
136139

137-
for delay in _create_exp_backoff_generator(max_value=self._MAX_RETRY_TIMEOUT):
140+
for delay in _create_exp_backoff_generator(
141+
max_value=self._MAX_RETRY_TIMEOUT
142+
):
138143

139144
if delay == self._MAX_RETRY_TIMEOUT:
140145
return LogExportResult.FAILURE

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
DEFAULT_METRICS_EXPORT_PATH = "v1/metrics"
8888
DEFAULT_TIMEOUT = 10 # in seconds
8989

90+
9091
class OTLPMetricExporter(MetricExporter, OTLPMetricExporterMixin):
9192

9293
_MAX_RETRY_TIMEOUT = 64
@@ -168,7 +169,9 @@ def export(
168169
**kwargs,
169170
) -> MetricExportResult:
170171
serialized_data = encode_metrics(metrics_data)
171-
for delay in _create_exp_backoff_generator(max_value=self._MAX_RETRY_TIMEOUT):
172+
for delay in _create_exp_backoff_generator(
173+
max_value=self._MAX_RETRY_TIMEOUT
174+
):
172175

173176
if delay == self._MAX_RETRY_TIMEOUT:
174177
return MetricExportResult.FAILURE

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import requests
2424

25-
from opentelemetry.exporter.otlp.proto.common._internal import _create_exp_backoff_generator
25+
from opentelemetry.exporter.otlp.proto.common._internal import (
26+
_create_exp_backoff_generator,
27+
)
2628
from opentelemetry.exporter.otlp.proto.common.trace_encoder import (
2729
encode_spans,
2830
)
@@ -54,6 +56,7 @@
5456
DEFAULT_TRACES_EXPORT_PATH = "v1/traces"
5557
DEFAULT_TIMEOUT = 10 # in seconds
5658

59+
5760
class OTLPSpanExporter(SpanExporter):
5861

5962
_MAX_RETRY_TIMEOUT = 64
@@ -132,7 +135,9 @@ def export(self, spans) -> SpanExportResult:
132135

133136
serialized_data = encode_spans(spans).SerializeToString()
134137

135-
for delay in _create_exp_backoff_generator(max_value=self._MAX_RETRY_TIMEOUT):
138+
for delay in _create_exp_backoff_generator(
139+
max_value=self._MAX_RETRY_TIMEOUT
140+
):
136141

137142
if delay == self._MAX_RETRY_TIMEOUT:
138143
return SpanExportResult.FAILURE

exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
DEFAULT_METRICS_EXPORT_PATH,
3232
DEFAULT_TIMEOUT,
3333
OTLPMetricExporter,
34-
_is_backoff_v2,
3534
)
3635
from opentelemetry.sdk.environment_variables import (
3736
OTEL_EXPORTER_OTLP_CERTIFICATE,
@@ -71,6 +70,7 @@
7170
InstrumentationScope as SDKInstrumentationScope,
7271
)
7372
from opentelemetry.test.metrictestutil import _generate_sum
73+
from opentelemetry.exporter.otlp.proto.common._internal import _is_backoff_v2
7474

7575
OS_ENV_ENDPOINT = "os.env.base"
7676
OS_ENV_CERTIFICATE = "os/env/base.crt"
@@ -298,7 +298,7 @@ def test_serialization(self, mock_post):
298298
)
299299

300300
@activate
301-
@patch("opentelemetry.exporter.otlp.proto.http.metric_exporter.backoff")
301+
@patch("opentelemetry.exporter.otlp.proto.common._internal.backoff")
302302
@patch("opentelemetry.exporter.otlp.proto.http.metric_exporter.sleep")
303303
def test_handles_backoff_v2_api(self, mock_sleep, mock_backoff):
304304
# In backoff ~= 2.0.0 the first value yielded from expo is None.

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
DEFAULT_LOGS_EXPORT_PATH,
3030
DEFAULT_TIMEOUT,
3131
OTLPLogExporter,
32-
_is_backoff_v2,
3332
)
3433
from opentelemetry.exporter.otlp.proto.http.version import __version__
3534
from opentelemetry.sdk._logs import LogData
@@ -50,6 +49,8 @@
5049
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
5150
from opentelemetry.trace import TraceFlags
5251

52+
from opentelemetry.exporter.otlp.proto.common._internal import _is_backoff_v2
53+
5354
ENV_ENDPOINT = "http://localhost.env:8080/"
5455
ENV_CERTIFICATE = "/etc/base.crt"
5556
ENV_HEADERS = "envHeader1=val1,envHeader2=val2"
@@ -168,7 +169,7 @@ def test_exporter_env(self):
168169
self.assertIsInstance(exporter._session, requests.Session)
169170

170171
@responses.activate
171-
@patch("opentelemetry.exporter.otlp.proto.http._log_exporter.backoff")
172+
@patch("opentelemetry.exporter.otlp.proto.common._internal.backoff")
172173
@patch("opentelemetry.exporter.otlp.proto.http._log_exporter.sleep")
173174
def test_handles_backoff_v2_api(self, mock_sleep, mock_backoff):
174175
# In backoff ~= 2.0.0 the first value yielded from expo is None.

exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
DEFAULT_TIMEOUT,
2727
DEFAULT_TRACES_EXPORT_PATH,
2828
OTLPSpanExporter,
29-
_is_backoff_v2,
3029
)
3130
from opentelemetry.exporter.otlp.proto.http.version import __version__
3231
from opentelemetry.sdk.environment_variables import (
@@ -48,6 +47,7 @@
4847
OS_ENV_HEADERS = "envHeader1=val1,envHeader2=val2"
4948
OS_ENV_TIMEOUT = "30"
5049

50+
from opentelemetry.exporter.otlp.proto.common._internal import _is_backoff_v2
5151

5252
# pylint: disable=protected-access
5353
class TestOTLPSpanExporter(unittest.TestCase):
@@ -204,7 +204,7 @@ def test_headers_parse_from_env(self):
204204

205205
# pylint: disable=no-self-use
206206
@responses.activate
207-
@patch("opentelemetry.exporter.otlp.proto.http.trace_exporter.backoff")
207+
@patch("opentelemetry.exporter.otlp.proto.common._internal.backoff")
208208
@patch("opentelemetry.exporter.otlp.proto.http.trace_exporter.sleep")
209209
def test_handles_backoff_v2_api(self, mock_sleep, mock_backoff):
210210
# In backoff ~= 2.0.0 the first value yielded from expo is None.

0 commit comments

Comments
 (0)