Skip to content

Commit

Permalink
Point pylint to the root directory of every package (#4048)
Browse files Browse the repository at this point in the history
* Point pylint to the root directory of every package

Fixes #3814

* Fix lint for api

* Fix sdk lint

* Fix sdk lint

* Fix lint for b3

* Fix tox ini and lint

* Fix zipkin
  • Loading branch information
ocelotl committed Jul 15, 2024
1 parent a67f5f8 commit b79a965
Show file tree
Hide file tree
Showing 33 changed files with 135 additions and 101 deletions.
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

from unittest.mock import patch

from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/tests/attributes/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class TestAttributes(unittest.TestCase):
# pylint: disable=invalid-name
def assertValid(self, value, key="k"):
expected = value
if isinstance(value, MutableSequence):
Expand Down Expand Up @@ -89,6 +90,7 @@ def test_sequence_attr_decode(self):


class TestBoundedAttributes(unittest.TestCase):
# pylint: disable=consider-using-dict-items
base = {
"name": "Firulais",
"age": 7,
Expand Down Expand Up @@ -188,7 +190,7 @@ def test_locking(self):
"""
bdict = BoundedAttributes(immutable=False)

with bdict._lock:
with bdict._lock: # pylint: disable=protected-access
for num in range(100):
bdict[str(num)] = num

Expand Down
14 changes: 8 additions & 6 deletions opentelemetry-api/tests/logs/test_logger_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ def tearDown(self):
def test_set_logger_provider(self):
lp_mock = Mock()
# pylint: disable=protected-access
assert logs_internal._LOGGER_PROVIDER is None
self.assertIsNone(logs_internal._LOGGER_PROVIDER)
set_logger_provider(lp_mock)
assert logs_internal._LOGGER_PROVIDER is lp_mock
assert get_logger_provider() is lp_mock
self.assertIs(logs_internal._LOGGER_PROVIDER, lp_mock)
self.assertIs(get_logger_provider(), lp_mock)

def test_get_logger_provider(self):
# pylint: disable=protected-access
assert logs_internal._LOGGER_PROVIDER is None
self.assertIsNone(logs_internal._LOGGER_PROVIDER)

assert isinstance(
self.assertIsInstance(
get_logger_provider(), logs_internal.ProxyLoggerProvider
)

Expand All @@ -59,4 +59,6 @@ def test_get_logger_provider(self):
"opentelemetry._logs._internal.cast",
Mock(**{"return_value": "test_logger_provider"}),
):
assert get_logger_provider() == "test_logger_provider"
self.assertEqual(
get_logger_provider(), "test_logger_provider"
)
2 changes: 2 additions & 0 deletions opentelemetry-api/tests/metrics/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


class ChildInstrument(Instrument):
# pylint: disable=useless-parent-delegation
def __init__(self, name, *args, unit="", description="", **kwargs):
super().__init__(
name, *args, unit=unit, description=description, **kwargs
Expand Down Expand Up @@ -500,6 +501,7 @@ def test_up_down_counter_add_method(self):


class TestObservableUpDownCounter(TestCase):
# pylint: disable=protected-access
def test_create_observable_up_down_counter(self):
"""
Test that the ObservableUpDownCounter can be created with create_observable_up_down_counter.
Expand Down
18 changes: 11 additions & 7 deletions opentelemetry-api/tests/metrics/test_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


class ChildMeter(Meter):
# pylint: disable=signature-differs
def create_counter(self, name, unit="", description=""):
super().create_counter(name, unit=unit, description=description)

Expand All @@ -32,10 +33,10 @@ def create_up_down_counter(self, name, unit="", description=""):
)

def create_observable_counter(
self, name, callback, unit="", description=""
self, name, callbacks, unit="", description=""
):
super().create_observable_counter(
name, callback, unit=unit, description=description
name, callbacks, unit=unit, description=description
)

def create_histogram(self, name, unit="", description=""):
Expand All @@ -44,20 +45,23 @@ def create_histogram(self, name, unit="", description=""):
def create_gauge(self, name, unit="", description=""):
super().create_gauge(name, unit=unit, description=description)

def create_observable_gauge(self, name, callback, unit="", description=""):
def create_observable_gauge(
self, name, callbacks, unit="", description=""
):
super().create_observable_gauge(
name, callback, unit=unit, description=description
name, callbacks, unit=unit, description=description
)

def create_observable_up_down_counter(
self, name, callback, unit="", description=""
self, name, callbacks, unit="", description=""
):
super().create_observable_up_down_counter(
name, callback, unit=unit, description=description
name, callbacks, unit=unit, description=description
)


class TestMeter(TestCase):
# pylint: disable=no-member
def test_repeated_instrument_names(self):

try:
Expand All @@ -72,7 +76,7 @@ def test_repeated_instrument_names(self):
test_meter.create_observable_up_down_counter(
"observable_up_down_counter", Mock()
)
except Exception as error:
except Exception as error: # pylint: disable=broad-exception-caught
self.fail(f"Unexpected exception raised {error}")

for instrument_name in [
Expand Down
7 changes: 5 additions & 2 deletions opentelemetry-api/tests/metrics/test_meter_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
# type: ignore

# pylint: disable=protected-access

from unittest import TestCase
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -54,6 +56,7 @@ def reset_meter_provider():
reset_metrics_globals()


# pylint: disable=redefined-outer-name
def test_set_meter_provider(reset_meter_provider):
"""
Test that the API provides a way to set a global default MeterProvider
Expand Down Expand Up @@ -113,7 +116,7 @@ def test_get_meter_parameters(self):
NoOpMeterProvider().get_meter(
"name", version="version", schema_url="schema_url"
)
except Exception as error:
except Exception as error: # pylint: disable=broad-exception-caught
self.fail(f"Unexpected exception raised: {error}")

def test_invalid_name(self):
Expand Down Expand Up @@ -176,7 +179,7 @@ def test_proxy_provider(self):
self.assertIsInstance(meter2, Mock)
mock_real_mp.get_meter.assert_called_with(another_name, None, None)

# pylint: disable=too-many-locals
# pylint: disable=too-many-locals,too-many-statements
def test_proxy_meter(self):
meter_name = "foo"
proxy_meter: _ProxyMeter = _ProxyMeterProvider().get_meter(meter_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Any tests that fail here indicate that the public API has changed in a way that is not backwards compatible.
# Either bump the major version of the API, or make the necessary changes to the API to remain semver compatible.

# pylint: disable=useless-parent-delegation,arguments-differ

from typing import Optional

from opentelemetry.metrics import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class TestDefaultGlobalPropagator(unittest.TestCase):
SPAN_ID = int("1234567890123456", 16) # type:int

def test_propagation(self):
traceparent_value = "00-{trace_id}-{span_id}-00".format(
trace_id=format_trace_id(self.TRACE_ID),
span_id=format_span_id(self.SPAN_ID),
traceparent_value = (
f"00-{format_trace_id(self.TRACE_ID)}-"
f"{format_span_id(self.SPAN_ID)}-00"
)
tracestate_value = "foo=1,bar=2,baz=3"
headers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class TestW3CBaggagePropagator(TestCase):
# pylint: disable=protected-access
# pylint: disable=too-many-public-methods
def setUp(self):
self.propagator = W3CBaggagePropagator()

Expand All @@ -38,7 +40,7 @@ def _extract(self, header_value):
def _inject(self, values):
"""Test helper"""
ctx = get_current()
for k, v in values.items():
for k, v in values.items(): # pylint: disable=invalid-name
ctx = set_baggage(k, v, context=ctx)
output = {}
self.propagator.inject(output, context=ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def test_headers_with_tracestate(self):
"""When there is a traceparent and tracestate header, data from
both should be added to the SpanContext.
"""
traceparent_value = "00-{trace_id}-{span_id}-00".format(
trace_id=format(self.TRACE_ID, "032x"),
span_id=format(self.SPAN_ID, "016x"),
traceparent_value = (
f"00-{format(self.TRACE_ID, '032x')}-"
f"{format(self.SPAN_ID, '016x')}-00"
)
tracestate_value = "foo=1,bar=2,baz=3"
span_context = trace.get_current_span(
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/util/test__providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from opentelemetry.util import _providers


class Test_Providers(TestCase):
class Test_Providers(TestCase): # pylint: disable=invalid-name
@patch.dict(
environ,
{ # type: ignore
Expand Down Expand Up @@ -49,7 +49,7 @@ def test__providers(self, mock_entry_points):
)

self.assertEqual(
_providers._load_provider(
_providers._load_provider( # pylint: disable=protected-access
"provider_environment_variable", "provider"
),
"a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
)
def test_counter_add(benchmark, num_labels, temporality):
labels = {}
# pylint: disable=invalid-name
for i in range(num_labels):
labels = {f"Key{i}": f"Value{i}" for i in range(num_labels)}

Expand All @@ -68,6 +69,7 @@ def benchmark_counter_add():
@pytest.mark.parametrize("num_labels", [0, 1, 3, 5, 10])
def test_up_down_counter_add(benchmark, num_labels):
labels = {}
# pylint: disable=invalid-name
for i in range(num_labels):
labels = {f"Key{i}": f"Value{i}" for i in range(num_labels)}

Expand Down
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 @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=protected-access

from math import inf
from sys import float_info, version_info
from unittest.mock import patch
Expand Down Expand Up @@ -60,7 +62,7 @@ def test_singleton(self):
"opentelemetry.sdk.metrics._internal.exponential_histogram.mapping."
"exponent_mapping.ExponentMapping._init"
)
def test_init_called_once(self, mock_init):
def test_init_called_once(self, mock_init): # pylint: disable=no-self-use

ExponentMapping(-3)
ExponentMapping(-3)
Expand Down Expand Up @@ -171,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,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# 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
from logging import WARNING
Expand Down Expand Up @@ -386,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 @@ -658,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 @@ -962,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
Loading

0 comments on commit b79a965

Please sign in to comment.