Skip to content

Commit 5e27735

Browse files
authored
テストコードをmypyチェックするようにしました。 (#498)
* テストコードのmypyチェック * format * テストコードの型チェック * poetry update * format
1 parent 13b87d6 commit 5e27735

File tree

7 files changed

+165
-275
lines changed

7 files changed

+165
-275
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ format:
1010
poetry run black annofabapi tests
1111

1212
lint:
13-
poetry run mypy annofabapi tests/create_test_project.py
14-
poetry run flake8 annofabapi tests/create_test_project.py
13+
poetry run mypy annofabapi tests
14+
poetry run flake8 annofabapi tests
1515
poetry run pylint --jobs=0 annofabapi
1616

1717
test:

poetry.lock

Lines changed: 75 additions & 222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_api.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
* 基本的にHTTP GETのテストのみ行うこと。PUT/POST/DELETEのテストがあると、間違えて修正してまうおそれあり。
77
88
"""
9+
from __future__ import annotations
10+
911
import configparser
1012
import datetime
1113
import os
1214
import uuid
15+
from typing import Any
1316

1417
import pytest
1518
import requests
@@ -45,6 +48,8 @@
4548

4649

4750
class TestAnnotation:
51+
input_data_id: str
52+
4853
@classmethod
4954
def setup_class(cls):
5055
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -121,6 +126,8 @@ def test_get_annotation_specs_relation(self):
121126

122127

123128
class TestComment:
129+
task: dict[str, Any]
130+
124131
@classmethod
125132
def setup_class(cls):
126133
task, _ = api.get_task(project_id, task_id)
@@ -178,6 +185,8 @@ def teardown_class(cls):
178185

179186

180187
class TestInputData:
188+
input_data_id: str
189+
181190
@classmethod
182191
def setup_class(cls):
183192
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -320,6 +329,8 @@ def test_get_my_member_in_project(self):
320329

321330

322331
class TestOrganization:
332+
organization_name: str
333+
323334
@classmethod
324335
def setup_class(cls):
325336
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
@@ -335,6 +346,8 @@ def test_wrapper_get_all_projects_of_organization(self):
335346

336347

337348
class TestOrganizationMember:
349+
organization_name: str
350+
338351
@classmethod
339352
def setup_class(cls):
340353
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
@@ -504,6 +517,8 @@ def test_get_statistics_available_dates(self):
504517

505518

506519
class Testsupplementary:
520+
input_data_id: str
521+
507522
@classmethod
508523
def setup_class(cls):
509524
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -519,19 +534,17 @@ def test_supplementary(self):
519534
)
520535

521536
supplementary_data_list = wrapper.get_supplementary_data_list_or_none(project_id, self.input_data_id)
537+
assert supplementary_data_list is not None
522538
assert len([e for e in supplementary_data_list if e["supplementary_data_id"] == supplementary_data_id]) == 1
523539

524540
api.delete_supplementary_data(project_id, self.input_data_id, supplementary_data_id)
525-
supplementary_data_list = api.get_supplementary_data_list(project_id, self.input_data_id)[0]
526-
assert len([e for e in supplementary_data_list if e["supplementary_data_id"] == supplementary_data_id]) == 0
527-
528-
# def test_wrapper_get_supplementary_data_list_or_none(self):
529-
# # 2021/01/04時点では、存在しないinput_data_idを指定すると404 Errorは発生しないので、このテストは実施しない
530-
# supplementary_data_list = wrapper.get_supplementary_data_list_or_none(project_id, "not-exists")
531-
# assert supplementary_data_list is None
541+
supplementary_data_list2 = api.get_supplementary_data_list(project_id, self.input_data_id)[0]
542+
assert len([e for e in supplementary_data_list2 if e["supplementary_data_id"] == supplementary_data_id]) == 0
532543

533544

534545
class TestTask:
546+
input_data_id: str
547+
535548
@classmethod
536549
def setup_class(cls):
537550
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -579,8 +592,8 @@ def test_batch_update_tasks(self):
579592
print(f"put_task: task_id={task_id}")
580593
test_task_data = api.put_task(project_id, test_task_id, request_body=request_body)[0]
581594

582-
request_body = [{"project_id": project_id, "task_id": test_task_id, "_type": "Delete"}]
583-
content = api.batch_update_tasks(project_id, request_body=request_body)[0]
595+
request_body2 = [{"project_id": project_id, "task_id": test_task_id, "_type": "Delete"}]
596+
content = api.batch_update_tasks(project_id, request_body=request_body2)[0]
584597
assert type(content) == list
585598

586599
def test_patch_tasks_metadata(self):
@@ -631,6 +644,9 @@ class TestGetObjOrNone:
631644
wrapper.get_xxx_or_none メソッドの確認
632645
"""
633646

647+
organization_name: str
648+
input_data_id: str
649+
634650
@classmethod
635651
def setup_class(cls):
636652
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
@@ -674,23 +690,23 @@ def test_get_task_or_none(self):
674690

675691
assert wrapper.get_task_or_none("not-exists", task_id) is None
676692

677-
def test_get_task_histories_or_none(self):
678-
assert type(wrapper.get_task_histories_or_none(project_id, task_id)) == list
679-
680-
assert wrapper.get_task_histories_or_none(project_id, "not-exists") is None
681-
682-
assert wrapper.get_task_histories_or_none("not-exists", task_id) is None
683-
684693
def test_get_task_histories_or_none(self):
685694
actual = wrapper.get_editor_annotation_or_none(project_id, task_id, self.input_data_id)
695+
assert actual is not None
686696
assert actual["task_id"] == task_id
687697
assert actual["input_data_id"] == self.input_data_id
688698

689699
assert wrapper.get_editor_annotation_or_none(project_id, task_id, "not-exists") is None
690700
assert wrapper.get_editor_annotation_or_none(project_id, "not-exists", "not-exists") is None
691701

702+
def test_get_supplementary_data_list_or_none(self):
703+
supplementary_data_list = wrapper.get_supplementary_data_list_or_none(project_id, "not-exists")
704+
assert supplementary_data_list is None
705+
692706

693707
class TestProtectedMethod:
708+
input_data_id: str
709+
694710
@classmethod
695711
def setup_class(cls):
696712
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)

tests/test_dataclass_webapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040

4141
class TestAnnotation:
42+
input_data_id: str
43+
4244
@classmethod
4345
def setup_class(cls):
4446
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -76,6 +78,8 @@ def test_input_data(self):
7678

7779

7880
class TestInspection:
81+
input_data_id: str
82+
7983
@classmethod
8084
def setup_class(cls):
8185
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
@@ -126,6 +130,8 @@ def test_my_account(self):
126130

127131

128132
class TestOrganization:
133+
organization_name: str
134+
129135
@classmethod
130136
def setup_class(cls):
131137
cls.organization_name = service.api.get_organization_of_project(project_id)[0]["organization_name"]
@@ -142,6 +148,8 @@ def test_organization_activity(self):
142148

143149

144150
class TestOrganizationMember:
151+
organization_name: str
152+
145153
@classmethod
146154
def setup_class(cls):
147155
cls.organization_name = service.api.get_organization_of_project(project_id)[0]["organization_name"]
@@ -181,6 +189,8 @@ def test_markers(self):
181189

182190

183191
class TestSupplementary:
192+
input_data_id: str
193+
184194
@classmethod
185195
def setup_class(cls):
186196
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)

tests/test_local_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,18 @@ def test_full_annotation_dir(self):
208208

209209
assert index == 4
210210

211-
parser = FullAnnotationDirParser(
211+
parser_full = FullAnnotationDirParser(
212212
Path(f"{test_dir}/full-annotation/sample_1/c86205d1-bdd4-4110-ae46-194e661d622b.json")
213213
)
214-
assert parser.task_id == "sample_1"
215-
assert parser.input_data_id == "c86205d1-bdd4-4110-ae46-194e661d622b"
214+
assert parser_full.task_id == "sample_1"
215+
assert parser_full.input_data_id == "c86205d1-bdd4-4110-ae46-194e661d622b"
216216

217-
dict_simple_annotation = parser.load_json()
217+
dict_simple_annotation = parser_full.load_json()
218218
assert type(dict_simple_annotation) == dict
219219
assert "details" in dict_simple_annotation
220220

221221
with pytest.raises(AnnotationOuterFileNotFoundError):
222-
parser.open_outer_file("foo")
222+
parser_full.open_outer_file("foo")
223223

224224
def convert_deitail_data(self, dict_data):
225225
if dict_data["_type"] == "Points":

0 commit comments

Comments
 (0)