Merge pull request #299 from YunoHost/mypy

tests: add mypy + misc fixes to make test pass
This commit is contained in:
Alexandre Aubin 2021-09-17 16:26:11 +02:00 committed by GitHub
commit 6a2ae5630b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 18 deletions

View file

@ -44,3 +44,5 @@ jobs:
pip install tox tox-gh-actions pip install tox tox-gh-actions
- name: Linter - name: Linter
run: tox -e py37-invalidcode run: tox -e py37-invalidcode
- name: Mypy
run: tox -e py37-mypy

View file

@ -6,6 +6,7 @@ import logging
import glob import glob
import pickle as pickle import pickle as pickle
from typing import List, Optional
from time import time from time import time
from collections import OrderedDict from collections import OrderedDict
from importlib import import_module from importlib import import_module
@ -30,7 +31,6 @@ logger = logging.getLogger("moulinette.actionsmap")
class _ExtraParameter(object): class _ExtraParameter(object):
""" """
Argument parser for an extra parameter. Argument parser for an extra parameter.
@ -39,21 +39,14 @@ class _ExtraParameter(object):
""" """
name: Optional[str] = None
"""A list of interface for which the parameter doesn't apply to"""
skipped_iface: List[str] = []
def __init__(self, iface): def __init__(self, iface):
self.iface = iface self.iface = iface
# Required variables
# Each extra parameters classes must overwrite these variables.
"""The extra parameter name"""
name = None
# Optional variables
# Each extra parameters classes can overwrite these variables.
"""A list of interface for which the parameter doesn't apply"""
skipped_iface = []
# Virtual methods # Virtual methods
# Each extra parameters classes can implement these methods. # Each extra parameters classes can implement these methods.
@ -621,7 +614,7 @@ class ActionsMap(object):
# This var is ['*'] by default but could be set for example to # This var is ['*'] by default but could be set for example to
# ['yunohost', 'yml_*'] # ['yunohost', 'yml_*']
NAMESPACE_PATTERNS = env["NAMESPACES"] NAMESPACE_PATTERNS = env["NAMESPACES"].split()
# Look for all files that match the given patterns in the actionsmap dir # Look for all files that match the given patterns in the actionsmap dir
for namespace_pattern in NAMESPACE_PATTERNS: for namespace_pattern in NAMESPACE_PATTERNS:

View file

@ -22,8 +22,6 @@ for key in env.keys():
if value_from_environ: if value_from_environ:
env[key] = value_from_environ env[key] = value_from_environ
env["NAMESPACES"] = env["NAMESPACES"].split()
def during_unittests_run(): def during_unittests_run():
return "TESTS_RUN" in os.environ return "TESTS_RUN" in os.environ

View file

@ -7,6 +7,7 @@ import copy
import datetime import datetime
from collections import deque, OrderedDict from collections import deque, OrderedDict
from json.encoder import JSONEncoder from json.encoder import JSONEncoder
from typing import Optional
from moulinette import m18n from moulinette import m18n
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
@ -44,7 +45,7 @@ class BaseActionsMapParser(object):
# Each parser classes must implement these properties. # Each parser classes must implement these properties.
"""The name of the interface for which it is the parser""" """The name of the interface for which it is the parser"""
interface = None interface: Optional[str] = None
# Virtual methods # Virtual methods
# Each parser classes must implement these methods. # Each parser classes must implement these methods.

View file

@ -268,6 +268,7 @@ class Session:
return infos return infos
@staticmethod
def delete_infos(): def delete_infos():
response.set_cookie(f"session.{Session.actionsmap_name}", "", max_age=-1) response.set_cookie(f"session.{Session.actionsmap_name}", "", max_age=-1)

View file

@ -1,6 +1,6 @@
[tox] [tox]
envlist = envlist =
py37-{pytest,lint,invalidcode} py37-{pytest,lint,invalidcode,mypy}
format format
format-check format-check
docs docs
@ -14,10 +14,12 @@ deps =
py37-pytest: .[tests] py37-pytest: .[tests]
py37-lint: flake8 py37-lint: flake8
py37-invalidcode: flake8 py37-invalidcode: flake8
py37-mypy: mypy >= 0.761
commands = commands =
py37-pytest: pytest {posargs} -c pytest.ini py37-pytest: pytest {posargs} -c pytest.ini
py37-lint: flake8 moulinette test py37-lint: flake8 moulinette test
py37-invalidcode: flake8 moulinette test --select F py37-invalidcode: flake8 moulinette test --select F
py37-mypy: mypy --ignore-missing-imports --install-types --non-interactive moulinette/
[gh-actions] [gh-actions]
python = python =