|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from unittest.mock import Mock |
| 4 | + |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from annofabcli.annotation.change_annotation_data_per_annotation import ( |
| 8 | + ChangeAnnotationDataCount, |
| 9 | + ChangeAnnotationDataPerAnnotationMain, |
6 | 10 | TargetAnnotationData, |
7 | 11 | create_request_body_for_change_data, |
8 | 12 | get_annotation_data_list_per_task_id_input_data_id, |
@@ -91,6 +95,42 @@ def test_skip_when_annotation_does_not_exist(self) -> None: |
91 | 95 | assert actual_request_body == [] |
92 | 96 | assert actual_failed_count == 1 |
93 | 97 |
|
| 98 | + |
| 99 | +class TestChangeAnnotationDataPerAnnotationMain: |
| 100 | + def test_change_annotation_data_for_task_skips_on_hold_task_by_default(self) -> None: |
| 101 | + service = Mock() |
| 102 | + service.wrapper.get_task_or_none.return_value = {"task_id": "task1", "status": "on_hold"} |
| 103 | + main_obj = ChangeAnnotationDataPerAnnotationMain(service, project_id="prj1", include_complete_task=False, include_on_hold_task=False, all_yes=True) |
| 104 | + |
| 105 | + actual_is_changeable, actual_count = main_obj.change_annotation_data_for_task( |
| 106 | + "task1", |
| 107 | + {"input1": [TargetAnnotationData(task_id="task1", input_data_id="input1", annotation_id="anno1", data={"_type": "Range", "begin": 1000, "end": 5000})]}, |
| 108 | + ) |
| 109 | + |
| 110 | + assert actual_is_changeable is False |
| 111 | + assert actual_count == ChangeAnnotationDataCount(success=0, failed=1) |
| 112 | + |
| 113 | + def test_change_annotation_data_for_task_allows_on_hold_task_when_option_is_enabled(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 114 | + service = Mock() |
| 115 | + service.wrapper.get_task_or_none.return_value = {"task_id": "task1", "status": "on_hold"} |
| 116 | + main_obj = ChangeAnnotationDataPerAnnotationMain(service, project_id="prj1", include_complete_task=False, include_on_hold_task=True, all_yes=True) |
| 117 | + |
| 118 | + def change_annotation_data_by_frame(task_id: str, input_data_id: str, anno_list: list[TargetAnnotationData]) -> ChangeAnnotationDataCount: |
| 119 | + assert task_id == "task1" |
| 120 | + assert input_data_id == "input1" |
| 121 | + assert len(anno_list) == 1 |
| 122 | + return ChangeAnnotationDataCount(success=1, failed=0) |
| 123 | + |
| 124 | + monkeypatch.setattr(main_obj, "change_annotation_data_by_frame", change_annotation_data_by_frame) |
| 125 | + |
| 126 | + actual_is_changeable, actual_count = main_obj.change_annotation_data_for_task( |
| 127 | + "task1", |
| 128 | + {"input1": [TargetAnnotationData(task_id="task1", input_data_id="input1", annotation_id="anno1", data={"_type": "Range", "begin": 1000, "end": 5000})]}, |
| 129 | + ) |
| 130 | + |
| 131 | + assert actual_is_changeable is True |
| 132 | + assert actual_count == ChangeAnnotationDataCount(success=1, failed=0) |
| 133 | + |
94 | 134 | def test_skip_when_data_type_is_changed(self) -> None: |
95 | 135 | editor_annotation = { |
96 | 136 | "project_id": "prj1", |
|
0 commit comments