77
88def 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():
2020def 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+
3132def test_post_init_sets_tool_type ():
3233 tool = RelationshipTool (name = "Test Tool" )
3334 assert tool .tool == Tool .Type .RELATIONSHIP
3435
3536
3637def 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+
5755def 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():
8684def 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
100101def 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
118131def 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
136152def 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
150169def 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
177196def 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