8000 Merge pull request #9 from suaaa7/python_test_example · suaaa7/samplecode-for-qiita@2a66062 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a66062

Browse files
authored
Merge pull request #9 from suaaa7/python_test_example
Add mypy
2 parents 7ece0ef + 050a71d commit 2a66062

File tree

7 files changed

+32
-6
lines changed

7 files changed

+32
-6
lines changed

.github/workflows/test_for_python_test_example.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ jobs:
1515
- name: Install Library
1616
run: |
1717
python3 -m pip install --upgrade pip
18-
pip install requests flask
18+
pip install requests flask mypy
19+
- name: Run mypy
20+
run: |
21+
mypy python_test_example --config-file python_test_example/mypy.ini
1922
- name: Run unittest
2023
run: |
2124
cd python_test_example

python_test_example/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM python:3.7-slim
22

33
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
4-
&& pip install --no-cache-dir requests flask
4+
&& pip install --no-cache-dir requests flask mypy

python_test_example/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ dbuild:
1010
drun:
1111
docker run --rm -it -v $(curdir):/opt -w /opt $(image):$(tag) bash
1212

13+
.PHONY: drmi
14+
drmi:
15+
docker rmi -f $(image):$(tag)
16+
1317
.PHONY: all_test
1418
all_test:
1519
python3 -m unittest discover --verbose --pattern "*_test.py"

python_test_example/flask_app/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from flask import Flask, jsonify, make_response
4+
from flask.wrappers import Response
45

56
from .service import Service
67

@@ -10,12 +11,12 @@
1011
service = Service()
1112

1213
@app.route('/', methods=['GET'])
13-
def index():
14+
def index() -> Response:
1415
message = {'message': 'OK'}
1516
return make_response(jsonify(message), 200)
1617

1718
@app.route('/predict', methods=['POST'])
18-
def predict():
19+
def predict() -> Response:
1920
print('Call predict in app')
2021
target = 'A'
2122
if not service.check_model():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
def load_model():
1+
def load_model() -> str:
22
print('Call load_model in model')
33
return 'model'

python_test_example/flask_app/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
print('In service')
66

77
class Service:
8-
def __init__(self):
8+
def __init__(self) -> None:
99
print('Init Service')
1010
self.model = load_model()
1111
print(f'self.model: {self.model}')

python_test_example/mypy.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[mypy]
2+
python_version = 3.7
3+
disallow_untyped_defs = True
4+
ignore_missing_imports = True
5+
warn_redundant_casts = True
6+
no_implicit_optional = True
7+
8+
[mypy-flask_app.app_test.*]
9+
disallow_untyped_defs = False
10+
11+
[mypy-i76_testcase_subclass.utils_test.*]
12+
disallow_untyped_defs = False
13+
14+
[mypy-i77_setup_and_teardown.*]
15+
disallow_untyped_defs = False
16+
17+
[mypy-mock.my_class_test.*]
18+
disallow_untyped_defs = False

0 commit comments

Comments
 (0)
0