diff --git a/.github/workflows/test_for_python_test_example.yml b/.github/workflows/test_for_python_test_example.yml index 7aa48ab..f881bd5 100644 --- a/.github/workflows/test_for_python_test_example.yml +++ b/.github/workflows/test_for_python_test_example.yml @@ -15,7 +15,10 @@ jobs: - name: Install Library run: | python3 -m pip install --upgrade pip - pip install requests flask + pip install requests flask mypy + - name: Run mypy + run: | + mypy python_test_example --config-file python_test_example/mypy.ini - name: Run unittest run: | cd python_test_example diff --git a/python_test_example/Dockerfile b/python_test_example/Dockerfile index 9d0711b..e97349f 100644 --- a/python_test_example/Dockerfile +++ b/python_test_example/Dockerfile @@ -1,4 +1,4 @@ FROM python:3.7-slim RUN pip install --no-cache-dir --upgrade pip setuptools wheel \ - && pip install --no-cache-dir requests flask + && pip install --no-cache-dir requests flask mypy diff --git a/python_test_example/Makefile b/python_test_example/Makefile index 9f0661e..ae48f0e 100644 --- a/python_test_example/Makefile +++ b/python_test_example/Makefile @@ -10,6 +10,10 @@ dbuild: drun: docker run --rm -it -v $(curdir):/opt -w /opt $(image):$(tag) bash +.PHONY: drmi +drmi: + docker rmi -f $(image):$(tag) + .PHONY: all_test all_test: python3 -m unittest discover --verbose --pattern "*_test.py" diff --git a/python_test_example/flask_app/app.py b/python_test_example/flask_app/app.py index de21bc0..f3de11e 100644 --- a/python_test_example/flask_app/app.py +++ b/python_test_example/flask_app/app.py @@ -1,6 +1,7 @@ import json from flask import Flask, jsonify, make_response +from flask.wrappers import Response from .service import Service @@ -10,12 +11,12 @@ service = Service() @app.route('/', methods=['GET']) -def index(): +def index() -> Response: message = {'message': 'OK'} return make_response(jsonify(message), 200) @app.route('/predict', methods=['POST']) -def predict(): +def predict() -> Response: print('Call predict in app') target = 'A' if not service.check_model(): diff --git a/python_test_example/flask_app/model.py b/python_test_example/flask_app/model.py index ef296ea..f136e85 100644 --- a/python_test_example/flask_app/model.py +++ b/python_test_example/flask_app/model.py @@ -1,3 +1,3 @@ -def load_model(): +def load_model() -> str: print('Call load_model in model') return 'model' diff --git a/python_test_example/flask_app/service.py b/python_test_example/flask_app/service.py index 5f4791f..98dd09e 100644 --- a/python_test_example/flask_app/service.py +++ b/python_test_example/flask_app/service.py @@ -5,7 +5,7 @@ print('In service') class Service: - def __init__(self): + def __init__(self) -> None: print('Init Service') self.model = load_model() print(f'self.model: {self.model}') diff --git a/python_test_example/mypy.ini b/python_test_example/mypy.ini new file mode 100644 index 0000000..9db99d4 --- /dev/null +++ b/python_test_example/mypy.ini @@ -0,0 +1,18 @@ +[mypy] +python_version = 3.7 +disallow_untyped_defs = True +ignore_missing_imports = True +warn_redundant_casts = True +no_implicit_optional = True + +[mypy-flask_app.app_test.*] +disallow_untyped_defs = False + +[mypy-i76_testcase_subclass.utils_test.*] +disallow_untyped_defs = False + +[mypy-i77_setup_and_teardown.*] +disallow_untyped_defs = False + +[mypy-mock.my_class_test.*] +disallow_untyped_defs = False