fix: refactor some more for tests + pylint
This commit is contained in:
parent
b89684cfc0
commit
0e25cca0ba
6 changed files with 29 additions and 11 deletions
4
.pylintrc
Normal file
4
.pylintrc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# -*- mode: conf; -*-
|
||||||
|
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
disable=fixme
|
|
@ -9,6 +9,9 @@ This package adds data versioning/history for `WuttJamaican`_, using
|
||||||
|
|
||||||
.. _SQLAlchemy-Continuum: https://sqlalchemy-continuum.readthedocs.io/en/latest/
|
.. _SQLAlchemy-Continuum: https://sqlalchemy-continuum.readthedocs.io/en/latest/
|
||||||
|
|
||||||
|
.. 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"]
|
docs = ["Sphinx", "furo"]
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Wutta-Continuum -- SQLAlchemy Versioning for Wutta Framework
|
# Wutta-Continuum -- SQLAlchemy Versioning for Wutta Framework
|
||||||
# Copyright © 2024 Lance Edgar
|
# Copyright © 2024-2025 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Wutta Framework.
|
# This file is part of Wutta Framework.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
App Configuration
|
App Configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from sqlalchemy.orm import configure_mappers
|
from sqlalchemy.orm import configure_mappers
|
||||||
|
@ -45,7 +44,7 @@ class WuttaContinuumConfigExtension(WuttaConfigExtension):
|
||||||
|
|
||||||
key = "wutta_continuum"
|
key = "wutta_continuum"
|
||||||
|
|
||||||
def startup(self, config):
|
def startup(self, config): # pylint: disable=empty-docstring
|
||||||
""" """
|
""" """
|
||||||
# only do this if config enables it
|
# only do this if config enables it
|
||||||
if not config.get_bool(
|
if not config.get_bool(
|
||||||
|
@ -59,14 +58,14 @@ class WuttaContinuumConfigExtension(WuttaConfigExtension):
|
||||||
usedb=False,
|
usedb=False,
|
||||||
default="wutta_continuum.conf:WuttaContinuumPlugin",
|
default="wutta_continuum.conf:WuttaContinuumPlugin",
|
||||||
)
|
)
|
||||||
WuttaPlugin = load_object(spec)
|
plugin = load_object(spec)
|
||||||
|
|
||||||
# tell sqlalchemy-continuum to do its thing
|
# tell sqlalchemy-continuum to do its thing
|
||||||
make_versioned(plugins=[WuttaPlugin()])
|
make_versioned(plugins=[plugin()])
|
||||||
|
|
||||||
# nb. must load the model before configuring mappers
|
# nb. must load the model before configuring mappers
|
||||||
app = config.get_app()
|
app = config.get_app()
|
||||||
model = app.model
|
model = app.model # pylint: disable=unused-variable
|
||||||
|
|
||||||
# tell sqlalchemy to do its thing
|
# tell sqlalchemy to do its thing
|
||||||
configure_mappers()
|
configure_mappers()
|
||||||
|
@ -99,15 +98,20 @@ class WuttaContinuumPlugin(Plugin):
|
||||||
:doc:`sqlalchemy-continuum:plugins`.
|
:doc:`sqlalchemy-continuum:plugins`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_remote_addr(self, uow, session):
|
def get_remote_addr( # pylint: disable=empty-docstring,unused-argument
|
||||||
|
self, uow, session
|
||||||
|
):
|
||||||
""" """
|
""" """
|
||||||
host = socket.gethostname()
|
host = socket.gethostname()
|
||||||
return socket.gethostbyname(host)
|
return socket.gethostbyname(host)
|
||||||
|
|
||||||
def get_user_id(self, uow, session):
|
def get_user_id( # pylint: disable=empty-docstring,unused-argument
|
||||||
|
self, uow, session
|
||||||
|
):
|
||||||
""" """
|
""" """
|
||||||
|
return None
|
||||||
|
|
||||||
def transaction_args(self, uow, session):
|
def transaction_args(self, uow, session): # pylint: disable=empty-docstring
|
||||||
""" """
|
""" """
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|
||||||
|
@ -115,7 +119,7 @@ class WuttaContinuumPlugin(Plugin):
|
||||||
if remote_addr:
|
if remote_addr:
|
||||||
kwargs["remote_addr"] = remote_addr
|
kwargs["remote_addr"] = remote_addr
|
||||||
|
|
||||||
user_id = self.get_user_id(uow, session)
|
user_id = self.get_user_id(uow, session) # pylint: disable=assignment-from-none
|
||||||
if user_id:
|
if user_id:
|
||||||
kwargs["user_id"] = user_id
|
kwargs["user_id"] = user_id
|
||||||
|
|
||||||
|
|
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 wutta_continuum
|
||||||
|
|
||||||
[testenv:coverage]
|
[testenv:coverage]
|
||||||
basepython = python3.11
|
basepython = python3.11
|
||||||
commands = pytest --cov=wutta_continuum --cov-report=html --cov-fail-under=100
|
commands = pytest --cov=wutta_continuum --cov-report=html --cov-fail-under=100
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue