Skip to content

Commit c525a42

Browse files
committed
Address pylint findings from CI (pylint 2.9)
Fixes ~30 lint issues surfaced by the CI job that were not caught locally because the dev env runs a newer pylint. All pure lint fixes, no behavior changes. - osbenchmark/metrics.py: - W0108 unnecessary-lambda: use bare OsResultsStore constructor. The default's FileTestRunStore lambda is kept (with pragma) because the class is defined later in the file, so a forward reference would fail at import. - C0415 import-outside-toplevel: pragma on the deferred cloudwatch imports (deferral is intentional — imports at module top trigger a circular between metrics.py and the cloudwatch submodules). - osbenchmark/metrics_stores/cloudwatch/metrics_store.py: - R1711 useless-return at end of to_externalizable. - W1309 pointless f-string in Insights query builder. - osbenchmark/metrics_stores/cloudwatch/client.py: - C0415 pragma on deferred botocore.credentials imports (deferred to keep the assume-role branch cost-free when unused). - tests/metrics_stores/cloudwatch/conftest.py: - E0702 raising-bad-type: bind fail_with to a local so type-narrowing is preserved. - Move botocore.exceptions import to the top of the module. - tests/metrics_stores/cloudwatch/test_read_path.py, tests/metrics_stores/cloudwatch/test_write_path.py: - C0321 multi-statement lines expanded across ~10 sites in fake classes and one-line def bodies. - C0415/C0411 in-function conftest imports moved to module top and consolidated in first-party-then-local order. - W0611 unused imports removed. - test_write_path.py adds a module-level `# pylint: disable=protected- access` because the tests deliberately assert on `_buffered_events` and `_client_factory` to verify internal state (test-only, expected). Signed-off-by: Michael Oviedo <mikeovi@amazon.com>
1 parent d1d1f67 commit c525a42

6 files changed

Lines changed: 44 additions & 26 deletions

File tree

osbenchmark/metrics.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _datastore_factories(cfg):
380380

381381
_DATASTORE_DEFAULT = {
382382
"metrics_store_class": None, # populated below once classes are imported
383-
"test_run_store": lambda cfg: FileTestRunStore(cfg),
383+
"test_run_store": lambda cfg: FileTestRunStore(cfg), # pylint: disable=unnecessary-lambda
384384
"results_store": lambda cfg: NoopResultsStore(),
385385
"test_run_store_log_message": "Creating file test_run store",
386386
"results_store_log_message": "Creating no-op results store",
@@ -1797,7 +1797,7 @@ def store_results(self, test_run):
17971797
datastore_type="opensearch",
17981798
metrics_store_class=OsMetricsStore,
17991799
test_run_store=lambda cfg: CompositeTestRunStore(OsTestRunStore(cfg), FileTestRunStore(cfg)),
1800-
results_store=lambda cfg: OsResultsStore(cfg),
1800+
results_store=OsResultsStore,
18011801
test_run_store_log_message="Creating OS test run store",
18021802
results_store_log_message="Creating OS results store",
18031803
)
@@ -1809,23 +1809,22 @@ def store_results(self, test_run):
18091809
# module top, and they would re-enter this file mid-load if we imported
18101810
# them eagerly here.
18111811
def _cloudwatch_metrics_store_class():
1812+
# pylint: disable=import-outside-toplevel
18121813
from osbenchmark.metrics_stores.cloudwatch.metrics_store import CloudWatchMetricsStore
18131814
return CloudWatchMetricsStore
18141815

18151816

18161817
def _cloudwatch_test_run_store(cfg):
1818+
# pylint: disable=import-outside-toplevel
18171819
from osbenchmark.metrics_stores.cloudwatch.test_run_store import (
18181820
CloudWatchTestRunStore, FileBackedCompositeTestRunStore,
18191821
)
1820-
# Writes fan out to CloudWatch + file; reads come from file until commit
1821-
# #12 wires Logs Insights. The dedicated composite avoids regressing
1822-
# `osbenchmark compare` / `aggregate` / `list test-runs` while the
1823-
# CloudWatch read path is stubbed.
18241822
return FileBackedCompositeTestRunStore(
18251823
CloudWatchTestRunStore(cfg), FileTestRunStore(cfg))
18261824

18271825

18281826
def _cloudwatch_results_store(cfg):
1827+
# pylint: disable=import-outside-toplevel
18291828
from osbenchmark.metrics_stores.cloudwatch.results_store import CloudWatchResultsStore
18301829
return CloudWatchResultsStore(cfg)
18311830

osbenchmark/metrics_stores/cloudwatch/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def _assume_role(self, source_session: boto3.session.Session, role_arn: str) ->
107107
# credential resolver. The `_credentials` attribute is the documented
108108
# private-but-stable extension point — `create_assume_role_refresher`
109109
# itself sets credentials this way internally.
110+
# pylint: disable=import-outside-toplevel
110111
from botocore.credentials import (
111112
DeferredRefreshableCredentials,
112113
create_assume_role_refresher,

osbenchmark/metrics_stores/cloudwatch/metrics_store.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def to_externalizable(self, clear=False):
239239
# for interface parity but has no separate meaning here — flushing
240240
# is the only externalization step.
241241
self.flush(refresh=False)
242-
return None
243242

244243
# `close()` inherited from MetricsStore — its implementation already
245244
# calls self.flush(), clears meta-info, and sets opened=False, which
@@ -477,7 +476,7 @@ def get_percentiles(self, name, task=None, operation_type=None,
477476
else:
478477
stats_parts.append(f"pct(`{safe_name}`, {p}) as `p_{_alias(p)}`")
479478
# count(*) so we can replicate OS's "no hits → None" behavior.
480-
stats_parts.append(f"count(*) as count")
479+
stats_parts.append("count(*) as count")
481480
query = (
482481
f"filter {filter_}\n"
483482
f"| stats " + ", ".join(stats_parts)

tests/metrics_stores/cloudwatch/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
otherwise hit AWS. Each test gets a fresh ``FakeLogsClient`` so state
2929
between tests stays isolated.
3030
"""
31+
import botocore.exceptions
3132
import pytest
3233

3334
import osbenchmark.metrics_stores.cloudwatch.insights as insights_mod
@@ -94,7 +95,8 @@ def put_log_events(self, **kw):
9495
if self.fail_count > 0:
9596
self.fail_count -= 1
9697
if self.fail_with is not None:
97-
raise self.fail_with
98+
exc = self.fail_with
99+
raise exc
98100
self.put_calls.append(kw)
99101

100102
# ----- Logs Insights -----
@@ -161,6 +163,5 @@ def make_insights_rows(rows):
161163

162164

163165
def make_client_error(code, op="PutLogEvents"):
164-
import botocore.exceptions
165166
return botocore.exceptions.ClientError(
166167
{"Error": {"Code": code, "Message": "test"}}, op)

tests/metrics_stores/cloudwatch/test_read_path.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
from osbenchmark import exceptions
3737
from osbenchmark.metrics import SampleType
38-
from osbenchmark.metrics_stores.cloudwatch import insights
3938
from osbenchmark.metrics_stores.cloudwatch.insights import (
4039
InsightsQueryError,
4140
_flatten_rows,
@@ -50,7 +49,7 @@
5049
FileBackedCompositeTestRunStore,
5150
)
5251

53-
from .conftest import make_insights_rows
52+
from .conftest import make_client_error, make_insights_rows
5453

5554

5655
# ----------------------------------------------------------------- Insights helper
@@ -177,8 +176,12 @@ def _make_factory(fake_client):
177176
class _F:
178177
def __init__(self, cw_cfg):
179178
self._client = fake_client
180-
def probe_caller_identity(self): pass
181-
def logs_client(self): return self._client
179+
180+
def probe_caller_identity(self):
181+
pass
182+
183+
def logs_client(self):
184+
return self._client
182185
return _F
183186

184187

@@ -362,7 +365,6 @@ def test_insights_error_degrades_to_empty(self, fake_logs_client, open_store):
362365
# logs:StartQuery. Reads should fail-soft to empty results so
363366
# the result-summary path doesn't crash the run. (Same fail-soft
364367
# contract as FileBackedCompositeTestRunStore.list.)
365-
from .conftest import make_client_error
366368
def boom(**kw):
367369
raise make_client_error("AccessDeniedException", op="StartQuery")
368370
fake_logs_client.start_query = boom
@@ -470,13 +472,20 @@ class _FakeFile:
470472
def __init__(self):
471473
self.runs = {}
472474
self.stored = []
473-
def store_test_run(self, run): self.stored.append(run)
475+
476+
def store_test_run(self, run):
477+
self.stored.append(run)
478+
474479
def find_by_test_run_id(self, tid):
475480
if tid in self.runs:
476481
return self.runs[tid]
477482
raise exceptions.NotFound("not local")
478-
def list(self): return list(self.runs.values())
479-
def store_html_results(self, run): pass
483+
484+
def list(self):
485+
return list(self.runs.values())
486+
487+
def store_html_results(self, run):
488+
pass
480489

481490

482491
class _FakeCW:
@@ -485,10 +494,14 @@ def __init__(self):
485494
self.list_called = False
486495
self.find_result = None
487496
self.find_called = False
488-
def store_test_run(self, run): pass
497+
498+
def store_test_run(self, run):
499+
pass
500+
489501
def list(self):
490502
self.list_called = True
491503
return self.list_result
504+
492505
def find_by_test_run_id(self, tid):
493506
self.find_called = True
494507
if self.find_result is not None:
@@ -497,7 +510,8 @@ def find_by_test_run_id(self, tid):
497510

498511

499512
class _Run:
500-
def __init__(self, test_run_id): self.test_run_id = test_run_id
513+
def __init__(self, test_run_id):
514+
self.test_run_id = test_run_id
501515

502516

503517
class TestFileBackedComposite:
@@ -535,7 +549,8 @@ def test_list_merges_and_dedupes(self):
535549

536550
def test_list_degrades_gracefully_on_cw_error(self):
537551
class _FailingCW:
538-
def list(self): raise RuntimeError("boom (any exception)")
552+
def list(self):
553+
raise RuntimeError("boom (any exception)")
539554
f = _FakeFile()
540555
f.runs["a"] = _Run("a")
541556
c = FileBackedCompositeTestRunStore(_FailingCW(), f)
@@ -548,7 +563,9 @@ def test_write_fans_out(self):
548563
cw.stored = []
549564
# Add `stored` to _FakeCW for the test
550565
cw_stored = []
551-
def store(run): cw_stored.append(run)
566+
567+
def store(run):
568+
cw_stored.append(run)
552569
cw.store_test_run = store
553570
c = FileBackedCompositeTestRunStore(cw, f)
554571
c.store_test_run(_Run("x"))

tests/metrics_stores/cloudwatch/test_write_path.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
EMF document builders, log-stream writer (chunking + retry), and the
2828
three store classes' write flows.
2929
"""
30+
# pylint: disable=protected-access
3031
import datetime
3132
import json
3233

@@ -36,7 +37,6 @@
3637
from osbenchmark import exceptions, metrics
3738
from osbenchmark.metrics_stores.cloudwatch import config as cw_config_mod
3839
from osbenchmark.metrics_stores.cloudwatch import emf
39-
from osbenchmark.metrics_stores.cloudwatch.config import CloudWatchConfig
4040
from osbenchmark.metrics_stores.cloudwatch.log_streams import (
4141
LogStreamWriter,
4242
_MAX_EVENTS_PER_BATCH,
@@ -52,7 +52,7 @@
5252
CloudWatchTestRunStore,
5353
)
5454

55-
from .conftest import make_client_error
55+
from .conftest import _ResourceNotFound, make_client_error
5656

5757

5858
# --------------------------------------------------------------------- config
@@ -412,7 +412,6 @@ def test_auth_error_retried_once_then_bubbles(self, fake_logs_client):
412412
w.write_batch([{"timestamp": 1, "message": "x"}])
413413

414414
def test_stream_recreated_on_resource_not_found(self, fake_logs_client):
415-
from .conftest import _ResourceNotFound
416415
fake_logs_client.fail_with = _ResourceNotFound("stream gone")
417416
fake_logs_client.fail_count = 1
418417
w = LogStreamWriter(fake_logs_client, "g", "s")
@@ -596,7 +595,9 @@ def test_store_results_explodes_into_records(self, fake_logs_client, cw_config):
596595
def test_empty_results_does_not_provision(self, fake_logs_client, cw_config):
597596
class _Empty:
598597
test_run_id = "x"
599-
def to_result_dicts(self): return []
598+
599+
def to_result_dicts(self):
600+
return []
600601
store = CloudWatchResultsStore(
601602
cfg=_StoreCfg(),
602603
client_factory_class=_make_fake_factory(fake_logs_client),

0 commit comments

Comments
 (0)