fix: refactor some more for tests + pylint
This commit is contained in:
parent
6e2428957b
commit
f747f6bb39
8 changed files with 29 additions and 15 deletions
4
.pylintrc
Normal file
4
.pylintrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
# -*- mode: conf; -*-
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
disable=fixme
|
|
@ -9,6 +9,9 @@ project.
|
|||
|
||||
.. _test coverage: https://buildbot.wuttaproject.org/coverage/wuttatell/
|
||||
|
||||
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
|
||||
:target: https://github.com/pylint-dev/pylint
|
||||
|
||||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
||||
:target: https://github.com/psf/black
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ dependencies = [
|
|||
|
||||
[project.optional-dependencies]
|
||||
docs = ["Sphinx", "furo", "sphinxcontrib-programoutput"]
|
||||
tests = ["pytest-cov", "tox"]
|
||||
tests = ["pylint", "pytest", "pytest-cov", "tox"]
|
||||
|
||||
|
||||
[project.entry-points."wutta.app.providers"]
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""
|
||||
Package Version
|
||||
"""
|
||||
|
||||
from importlib.metadata import version
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ class WuttaTellAppProvider(AppProvider):
|
|||
|
||||
:rtype: :class:`~wuttatell.telemetry.TelemetryHandler`
|
||||
"""
|
||||
if not hasattr(self, "telemetry_handler"):
|
||||
if "telemetry" not in self.app.handlers:
|
||||
spec = self.config.get(
|
||||
f"{self.appname}.telemetry.handler",
|
||||
default="wuttatell.telemetry:TelemetryHandler",
|
||||
)
|
||||
factory = self.app.load_object(spec)
|
||||
self.telemetry_handler = factory(self.config, **kwargs)
|
||||
return self.telemetry_handler
|
||||
self.app.handlers["telemetry"] = factory(self.config, **kwargs)
|
||||
return self.app.handlers["telemetry"]
|
||||
|
|
|
@ -71,7 +71,7 @@ class SimpleAPIClient:
|
|||
API requests.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
|
||||
self, config, base_url=None, token=None, ssl_verify=None, max_retries=None
|
||||
):
|
||||
self.config = config
|
||||
|
|
|
@ -44,7 +44,7 @@ class TelemetryHandler(GenericHandler):
|
|||
* :meth:`submit_all_data()`
|
||||
"""
|
||||
|
||||
def get_profile(self, profile):
|
||||
def get_profile(self, profile): # pylint: disable=empty-docstring
|
||||
""" """
|
||||
if isinstance(profile, TelemetryProfile):
|
||||
return profile
|
||||
|
@ -82,10 +82,10 @@ class TelemetryHandler(GenericHandler):
|
|||
self.normalize_errors(data)
|
||||
return data
|
||||
|
||||
def normalize_errors(self, data):
|
||||
def normalize_errors(self, data): # pylint: disable=empty-docstring
|
||||
""" """
|
||||
all_errors = []
|
||||
for key, value in data.items():
|
||||
for value in data.values():
|
||||
if value:
|
||||
errors = value.pop("errors", None)
|
||||
if errors:
|
||||
|
@ -93,7 +93,7 @@ class TelemetryHandler(GenericHandler):
|
|||
if all_errors:
|
||||
data["errors"] = all_errors
|
||||
|
||||
def collect_data_os(self, profile, **kwargs):
|
||||
def collect_data_os(self, profile, **kwargs): # pylint: disable=unused-argument
|
||||
"""
|
||||
Collect basic data about the operating system.
|
||||
|
||||
|
@ -121,9 +121,9 @@ class TelemetryHandler(GenericHandler):
|
|||
# release
|
||||
release_path = kwargs.get("release_path", "/etc/os-release")
|
||||
try:
|
||||
with open(release_path, "rt") as f:
|
||||
with open(release_path, "rt", encoding="utf_8") as f:
|
||||
output = f.read()
|
||||
except:
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
errors.append(f"Failed to read {release_path}")
|
||||
else:
|
||||
release = {}
|
||||
|
@ -144,9 +144,9 @@ class TelemetryHandler(GenericHandler):
|
|||
# timezone
|
||||
timezone_path = kwargs.get("timezone_path", "/etc/timezone")
|
||||
try:
|
||||
with open(timezone_path, "rt") as f:
|
||||
with open(timezone_path, "rt", encoding="utf_8") as f:
|
||||
output = f.read()
|
||||
except:
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
errors.append(f"Failed to read {timezone_path}")
|
||||
else:
|
||||
data["timezone"] = output.strip()
|
||||
|
@ -264,11 +264,11 @@ class TelemetryProfile(WuttaConfigProfile):
|
|||
"""
|
||||
|
||||
@property
|
||||
def section(self):
|
||||
def section(self): # pylint: disable=empty-docstring
|
||||
""" """
|
||||
return f"{self.config.appname}.telemetry"
|
||||
|
||||
def load(self):
|
||||
def load(self): # pylint: disable=empty-docstring
|
||||
""" """
|
||||
keys = self.get_str("collect.keys", default="os,python")
|
||||
self.collect_keys = self.config.parse_list(keys)
|
||||
|
|
4
tox.ini
4
tox.ini
|
@ -6,6 +6,10 @@ envlist = py38, py39, py310, py311
|
|||
extras = tests
|
||||
commands = pytest {posargs}
|
||||
|
||||
[testenv:pylint]
|
||||
basepython = python3.11
|
||||
commands = pylint wuttatell
|
||||
|
||||
[testenv:coverage]
|
||||
basepython = python3.11
|
||||
commands = pytest --cov=wuttatell --cov-report=html --cov-fail-under=100
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue