Skip to content

Commit c375b68

Browse files
committed
Fix lint
1 parent 3c5bf21 commit c375b68

File tree

3 files changed

+79
-51
lines changed

3 files changed

+79
-51
lines changed

libs/labelbox/src/labelbox/schema/ontology.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def add_classification(self, classification: Classification) -> None:
155155
)
156156
self.classifications.append(classification)
157157

158+
158159
"""
159160
The following 2 functions help to bridge the gap between the step reasoning all other tool ontologies.
160161
"""

libs/labelbox/src/labelbox/schema/tool_building/relationship_tool.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from labelbox.schema.ontology import Tool
88

9+
910
@dataclass
1011
class RelationshipTool(Tool):
1112
"""
@@ -44,7 +45,12 @@ class RelationshipTool(Tool):
4445

4546
constraints: Optional[List[Tuple[str, str]]] = None
4647

47-
def __init__(self, name: str, constraints: Optional[List[Tuple[str, str]]] = None, **kwargs):
48+
def __init__(
49+
self,
50+
name: str,
51+
constraints: Optional[List[Tuple[str, str]]] = None,
52+
**kwargs,
53+
):
4854
super().__init__(Tool.Type.RELATIONSHIP, name, **kwargs)
4955
if constraints is not None:
5056
self.constraints = constraints
@@ -57,7 +63,7 @@ def __post_init__(self):
5763
def asdict(self) -> Dict[str, Any]:
5864
result = super().asdict()
5965
if self.constraints is not None:
60-
result["definition"] = { "constraints": self.constraints }
66+
result["definition"] = {"constraints": self.constraints}
6167
return result
6268

6369
def add_constraint(self, start: Tool, end: Tool) -> None:
@@ -77,8 +83,10 @@ def add_constraint(self, start: Tool, end: Tool) -> None:
7783
if end.schema_id is None:
7884
end.schema_id = str(uuid.uuid4())
7985

80-
self.constraints.append((start.feature_schema_id, end.feature_schema_id))
81-
86+
self.constraints.append(
87+
(start.feature_schema_id, end.feature_schema_id)
88+
)
89+
8290
def set_constraints(self, constraints: List[Tuple[Tool, Tool]]) -> None:
8391
self.constraints = []
8492
for constraint in constraints:

libs/labelbox/tests/unit/test_unit_relationship_tool.py

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def test_basic_instantiation():
99
tool = RelationshipTool(name="Test Relationship Tool")
10-
10+
1111
assert tool.name == "Test Relationship Tool"
1212
assert tool.tool == Tool.Type.RELATIONSHIP
1313
assert tool.constraints is None
@@ -20,26 +20,23 @@ def test_basic_instantiation():
2020
def test_instantiation_with_constraints():
2121
constraints = [
2222
("source_id_1", "target_id_1"),
23-
("source_id_2", "target_id_2")
23+
("source_id_2", "target_id_2"),
2424
]
2525
tool = RelationshipTool(name="Test Tool", constraints=constraints)
26-
26+
2727
assert tool.name == "Test Tool"
2828
assert tool.constraints == constraints
2929
assert len(tool.constraints) == 2
3030

31+
3132
def test_post_init_sets_tool_type():
3233
tool = RelationshipTool(name="Test Tool")
3334
assert tool.tool == Tool.Type.RELATIONSHIP
3435

3536

3637
def test_asdict_without_constraints():
37-
tool = RelationshipTool(
38-
name="Test Tool",
39-
required=True,
40-
color="#FF0000"
41-
)
42-
38+
tool = RelationshipTool(name="Test Tool", required=True, color="#FF0000")
39+
4340
result = tool.asdict()
4441
expected = {
4542
"tool": "edge",
@@ -49,17 +46,18 @@ def test_asdict_without_constraints():
4946
"classifications": [],
5047
"schemaNodeId": None,
5148
"featureSchemaId": None,
52-
"attributes": None
49+
"attributes": None,
5350
}
54-
51+
5552
assert result == expected
5653

54+
5755
def test_asdict_with_constraints():
5856
constraints = [("source_id", "target_id")]
5957
tool = RelationshipTool(name="Test Tool", constraints=constraints)
60-
58+
6159
result = tool.asdict()
62-
60+
6361
assert "definition" in result
6462
assert result["definition"] == {"constraints": constraints}
6563
assert result["tool"] == "edge"
@@ -70,11 +68,11 @@ def test_add_constraint_to_empty_constraints():
7068
tool = RelationshipTool(name="Test Tool")
7169
start_tool = Tool(Tool.Type.BBOX, "Start Tool")
7270
end_tool = Tool(Tool.Type.POLYGON, "End Tool")
73-
74-
with patch('uuid.uuid4') as mock_uuid:
71+
72+
with patch("uuid.uuid4") as mock_uuid:
7573
mock_uuid.return_value.hex = "test-uuid"
7674
tool.add_constraint(start_tool, end_tool)
77-
75+
7876
assert tool.constraints is not None
7977
assert len(tool.constraints) == 1
8078
assert start_tool.feature_schema_id is not None
@@ -86,87 +84,108 @@ def test_add_constraint_to_empty_constraints():
8684
def test_add_constraint_to_existing_constraints():
8785
existing_constraints = [("existing_source", "existing_target")]
8886
tool = RelationshipTool(name="Test Tool", constraints=existing_constraints)
89-
87+
9088
start_tool = Tool(Tool.Type.BBOX, "Start Tool")
9189
end_tool = Tool(Tool.Type.POLYGON, "End Tool")
92-
90+
9391
tool.add_constraint(start_tool, end_tool)
94-
92+
9593
assert len(tool.constraints) == 2
9694
assert tool.constraints[0] == ("existing_source", "existing_target")
97-
assert tool.constraints[1] == (start_tool.feature_schema_id, end_tool.feature_schema_id)
95+
assert tool.constraints[1] == (
96+
start_tool.feature_schema_id,
97+
end_tool.feature_schema_id,
98+
)
9899

99100

100101
def test_add_constraint_preserves_existing_ids():
101102
tool = RelationshipTool(name="Test Tool")
102103
start_tool_feature_schema_id = "start_tool_feature_schema_id"
103104
start_tool_schema_id = "start_tool_schema_id"
104-
start_tool = Tool(Tool.Type.BBOX, "Start Tool", feature_schema_id=start_tool_feature_schema_id, schema_id=start_tool_schema_id)
105+
start_tool = Tool(
106+
Tool.Type.BBOX,
107+
"Start Tool",
108+
feature_schema_id=start_tool_feature_schema_id,
109+
schema_id=start_tool_schema_id,
110+
)
105111
end_tool_feature_schema_id = "end_tool_feature_schema_id"
106112
end_tool_schema_id = "end_tool_schema_id"
107-
end_tool = Tool(Tool.Type.POLYGON, "End Tool", feature_schema_id=end_tool_feature_schema_id, schema_id=end_tool_schema_id)
113+
end_tool = Tool(
114+
Tool.Type.POLYGON,
115+
"End Tool",
116+
feature_schema_id=end_tool_feature_schema_id,
117+
schema_id=end_tool_schema_id,
118+
)
108119

109120
tool.add_constraint(start_tool, end_tool)
110-
121+
111122
assert start_tool.feature_schema_id == start_tool_feature_schema_id
112123
assert start_tool.schema_id == start_tool_schema_id
113124
assert end_tool.feature_schema_id == end_tool_feature_schema_id
114125
assert end_tool.schema_id == end_tool_schema_id
115-
assert tool.constraints == [(start_tool_feature_schema_id, end_tool_feature_schema_id)]
126+
assert tool.constraints == [
127+
(start_tool_feature_schema_id, end_tool_feature_schema_id)
128+
]
116129

117130

118131
def test_set_constraints():
119132
tool = RelationshipTool(name="Test Tool")
120-
133+
121134
start_tool1 = Tool(Tool.Type.BBOX, "Start Tool 1")
122135
end_tool1 = Tool(Tool.Type.POLYGON, "End Tool 1")
123136
start_tool2 = Tool(Tool.Type.POINT, "Start Tool 2")
124137
end_tool2 = Tool(Tool.Type.LINE, "End Tool 2")
125-
126-
tool.set_constraints([
127-
(start_tool1, end_tool1),
128-
(start_tool2, end_tool2)
129-
])
130-
138+
139+
tool.set_constraints([(start_tool1, end_tool1), (start_tool2, end_tool2)])
140+
131141
assert len(tool.constraints) == 2
132-
assert tool.constraints[0] == (start_tool1.feature_schema_id, end_tool1.feature_schema_id)
133-
assert tool.constraints[1] == (start_tool2.feature_schema_id, end_tool2.feature_schema_id)
142+
assert tool.constraints[0] == (
143+
start_tool1.feature_schema_id,
144+
end_tool1.feature_schema_id,
145+
)
146+
assert tool.constraints[1] == (
147+
start_tool2.feature_schema_id,
148+
end_tool2.feature_schema_id,
149+
)
134150

135151

136152
def test_set_constraints_replaces_existing():
137153
existing_constraints = [("old_source", "old_target")]
138154
tool = RelationshipTool(name="Test Tool", constraints=existing_constraints)
139-
155+
140156
start_tool = Tool(Tool.Type.BBOX, "Start Tool")
141157
end_tool = Tool(Tool.Type.POLYGON, "End Tool")
142-
158+
143159
tool.set_constraints([(start_tool, end_tool)])
144-
160+
145161
assert len(tool.constraints) == 1
146162
assert tool.constraints[0] != ("old_source", "old_target")
147-
assert tool.constraints[0] == (start_tool.feature_schema_id, end_tool.feature_schema_id)
163+
assert tool.constraints[0] == (
164+
start_tool.feature_schema_id,
165+
end_tool.feature_schema_id,
166+
)
148167

149168

150169
def test_uuid_generation_in_add_constraint():
151170
tool = RelationshipTool(name="Test Tool")
152-
171+
153172
start_tool = Tool(Tool.Type.BBOX, "Start Tool")
154173
end_tool = Tool(Tool.Type.POLYGON, "End Tool")
155-
174+
156175
# Ensure tools don't have IDs initially
157176
assert start_tool.feature_schema_id is None
158177
assert start_tool.schema_id is None
159178
assert end_tool.feature_schema_id is None
160179
assert end_tool.schema_id is None
161-
180+
162181
tool.add_constraint(start_tool, end_tool)
163-
182+
164183
# Check that UUIDs were generated
165184
assert start_tool.feature_schema_id is not None
166185
assert start_tool.schema_id is not None
167186
assert end_tool.feature_schema_id is not None
168187
assert end_tool.schema_id is not None
169-
188+
170189
# Check that they are valid UUID strings
171190
uuid.UUID(start_tool.feature_schema_id) # Will raise ValueError if invalid
172191
uuid.UUID(start_tool.schema_id)
@@ -176,18 +195,18 @@ def test_uuid_generation_in_add_constraint():
176195

177196
def test_constraints_in_asdict():
178197
tool = RelationshipTool(name="Test Tool")
179-
198+
180199
start_tool = Tool(Tool.Type.BBOX, "Start Tool")
181200
end_tool = Tool(Tool.Type.POLYGON, "End Tool")
182-
201+
183202
tool.add_constraint(start_tool, end_tool)
184-
203+
185204
result = tool.asdict()
186-
205+
187206
assert "definition" in result
188207
assert "constraints" in result["definition"]
189208
assert len(result["definition"]["constraints"]) == 1
190209
assert result["definition"]["constraints"][0] == (
191210
start_tool.feature_schema_id,
192-
end_tool.feature_schema_id
211+
end_tool.feature_schema_id,
193212
)

0 commit comments

Comments
 (0)