Skip to content

Commit

Permalink
Fix sdk lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 12, 2024
1 parent 636a363 commit 3602956
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,6 +225,7 @@ def test_synchronous_cumulative_temporality(self):
)
self.assertEqual(
metric_data.bucket_counts,
# pylint: disable=consider-using-generator
tuple(
[
(
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/metrics/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class OrigMetricExporter(MetricExporter):
def export(
self,
metrics: Sequence[Metric],
metrics_data: Sequence[Metric],
timeout_millis: float = 10_000,
**kwargs,
) -> MetricExportResult:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion opentelemetry-sdk/tests/metrics/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_measurement_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-sdk/tests/metrics/test_metric_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(

def _receive_metrics(
self,
metrics: Iterable[Metric],
metrics_data: Iterable[Metric],
timeout_millis: float = 10_000,
**kwargs,
) -> None:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()]
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-sdk/tests/metrics/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)


class Test_ViewInstrumentMatch(TestCase):
class Test_ViewInstrumentMatch(TestCase): # pylint: disable=invalid-name
@classmethod
def setUpClass(cls):

Expand Down

0 comments on commit 3602956

Please sign in to comment.