Skip to content

Commit ac3f28b

Browse files
committed
add
1 parent ff6bd52 commit ac3f28b

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"pydantic",
3434
"pydata",
3535
"pylint",
36+
"pytest",
3637
"relativedelta",
3738
"timespec",
3839
"tzlocal",

annofabapi/util/attribute_restrictions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
99
>>> import annofabapi
1010
>>> from annofabapi.util.annotation_specs import AnnotationSpecsAccessor
11-
>>> from annofabapi.util.attribute_restrictions import AttributeFactory
1211
>>> service = annofabapi.build()
1312
>>> annotation_specs, _ = service.api.get_annotation_specs("prj1", query_params={"v": "3"})
14-
>>> fac = AttributeFactory(AnnotationSpecsAccessor(annotation_specs))
13+
>>> fac = AttributeFactory(annotation_specs)
1514
1615
# 「'occluded'チェックボックスがONならば、'note'テキストボックスは空ではない」という制約
1716
>>> premise_restriction = fac.checkbox(attribute_name="occluded").checked()
@@ -295,11 +294,11 @@ class AttributeFactory:
295294
属性を生成するためのFactoryクラス
296295
297296
Attributes:
298-
accessor: アノテーション仕様のアクセサ
297+
annotation_specs: アノテーション仕様(v3)の情報
299298
"""
300299

301-
def __init__(self, accessor: AnnotationSpecsAccessor) -> None:
302-
self.accessor = accessor
300+
def __init__(self, annotation_specs: dict[str, Any]) -> None:
301+
self.accessor = AnnotationSpecsAccessor(annotation_specs)
303302

304303
def checkbox(self, *, attribute_id: Optional[str] = None, attribute_name: Optional[str] = None) -> Checkbox:
305304
return Checkbox(self.accessor, attribute_id=attribute_id, attribute_name=attribute_name)

tests/util/test_attribute_restrictions.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
from annofabapi.util.annotation_specs import AnnotationSpecsAccessor
7-
from annofabapi.util.attribute_restrictions import AnnotationLink, Checkbox, IntegerTextbox, Selection, StringTextbox, TrackingId
7+
from annofabapi.util.attribute_restrictions import AnnotationLink, Checkbox, IntegerTextbox, Selection, StringTextbox, TrackingId, AttributeFactory
88

99
accessor = AnnotationSpecsAccessor(annotation_specs=json.loads(Path("tests/data/util/attribute_restrictions/annotation_specs.json").read_text()))
1010

@@ -161,3 +161,40 @@ def test__implyメソッドの戻りに対してimplyメソッドを実行する
161161
Checkbox(accessor, attribute_name="occluded").checked().imply(IntegerTextbox(accessor, attribute_name="traffic_lane").equals(2)).imply(
162162
StringTextbox(accessor, attribute_name="note").is_not_empty()
163163
)
164+
165+
166+
class Test__AttributeFactory:
167+
def setup_method(self):
168+
self.annotation_specs = json.loads(Path("tests/data/util/attribute_restrictions/annotation_specs.json").read_text())
169+
self.factory = AttributeFactory(self.annotation_specs)
170+
171+
def test__checkbox(self):
172+
checkbox = self.factory.checkbox(attribute_name="occluded")
173+
assert isinstance(checkbox, Checkbox)
174+
assert checkbox.attribute_id == "2517f635-2269-4142-8ef4-16312b4cc9f7"
175+
176+
def test__string_textbox(self):
177+
string_textbox = self.factory.string_textbox(attribute_name="note")
178+
assert isinstance(string_textbox, StringTextbox)
179+
assert string_textbox.attribute_id == "9b05648d-1e16-4ea2-ab79-48907f5eed00"
180+
181+
def test__integer_textbox(self):
182+
integer_textbox = self.factory.integer_textbox(attribute_name="traffic_lane")
183+
assert isinstance(integer_textbox, IntegerTextbox)
184+
assert integer_textbox.attribute_id == "ec27de5d-122c-40e7-89bc-5500e37bae6a"
185+
186+
def test__annotation_link(self):
187+
annotation_link = self.factory.annotation_link(attribute_name="link_car")
188+
assert isinstance(annotation_link, AnnotationLink)
189+
assert annotation_link.attribute_id == "15ba8b9d-4882-40c2-bb31-ed3f68197c2e"
190+
191+
def test__tracking_id(self):
192+
tracking_id = self.factory.tracking_id(attribute_name="tracking")
193+
assert isinstance(tracking_id, TrackingId)
194+
assert tracking_id.attribute_id == "d349e76d-b59a-44cd-94b4-713a00b2e84d"
195+
196+
def test__selection(self):
197+
selection = self.factory.selection(attribute_name="car_kind")
198+
assert isinstance(selection, Selection)
199+
assert selection.attribute_id == "cbb0155f-1631-48e1-8fc3-43c5f254b6f2"
200+

0 commit comments

Comments
 (0)