Skip to content

Commit 07388cb

Browse files
committed
update to tests
1 parent 5c27405 commit 07388cb

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

Dockerfile

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

33
COPY . /usr/src/labelbox
44
WORKDIR /usr/src/labelbox

labelbox/schema/ontology_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def add_classification(self, classification: Classification):
143143
for c in self.classifications):
144144
raise InconsistentOntologyException(
145145
f"Duplicate nested classification '{classification.instructions}' "
146-
f"for option '{self.label}'")
146+
f"for tool '{self.name}'")
147147
self.classifications.append(classification)
148148

149149
@dataclass
@@ -175,7 +175,7 @@ def add_classification(self, classification: Classification) -> Classification:
175175
if classification.instructions in (c.instructions
176176
for c in self.classifications):
177177
raise InconsistentOntologyException(
178-
f"Duplicate classifications instructions '{classification.instructions}'. ")
178+
f"Duplicate classification instructions '{classification.instructions}'. ")
179179
self.classifications.append(classification)
180180

181181
def asdict(self):

tests/integration/test_ontology.py

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
"""
2-
TODO:
3-
test option.add_option
4-
test classification.add_option
5-
test tool.add_classification
6-
consider testing and ensuring failed scenarios
7-
"""
81
from typing import Any, Dict, List, Union
92

103
import pytest
@@ -21,7 +14,7 @@
2114
"color": "#FF0000",
2215
"tool": "rectangle",
2316
"classifications": []
24-
}],
17+
}],
2518
"classifications": [{
2619
"required": True,
2720
"instructions": "This is a question.",
@@ -71,9 +64,12 @@ def test_add_ontology_tool() -> None:
7164

7265
second_tool = Tool(tool = Tool.Type.SEGMENTATION, name = "segmentation")
7366
o.add_tool(second_tool)
74-
7567
assert len(o.tools) == 2
7668

69+
with pytest.raises(InconsistentOntologyException) as exc:
70+
o.add_tool(Tool(tool=Tool.Type.BBOX, name = "bounding box"))
71+
assert "Duplicate tool name" in str(exc.value)
72+
7773
def test_add_ontology_classification() -> None:
7874
o = Ontology()
7975
o.add_classification(Classification(
@@ -82,23 +78,56 @@ def test_add_ontology_classification() -> None:
8278
second_classification = Classification(
8379
class_type = Classification.Type.CHECKLIST, instructions = "checklist")
8480
o.add_classification(second_classification)
85-
8681
assert len(o.classifications) == 2
8782

83+
with pytest.raises(InconsistentOntologyException) as exc:
84+
o.add_classification(Classification(
85+
class_type = Classification.Type.TEXT, instructions = "text"))
86+
assert "Duplicate classification instructions" in str(exc.value)
87+
88+
def test_tool_add_classification() -> None:
89+
t = Tool(tool = Tool.Type.SEGMENTATION, name = "segmentation")
90+
c = Classification(
91+
class_type = Classification.Type.TEXT, instructions = "text")
92+
t.add_classification(c)
93+
assert t.classifications[0] == c
94+
95+
with pytest.raises(Exception) as exc:
96+
t.add_classification(c)
97+
assert "Duplicate nested classification" in str(exc)
98+
99+
def test_classification_add_option() -> None:
100+
c = Classification(
101+
class_type = Classification.Type.RADIO, instructions = "radio")
102+
o = Option(value = "option")
103+
c.add_option(o)
104+
assert c.options[0] == o
105+
106+
with pytest.raises(InconsistentOntologyException) as exc:
107+
c.add_option(Option(value = "option"))
108+
assert "Duplicate option" in str(exc.value)
109+
110+
def test_option_add_option() -> None:
111+
o = Option(value = "option")
112+
c = Classification(
113+
class_type = Classification.Type.TEXT, instructions = "text")
114+
o.add_option(c)
115+
assert o.options[0] == c
116+
117+
with pytest.raises(InconsistentOntologyException) as exc:
118+
o.add_option(c)
119+
assert "Duplicate nested classification" in str(exc.value)
120+
88121
def test_ontology_asdict(project) -> None:
89122
o = Ontology.from_project(project)
90123
assert o.asdict() == project.ontology().normalized
91124

92125
def test_from_project_ontology(client, project) -> None:
93-
frontend = list(
94-
client.get_labeling_frontends(
95-
where=LabelingFrontend.name == "Editor"))[0]
126+
frontend = list(client.get_labeling_frontends(
127+
where=LabelingFrontend.name == "Editor"))[0]
96128
project.setup(frontend, _SAMPLE_ONTOLOGY)
97129
o = Ontology.from_project(project)
98130

99131
assert o.tools[0].tool == Tool.Type.BBOX
100132
assert o.classifications[0].class_type == Classification.Type.RADIO
101-
assert o.classifications[0].options[0].value.lower() == "yes"
102-
103-
104-
133+
assert o.classifications[0].options[0].value.lower() == "yes"

0 commit comments

Comments
 (0)