#524 Add mypy for testing
Merged 4 years ago by mulaieva. Opened 4 years ago by mulaieva.
mulaieva/freshmaker mypy_add  into  master

file modified
+4
@@ -9,3 +9,7 @@ 

  tests/test_freshmaker.db

  freshmaker.db

  .pytest_cache

+ # mypy

+ .mypy_cache/

+ .dmypy.json

+ dmypy.json

file modified
+3 -2
@@ -2,6 +2,7 @@ 

  

  import os

  import tempfile

+ from typing import Optional, Tuple, Union

  

  from freshmaker.config import all_, any_  # noqa

  
@@ -148,9 +149,9 @@ 

      # Path to credential cache file. This optional could be None when not using

      # a client keytab to acquire credential.

      KRB_AUTH_CCACHE_FILE = tempfile.mkstemp(

-         suffix=str(os.getpid()), prefix="freshmaker_cc_")

+         suffix=str(os.getpid()), prefix="freshmaker_cc_")  # type: Union[Tuple[int, str], Optional[str]]

  

-     # Select which authentication backend to work with. There are 3 choices

+     # Select which authentication backend to work with. There are 3 choices Tuple[int, str]

      # noauth: no authentication is enabled. Useful for development particularly.

      # kerberos: Kerberos authentication is enabled.

      # openidc: OpenIDC authentication is enabled.

file modified
+3 -2
@@ -26,6 +26,7 @@ 

  import pkg_resources

  

  from logging import getLogger

+ from typing import Any

  

  from flask import Flask

  from flask_login import LoginManager
@@ -40,12 +41,12 @@ 

  except pkg_resources.DistributionNotFound:

      version = 'unknown'

  

- app = Flask(__name__)

+ app = Flask(__name__)  # type: Any

  app.wsgi_app = ReverseProxy(app.wsgi_app)

  

  conf = init_config(app)

  

- db = SQLAlchemy(app)

+ db = SQLAlchemy(app)  # type: Any

  

  init_logging(conf)

  log = getLogger(__name__)

file modified
+1 -1
@@ -29,7 +29,7 @@ 

  import os

  import threading

  

- from os import sys

+ from os import sys  # type: ignore

  from freshmaker import logger

  

  

file modified
+2 -1
@@ -22,6 +22,7 @@ 

  # Written by Jan Kaluza <jkaluza@redhat.com>

  

  import itertools

+ from typing import Dict, Any

  

  from freshmaker import conf

  from freshmaker.types import ArtifactType
@@ -31,7 +32,7 @@ 

  

  class BaseEvent(object):

  

-     _parsers = {}

+     _parsers = {}  # type: Dict[Any, Any]

  

      def __init__(self, msg_id, manual=False, dry_run=False):

          """

@@ -22,6 +22,7 @@ 

  # Written by Jan Kaluza <jkaluza@redhat.com>

  

  import abc

+ from typing import List

  

  

  class BaseParser(object):
@@ -30,7 +31,7 @@ 

      """

      __metaclass__ = abc.ABCMeta

      name = "abstract_parser"

-     topic_suffixes = []

+     topic_suffixes = []  # type: List[str]

  

      @abc.abstractmethod

      def can_parse(self, topic, msg):

file modified
+1
@@ -5,6 +5,7 @@ 

  pytest-cov

  vcrpy

  tox

+ mypy

  # It seems like Flask needs this itsdangerous package.

  # But there's a bug in a previous version:

  # https://github.com/pallets/itsdangerous/issues/102

file modified
+8 -1
@@ -4,7 +4,7 @@ 

  # and then run "tox" from this directory.

  

  [tox]

- envlist = py37, flake8, bandit

+ envlist = py37, flake8, bandit, mypy

  

  [testenv]

  basepython = python3
@@ -27,6 +27,13 @@ 

  deps = flake8

  commands = flake8

  

+ [testenv:mypy]

+ description = type check

+ deps =

+     mypy

+ commands =

+         mypy --ignore-missing-imports .

+ 

  [testenv:bandit]

  basepython = python3

  skip_install = true