From 3602956dc06353ba5bf1951fe0244d26323c94d9 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 11 Jul 2024 18:17:06 -0600 Subject: [PATCH] Fix sdk lint --- .../metrics/test_benchmark_metrics_histogram.py | 12 +++++++----- .../benchmarks/trace/test_benchmark_trace.py | 5 ++--- .../exponential_histogram/test_exponent_mapping.py | 1 + .../test_exponential_bucket_histogram_aggregation.py | 7 +++++-- .../exponential_histogram/test_logarithm_mapping.py | 1 + .../test_explicit_bucket_histogram_aggregation.py | 2 ++ .../tests/metrics/test_backward_compat.py | 4 ++-- opentelemetry-sdk/tests/metrics/test_import.py | 2 +- .../tests/metrics/test_in_memory_metric_reader.py | 2 ++ opentelemetry-sdk/tests/metrics/test_instrument.py | 1 - .../tests/metrics/test_measurement_consumer.py | 2 ++ .../tests/metrics/test_metric_reader.py | 3 ++- .../tests/metrics/test_metric_reader_storage.py | 2 ++ opentelemetry-sdk/tests/metrics/test_metrics.py | 7 ++++--- .../metrics/test_periodic_exporting_metric_reader.py | 9 +++++---- opentelemetry-sdk/tests/metrics/test_point.py | 6 ------ .../tests/metrics/test_view_instrument_match.py | 2 +- 17 files changed, 39 insertions(+), 29 deletions(-) diff --git a/opentelemetry-sdk/benchmarks/metrics/test_benchmark_metrics_histogram.py b/opentelemetry-sdk/benchmarks/metrics/test_benchmark_metrics_histogram.py index 2f9c4405418..1c7cdf2cb5a 100644 --- a/opentelemetry-sdk/benchmarks/metrics/test_benchmark_metrics_histogram.py +++ b/opentelemetry-sdk/benchmarks/metrics/test_benchmark_metrics_histogram.py @@ -11,6 +11,8 @@ # 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. + +# pylint: disable=invalid-name import random import pytest @@ -70,7 +72,7 @@ def _generate_bounds(bound_count): def test_histogram_record(benchmark, num_labels): labels = {} for i in range(num_labels): - labels["Key{}".format(i)] = "Value{}".format(i) + labels[f"Key{i}"] = "Value{i}" def benchmark_histogram_record(): hist.record(random.random() * MAX_BOUND_VALUE) @@ -82,7 +84,7 @@ def benchmark_histogram_record(): def test_histogram_record_10(benchmark, num_labels): labels = {} for i in range(num_labels): - labels["Key{}".format(i)] = "Value{}".format(i) + labels[f"Key{i}"] = "Value{i}" def benchmark_histogram_record_10(): hist10.record(random.random() * MAX_BOUND_VALUE) @@ -94,7 +96,7 @@ def benchmark_histogram_record_10(): def test_histogram_record_49(benchmark, num_labels): labels = {} for i in range(num_labels): - labels["Key{}".format(i)] = "Value{}".format(i) + labels[f"Key{i}"] = "Value{i}" def benchmark_histogram_record_49(): hist49.record(random.random() * MAX_BOUND_VALUE) @@ -106,7 +108,7 @@ def benchmark_histogram_record_49(): def test_histogram_record_50(benchmark, num_labels): labels = {} for i in range(num_labels): - labels["Key{}".format(i)] = "Value{}".format(i) + labels[f"Key{i}"] = "Value{i}" def benchmark_histogram_record_50(): hist50.record(random.random() * MAX_BOUND_VALUE) @@ -118,7 +120,7 @@ def benchmark_histogram_record_50(): def test_histogram_record_1000(benchmark, num_labels): labels = {} for i in range(num_labels): - labels["Key{}".format(i)] = "Value{}".format(i) + labels[f"Key{i}"] = "Value{i}" def benchmark_histogram_record_1000(): hist1000.record(random.random() * MAX_BOUND_VALUE) diff --git a/opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py b/opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py index a407a341f45..20a9b909427 100644 --- a/opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py +++ b/opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import opentelemetry.sdk.trace as trace from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.trace import sampling +from opentelemetry.sdk.trace import TracerProvider, sampling -tracer = trace.TracerProvider( +tracer = TracerProvider( sampler=sampling.DEFAULT_ON, resource=Resource( { diff --git a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponent_mapping.py b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponent_mapping.py index 30c178bbcba..cfd33ef4a15 100644 --- a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponent_mapping.py +++ b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponent_mapping.py @@ -173,6 +173,7 @@ def test_exponent_mapping_neg_one(self): self.assertEqual(exponent_mapping.map_to_index(0.06), -3) def test_exponent_mapping_neg_four(self): + # pylint: disable=too-many-statements exponent_mapping = ExponentMapping(-4) self.assertEqual(exponent_mapping.map_to_index(float(0x1)), -1) self.assertEqual(exponent_mapping.map_to_index(float(0x10)), 0) diff --git a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py index 762bd060f58..e243e09643d 100644 --- a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py +++ b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_exponential_bucket_histogram_aggregation.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=protected-access +# pylint: disable=protected-access,too-many-lines,invalid-name +# pylint: disable=consider-using-enumerate,no-self-use,too-many-public-methods import random as insecure_random from itertools import permutations @@ -388,7 +389,7 @@ def mock_increment(self, bucket_index: int) -> None: """ Increments a bucket """ - + # pylint: disable=cell-var-from-loop self._counts[bucket_index] += increment exponential_histogram_aggregation = ( @@ -660,6 +661,7 @@ def test_aggregator_copy_swap(self): exponential_histogram_aggregation_1, ) + # pylint: disable=unnecessary-dunder-call exponential_histogram_aggregation_2._positive.__init__() exponential_histogram_aggregation_2._negative.__init__() exponential_histogram_aggregation_2._sum = 0 @@ -964,6 +966,7 @@ def collect_and_validate() -> None: upper_bound = 2 ** ((index + 1) / (2**scale)) matches = 0 for value in values: + # pylint: disable=chained-comparison if value > lower_bound and value <= upper_bound: matches += 1 assert ( diff --git a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_logarithm_mapping.py b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_logarithm_mapping.py index 075c95b794f..43820d677b0 100644 --- a/opentelemetry-sdk/tests/metrics/exponential_histogram/test_logarithm_mapping.py +++ b/opentelemetry-sdk/tests/metrics/exponential_histogram/test_logarithm_mapping.py @@ -55,6 +55,7 @@ def left_boundary(scale: int, index: int) -> float: class TestLogarithmMapping(TestCase): + # pylint: disable=invalid-name def assertInEpsilon(self, first, second, epsilon): self.assertLessEqual(first, (second * (1 + epsilon))) self.assertGreaterEqual(first, (second * (1 - epsilon))) diff --git a/opentelemetry-sdk/tests/metrics/integration_test/test_explicit_bucket_histogram_aggregation.py b/opentelemetry-sdk/tests/metrics/integration_test/test_explicit_bucket_histogram_aggregation.py index b705be33569..fee13525a32 100644 --- a/opentelemetry-sdk/tests/metrics/integration_test/test_explicit_bucket_histogram_aggregation.py +++ b/opentelemetry-sdk/tests/metrics/integration_test/test_explicit_bucket_histogram_aggregation.py @@ -104,6 +104,7 @@ def test_synchronous_delta_temporality(self): previous_time_unix_nano = metric_data.time_unix_nano self.assertEqual( metric_data.bucket_counts, + # pylint: disable=consider-using-generator tuple( [ 1 if internal_index == index + 2 else 0 @@ -224,6 +225,7 @@ def test_synchronous_cumulative_temporality(self): ) self.assertEqual( metric_data.bucket_counts, + # pylint: disable=consider-using-generator tuple( [ ( diff --git a/opentelemetry-sdk/tests/metrics/test_backward_compat.py b/opentelemetry-sdk/tests/metrics/test_backward_compat.py index 46008554fe6..e29ca71469f 100644 --- a/opentelemetry-sdk/tests/metrics/test_backward_compat.py +++ b/opentelemetry-sdk/tests/metrics/test_backward_compat.py @@ -44,7 +44,7 @@ class OrigMetricExporter(MetricExporter): def export( self, - metrics: Sequence[Metric], + metrics_data: Sequence[Metric], timeout_millis: float = 10_000, **kwargs, ) -> MetricExportResult: @@ -60,7 +60,7 @@ def force_flush(self, timeout_millis: float = 10_000) -> bool: class OrigMetricReader(MetricReader): def _receive_metrics( self, - metrics: Iterable[Metric], + metrics_data: Iterable[Metric], timeout_millis: float = 10_000, **kwargs, ) -> None: diff --git a/opentelemetry-sdk/tests/metrics/test_import.py b/opentelemetry-sdk/tests/metrics/test_import.py index b53445f12ae..5d656acce69 100644 --- a/opentelemetry-sdk/tests/metrics/test_import.py +++ b/opentelemetry-sdk/tests/metrics/test_import.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=unused-import,import-outside-top-level,too-many-locals +# pylint: disable=unused-import,import-outside-toplevel,too-many-locals from opentelemetry.test import TestCase diff --git a/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py b/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py index 68c81e8b7ef..40a0f3a3042 100644 --- a/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py +++ b/opentelemetry-sdk/tests/metrics/test_in_memory_metric_reader.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=protected-access + from time import sleep from unittest import TestCase from unittest.mock import Mock diff --git a/opentelemetry-sdk/tests/metrics/test_instrument.py b/opentelemetry-sdk/tests/metrics/test_instrument.py index 6f78b6e6ffa..d4a2ddf5094 100644 --- a/opentelemetry-sdk/tests/metrics/test_instrument.py +++ b/opentelemetry-sdk/tests/metrics/test_instrument.py @@ -200,7 +200,6 @@ def test_generator_callback_0(self): ) def test_generator_multiple_generator_callback(self): - self.maxDiff = None observable_gauge = _ObservableGauge( "name", Mock(), diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index 9d3b9691d61..19c514c13e8 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=invalid-name,no-self-use + from time import sleep from unittest import TestCase from unittest.mock import MagicMock, Mock, patch diff --git a/opentelemetry-sdk/tests/metrics/test_metric_reader.py b/opentelemetry-sdk/tests/metrics/test_metric_reader.py index 4ae51bc09a2..5a09112bd0e 100644 --- a/opentelemetry-sdk/tests/metrics/test_metric_reader.py +++ b/opentelemetry-sdk/tests/metrics/test_metric_reader.py @@ -64,7 +64,7 @@ def __init__( def _receive_metrics( self, - metrics: Iterable[Metric], + metrics_data: Iterable[Metric], timeout_millis: float = 10_000, **kwargs, ) -> None: @@ -148,6 +148,7 @@ def test_configure_aggregation(self): LastValueAggregation, ) + # pylint: disable=no-self-use def test_force_flush(self): with patch.object(DummyMetricReader, "collect") as mock_collect: diff --git a/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py b/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py index 5bcf07f6b68..2aac9874659 100644 --- a/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py +++ b/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=protected-access,invalid-name + from logging import WARNING from unittest.mock import MagicMock, Mock, patch diff --git a/opentelemetry-sdk/tests/metrics/test_metrics.py b/opentelemetry-sdk/tests/metrics/test_metrics.py index fdccbee61af..f899b30808a 100644 --- a/opentelemetry-sdk/tests/metrics/test_metrics.py +++ b/opentelemetry-sdk/tests/metrics/test_metrics.py @@ -54,7 +54,7 @@ def __init__(self): def _receive_metrics( self, - metrics: Iterable[Metric], + metrics_data: Iterable[Metric], timeout_millis: float = 10_000, **kwargs, ) -> None: @@ -358,6 +358,7 @@ def test_register_asynchronous_instrument( meter_provider = MeterProvider() + # pylint: disable=no-member meter_provider._measurement_consumer.register_asynchronous_instrument.assert_called_with( meter_provider.get_meter("name").create_observable_counter( "name0", callbacks=[Mock()] @@ -546,11 +547,11 @@ def __init__(self): def export( self, - metrics: Sequence[Metric], + metrics_data: Sequence[Metric], timeout_millis: float = 10_000, **kwargs, ) -> MetricExportResult: - self.metrics[self._counter] = metrics + self.metrics[self._counter] = metrics_data self._counter += 1 return MetricExportResult.SUCCESS diff --git a/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py b/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py index cadea69650a..962b4fdd643 100644 --- a/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py +++ b/opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# pylint: disable=protected-access +# pylint: disable=protected-access,invalid-name,no-self-use import math from logging import WARNING @@ -55,12 +55,12 @@ def __init__( def export( self, - metrics: Sequence[Metric], + metrics_data: Sequence[Metric], timeout_millis: float = 10_000, **kwargs, ) -> MetricExportResult: sleep(self.wait) - self.metrics.extend(metrics) + self.metrics.extend(metrics_data) return True def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: @@ -85,6 +85,7 @@ def __init__( ) self._collect_exception = exception + # pylint: disable=overridden-final-method def collect(self, timeout_millis: float = 10_000) -> None: raise self._collect_exception @@ -216,7 +217,7 @@ def test_shutdown_multiple_times(self): pmr = self._create_periodic_reader([], FakeMetricsExporter()) with self.assertLogs(level="WARNING") as w: self.run_with_many_threads(pmr.shutdown) - self.assertTrue("Can't shutdown multiple times", w.output[0]) + self.assertTrue("Can't shutdown multiple times" in w.output[0]) with self.assertLogs(level="WARNING") as w: pmr.shutdown() diff --git a/opentelemetry-sdk/tests/metrics/test_point.py b/opentelemetry-sdk/tests/metrics/test_point.py index cff07ff6aea..846f2c2fc9f 100644 --- a/opentelemetry-sdk/tests/metrics/test_point.py +++ b/opentelemetry-sdk/tests/metrics/test_point.py @@ -238,8 +238,6 @@ def test_histogram_data_point(self): def test_exp_histogram_data_point(self): - self.maxDiff = None - self.assertEqual( self.exp_histogram_data_point_0.to_json(indent=None), self.exp_histogram_data_point_0_str, @@ -251,8 +249,6 @@ def test_sum(self): def test_gauge(self): - self.maxDiff = None - self.assertEqual(self.gauge_0.to_json(indent=None), self.gauge_0_str) def test_histogram(self): @@ -263,8 +259,6 @@ def test_histogram(self): def test_exp_histogram(self): - self.maxDiff = None - self.assertEqual( self.exp_histogram_0.to_json(indent=None), self.exp_histogram_0_str ) diff --git a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py index c27fdca2f47..f4d2d02351a 100644 --- a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py +++ b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py @@ -38,7 +38,7 @@ ) -class Test_ViewInstrumentMatch(TestCase): +class Test_ViewInstrumentMatch(TestCase): # pylint: disable=invalid-name @classmethod def setUpClass(cls):