Skip to content

Commit

Permalink
テストコードをmypyチェックするようにしました。 (#498)
Browse files Browse the repository at this point in the history
* テストコードのmypyチェック

* format

* テストコードの型チェック

* poetry update

* format
  • Loading branch information
yuji38kwmt committed Aug 18, 2022
1 parent 13b87d6 commit 5e27735
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 275 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ format:
poetry run black annofabapi tests

lint:
poetry run mypy annofabapi tests/create_test_project.py
poetry run flake8 annofabapi tests/create_test_project.py
poetry run mypy annofabapi tests
poetry run flake8 annofabapi tests
poetry run pylint --jobs=0 annofabapi

test:
Expand Down
297 changes: 75 additions & 222 deletions poetry.lock

Large diffs are not rendered by default.

48 changes: 32 additions & 16 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
* 基本的にHTTP GETのテストのみ行うこと。PUT/POST/DELETEのテストがあると、間違えて修正してまうおそれあり。
"""
from __future__ import annotations

import configparser
import datetime
import os
import uuid
from typing import Any

import pytest
import requests
Expand Down Expand Up @@ -45,6 +48,8 @@


class TestAnnotation:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down Expand Up @@ -121,6 +126,8 @@ def test_get_annotation_specs_relation(self):


class TestComment:
task: dict[str, Any]

@classmethod
def setup_class(cls):
task, _ = api.get_task(project_id, task_id)
Expand Down Expand Up @@ -178,6 +185,8 @@ def teardown_class(cls):


class TestInputData:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down Expand Up @@ -320,6 +329,8 @@ def test_get_my_member_in_project(self):


class TestOrganization:
organization_name: str

@classmethod
def setup_class(cls):
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
Expand All @@ -335,6 +346,8 @@ def test_wrapper_get_all_projects_of_organization(self):


class TestOrganizationMember:
organization_name: str

@classmethod
def setup_class(cls):
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
Expand Down Expand Up @@ -504,6 +517,8 @@ def test_get_statistics_available_dates(self):


class Testsupplementary:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand All @@ -519,19 +534,17 @@ def test_supplementary(self):
)

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

api.delete_supplementary_data(project_id, self.input_data_id, supplementary_data_id)
supplementary_data_list = api.get_supplementary_data_list(project_id, self.input_data_id)[0]
assert len([e for e in supplementary_data_list if e["supplementary_data_id"] == supplementary_data_id]) == 0

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


class TestTask:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down Expand Up @@ -579,8 +592,8 @@ def test_batch_update_tasks(self):
print(f"put_task: task_id={task_id}")
test_task_data = api.put_task(project_id, test_task_id, request_body=request_body)[0]

request_body = [{"project_id": project_id, "task_id": test_task_id, "_type": "Delete"}]
content = api.batch_update_tasks(project_id, request_body=request_body)[0]
request_body2 = [{"project_id": project_id, "task_id": test_task_id, "_type": "Delete"}]
content = api.batch_update_tasks(project_id, request_body=request_body2)[0]
assert type(content) == list

def test_patch_tasks_metadata(self):
Expand Down Expand Up @@ -631,6 +644,9 @@ class TestGetObjOrNone:
wrapper.get_xxx_or_none メソッドの確認
"""

organization_name: str
input_data_id: str

@classmethod
def setup_class(cls):
cls.organization_name = api.get_organization_of_project(project_id)[0]["organization_name"]
Expand Down Expand Up @@ -674,23 +690,23 @@ def test_get_task_or_none(self):

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

def test_get_task_histories_or_none(self):
assert type(wrapper.get_task_histories_or_none(project_id, task_id)) == list

assert wrapper.get_task_histories_or_none(project_id, "not-exists") is None

assert wrapper.get_task_histories_or_none("not-exists", task_id) is None

def test_get_task_histories_or_none(self):
actual = wrapper.get_editor_annotation_or_none(project_id, task_id, self.input_data_id)
assert actual is not None
assert actual["task_id"] == task_id
assert actual["input_data_id"] == self.input_data_id

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

def test_get_supplementary_data_list_or_none(self):
supplementary_data_list = wrapper.get_supplementary_data_list_or_none(project_id, "not-exists")
assert supplementary_data_list is None


class TestProtectedMethod:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_dataclass_webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@


class TestAnnotation:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down Expand Up @@ -76,6 +78,8 @@ def test_input_data(self):


class TestInspection:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down Expand Up @@ -126,6 +130,8 @@ def test_my_account(self):


class TestOrganization:
organization_name: str

@classmethod
def setup_class(cls):
cls.organization_name = service.api.get_organization_of_project(project_id)[0]["organization_name"]
Expand All @@ -142,6 +148,8 @@ def test_organization_activity(self):


class TestOrganizationMember:
organization_name: str

@classmethod
def setup_class(cls):
cls.organization_name = service.api.get_organization_of_project(project_id)[0]["organization_name"]
Expand Down Expand Up @@ -181,6 +189,8 @@ def test_markers(self):


class TestSupplementary:
input_data_id: str

@classmethod
def setup_class(cls):
cls.input_data_id = test_wrapper.get_first_input_data_id_in_task(project_id, task_id)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_local_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ def test_full_annotation_dir(self):

assert index == 4

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

dict_simple_annotation = parser.load_json()
dict_simple_annotation = parser_full.load_json()
assert type(dict_simple_annotation) == dict
assert "details" in dict_simple_annotation

with pytest.raises(AnnotationOuterFileNotFoundError):
parser.open_outer_file("foo")
parser_full.open_outer_file("foo")

def convert_deitail_data(self, dict_data):
if dict_data["_type"] == "Points":
Expand Down

0 comments on commit 5e27735

Please sign in to comment.