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/
 | 
					.. _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
 | 
					.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
 | 
				
			||||||
   :target: https://github.com/psf/black
 | 
					   :target: https://github.com/psf/black
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,7 @@ dependencies = [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[project.optional-dependencies]
 | 
					[project.optional-dependencies]
 | 
				
			||||||
docs = ["Sphinx", "furo", "sphinxcontrib-programoutput"]
 | 
					docs = ["Sphinx", "furo", "sphinxcontrib-programoutput"]
 | 
				
			||||||
tests = ["pytest-cov", "tox"]
 | 
					tests = ["pylint", "pytest", "pytest-cov", "tox"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[project.entry-points."wutta.app.providers"]
 | 
					[project.entry-points."wutta.app.providers"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,7 @@
 | 
				
			||||||
# -*- coding: utf-8; -*-
 | 
					# -*- coding: utf-8; -*-
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					Package Version
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from importlib.metadata import version
 | 
					from importlib.metadata import version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,11 +41,11 @@ class WuttaTellAppProvider(AppProvider):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        :rtype: :class:`~wuttatell.telemetry.TelemetryHandler`
 | 
					        :rtype: :class:`~wuttatell.telemetry.TelemetryHandler`
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        if not hasattr(self, "telemetry_handler"):
 | 
					        if "telemetry" not in self.app.handlers:
 | 
				
			||||||
            spec = self.config.get(
 | 
					            spec = self.config.get(
 | 
				
			||||||
                f"{self.appname}.telemetry.handler",
 | 
					                f"{self.appname}.telemetry.handler",
 | 
				
			||||||
                default="wuttatell.telemetry:TelemetryHandler",
 | 
					                default="wuttatell.telemetry:TelemetryHandler",
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            factory = self.app.load_object(spec)
 | 
					            factory = self.app.load_object(spec)
 | 
				
			||||||
            self.telemetry_handler = factory(self.config, **kwargs)
 | 
					            self.app.handlers["telemetry"] = factory(self.config, **kwargs)
 | 
				
			||||||
        return self.telemetry_handler
 | 
					        return self.app.handlers["telemetry"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,7 +71,7 @@ class SimpleAPIClient:
 | 
				
			||||||
       API requests.
 | 
					       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, base_url=None, token=None, ssl_verify=None, max_retries=None
 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        self.config = config
 | 
					        self.config = config
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ class TelemetryHandler(GenericHandler):
 | 
				
			||||||
    * :meth:`submit_all_data()`
 | 
					    * :meth:`submit_all_data()`
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_profile(self, profile):
 | 
					    def get_profile(self, profile):  # pylint: disable=empty-docstring
 | 
				
			||||||
        """ """
 | 
					        """ """
 | 
				
			||||||
        if isinstance(profile, TelemetryProfile):
 | 
					        if isinstance(profile, TelemetryProfile):
 | 
				
			||||||
            return profile
 | 
					            return profile
 | 
				
			||||||
| 
						 | 
					@ -82,10 +82,10 @@ class TelemetryHandler(GenericHandler):
 | 
				
			||||||
        self.normalize_errors(data)
 | 
					        self.normalize_errors(data)
 | 
				
			||||||
        return data
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def normalize_errors(self, data):
 | 
					    def normalize_errors(self, data):  # pylint: disable=empty-docstring
 | 
				
			||||||
        """ """
 | 
					        """ """
 | 
				
			||||||
        all_errors = []
 | 
					        all_errors = []
 | 
				
			||||||
        for key, value in data.items():
 | 
					        for value in data.values():
 | 
				
			||||||
            if value:
 | 
					            if value:
 | 
				
			||||||
                errors = value.pop("errors", None)
 | 
					                errors = value.pop("errors", None)
 | 
				
			||||||
                if errors:
 | 
					                if errors:
 | 
				
			||||||
| 
						 | 
					@ -93,7 +93,7 @@ class TelemetryHandler(GenericHandler):
 | 
				
			||||||
        if all_errors:
 | 
					        if all_errors:
 | 
				
			||||||
            data["errors"] = 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.
 | 
					        Collect basic data about the operating system.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,9 +121,9 @@ class TelemetryHandler(GenericHandler):
 | 
				
			||||||
        # release
 | 
					        # release
 | 
				
			||||||
        release_path = kwargs.get("release_path", "/etc/os-release")
 | 
					        release_path = kwargs.get("release_path", "/etc/os-release")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            with open(release_path, "rt") as f:
 | 
					            with open(release_path, "rt", encoding="utf_8") as f:
 | 
				
			||||||
                output = f.read()
 | 
					                output = f.read()
 | 
				
			||||||
        except:
 | 
					        except Exception:  # pylint: disable=broad-exception-caught
 | 
				
			||||||
            errors.append(f"Failed to read {release_path}")
 | 
					            errors.append(f"Failed to read {release_path}")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            release = {}
 | 
					            release = {}
 | 
				
			||||||
| 
						 | 
					@ -144,9 +144,9 @@ class TelemetryHandler(GenericHandler):
 | 
				
			||||||
        # timezone
 | 
					        # timezone
 | 
				
			||||||
        timezone_path = kwargs.get("timezone_path", "/etc/timezone")
 | 
					        timezone_path = kwargs.get("timezone_path", "/etc/timezone")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            with open(timezone_path, "rt") as f:
 | 
					            with open(timezone_path, "rt", encoding="utf_8") as f:
 | 
				
			||||||
                output = f.read()
 | 
					                output = f.read()
 | 
				
			||||||
        except:
 | 
					        except Exception:  # pylint: disable=broad-exception-caught
 | 
				
			||||||
            errors.append(f"Failed to read {timezone_path}")
 | 
					            errors.append(f"Failed to read {timezone_path}")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            data["timezone"] = output.strip()
 | 
					            data["timezone"] = output.strip()
 | 
				
			||||||
| 
						 | 
					@ -264,11 +264,11 @@ class TelemetryProfile(WuttaConfigProfile):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def section(self):
 | 
					    def section(self):  # pylint: disable=empty-docstring
 | 
				
			||||||
        """ """
 | 
					        """ """
 | 
				
			||||||
        return f"{self.config.appname}.telemetry"
 | 
					        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")
 | 
					        keys = self.get_str("collect.keys", default="os,python")
 | 
				
			||||||
        self.collect_keys = self.config.parse_list(keys)
 | 
					        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
 | 
					extras = tests
 | 
				
			||||||
commands = pytest {posargs}
 | 
					commands = pytest {posargs}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[testenv:pylint]
 | 
				
			||||||
 | 
					basepython = python3.11
 | 
				
			||||||
 | 
					commands = pylint wuttatell
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[testenv:coverage]
 | 
					[testenv:coverage]
 | 
				
			||||||
basepython = python3.11
 | 
					basepython = python3.11
 | 
				
			||||||
commands = pytest --cov=wuttatell --cov-report=html --cov-fail-under=100
 | 
					commands = pytest --cov=wuttatell --cov-report=html --cov-fail-under=100
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue