tests: add mypy + misc fixes to make test pass

This commit is contained in:
Alexandre Aubin 2021-09-17 18:27:16 +02:00
parent e07c01e936
commit 1c46636b7e
7 changed files with 21 additions and 6 deletions

View file

@ -19,6 +19,13 @@ invalidcode37:
script: script:
- tox -e py37-invalidcode - tox -e py37-invalidcode
mypy:
stage: lint
image: "before-install"
needs: []
script:
- tox -e py37-mypy
format-check: format-check:
stage: lint stage: lint
image: "before-install" image: "before-install"

View file

@ -24,6 +24,7 @@
Manage domains Manage domains
""" """
import os import os
from typing import Dict, Any
from moulinette import m18n, Moulinette from moulinette import m18n, Moulinette
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
@ -47,7 +48,7 @@ DOMAIN_CONFIG_PATH = "/usr/share/yunohost/other/config_domain.toml"
DOMAIN_SETTINGS_DIR = "/etc/yunohost/domains" DOMAIN_SETTINGS_DIR = "/etc/yunohost/domains"
# Lazy dev caching to avoid re-query ldap every time we need the domain list # Lazy dev caching to avoid re-query ldap every time we need the domain list
domain_list_cache = {} domain_list_cache: Dict[str, Any] = {}
def domain_list(exclude_subdomains=False): def domain_list(exclude_subdomains=False):

View file

@ -29,6 +29,7 @@ import re
import yaml import yaml
import glob import glob
import psutil import psutil
from typing import List
from datetime import datetime, timedelta from datetime import datetime, timedelta
from logging import FileHandler, getLogger, Formatter from logging import FileHandler, getLogger, Formatter
@ -478,7 +479,7 @@ class OperationLogger(object):
This class record logs and metadata like context or start time/end time. This class record logs and metadata like context or start time/end time.
""" """
_instances = [] _instances: List[object] = []
def __init__(self, operation, related_to=None, **kwargs): def __init__(self, operation, related_to=None, **kwargs):
# TODO add a way to not save password on app installation # TODO add a way to not save password on app installation

View file

@ -29,6 +29,7 @@ import subprocess
import time import time
from importlib import import_module from importlib import import_module
from packaging import version from packaging import version
from typing import List
from moulinette import Moulinette, m18n from moulinette import Moulinette, m18n
from moulinette.utils.log import getActionLogger from moulinette.utils.log import getActionLogger
@ -1113,7 +1114,7 @@ class Migration(object):
# Those are to be implemented by daughter classes # Those are to be implemented by daughter classes
mode = "auto" mode = "auto"
dependencies = [] # List of migration ids required before running this migration dependencies: List[str] = [] # List of migration ids required before running this migration
@property @property
def disclaimer(self): def disclaimer(self):

View file

@ -25,6 +25,7 @@ import urllib.parse
import tempfile import tempfile
import shutil import shutil
from collections import OrderedDict from collections import OrderedDict
from typing import Optional, Dict, List
from moulinette.interfaces.cli import colorize from moulinette.interfaces.cli import colorize
from moulinette import Moulinette, m18n from moulinette import Moulinette, m18n
@ -454,7 +455,7 @@ class ConfigPanel:
class Question(object): class Question(object):
hide_user_input_in_prompt = False hide_user_input_in_prompt = False
pattern = None pattern: Optional[Dict] = None
def __init__(self, question, user_answers): def __init__(self, question, user_answers):
self.name = question["name"] self.name = question["name"]
@ -940,7 +941,7 @@ class DisplayTextQuestion(Question):
class FileQuestion(Question): class FileQuestion(Question):
argument_type = "file" argument_type = "file"
upload_dirs = [] upload_dirs: List[str] = []
@classmethod @classmethod
def clean_upload_dirs(cls): def clean_upload_dirs(cls):

View file

@ -19,13 +19,15 @@
""" """
import dns.resolver import dns.resolver
from typing import List
from moulinette.utils.filesystem import read_file from moulinette.utils.filesystem import read_file
YNH_DYNDNS_DOMAINS = ["nohost.me", "noho.st", "ynh.fr"] YNH_DYNDNS_DOMAINS = ["nohost.me", "noho.st", "ynh.fr"]
# Lazy dev caching to avoid re-reading the file multiple time when calling # Lazy dev caching to avoid re-reading the file multiple time when calling
# dig() often during same yunohost operation # dig() often during same yunohost operation
external_resolvers_ = [] external_resolvers_: List[str] = []
def external_resolvers(): def external_resolvers():

View file

@ -6,8 +6,10 @@ skip_install=True
deps = deps =
py37-{lint,invalidcode}: flake8 py37-{lint,invalidcode}: flake8
py37-black-{run,check}: black py37-black-{run,check}: black
py37-mypy: mypy >= 0.900
commands = commands =
py37-lint: flake8 src doc data tests --ignore E402,E501,E203,W503 --exclude src/yunohost/vendor py37-lint: flake8 src doc data tests --ignore E402,E501,E203,W503 --exclude src/yunohost/vendor
py37-invalidcode: flake8 src data --exclude src/yunohost/tests,src/yunohost/vendor --select F py37-invalidcode: flake8 src data --exclude src/yunohost/tests,src/yunohost/vendor --select F
py37-black-check: black --check --diff src doc data tests py37-black-check: black --check --diff src doc data tests
py37-black-run: black src doc data tests py37-black-run: black src doc data tests
py37-mypy: mypy --ignore-missing-import --install-types --non-interactive --follow-imports silent src/yunohost/ --exclude (acme_tiny|data_migrations)