Skip to content

Commit 3c7cb66

Browse files
authored
Merge pull request #823 from LalatenduMohanty/fix_types_in_test_graph
test(graph): fix constraint tests for Requirement objects
2 parents 5503c28 + 7d8dbf0 commit 3c7cb66

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

tests/test_graph.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ def test_graph_add_dependency_with_constraint() -> None:
161161
req=Requirement("package-a>=1.0"),
162162
req_version=Version("2.0"),
163163
download_url="url",
164-
constraint="package-a>=1.0,<3.0",
164+
constraint=Requirement("package-a>=1.0,<3.0"),
165165
)
166166

167167
# Verify constraint is stored
168168
node = graph.nodes["package-a==2.0"]
169-
assert node.constraint == "package-a>=1.0,<3.0"
169+
assert node.constraint is not None
170+
assert str(node.constraint) == "package-a<3.0,>=1.0"
170171

171172
# Add child dependency with its own constraint
172173
graph.add_dependency(
@@ -176,12 +177,13 @@ def test_graph_add_dependency_with_constraint() -> None:
176177
req=Requirement("package-b>=2.0"),
177178
req_version=Version("2.5.0"),
178179
download_url="url-b",
179-
constraint="package-b>=2.0,<3.0",
180+
constraint=Requirement("package-b>=2.0,<3.0"),
180181
)
181182

182183
# Verify child constraint is stored
183184
child_node = graph.nodes["package-b==2.5.0"]
184-
assert child_node.constraint == "package-b>=2.0,<3.0"
185+
assert child_node.constraint is not None
186+
assert str(child_node.constraint) == "package-b<3.0,>=2.0"
185187

186188

187189
def test_graph_constraint_serialization() -> None:
@@ -196,7 +198,7 @@ def test_graph_constraint_serialization() -> None:
196198
req=Requirement("pkg-with-constraint"),
197199
req_version=Version("1.5.0"),
198200
download_url="url",
199-
constraint="pkg-with-constraint>=1.0,<2.0",
201+
constraint=Requirement("pkg-with-constraint>=1.0,<2.0"),
200202
)
201203

202204
graph.add_dependency(
@@ -206,7 +208,7 @@ def test_graph_constraint_serialization() -> None:
206208
req=Requirement("dependency-pkg"),
207209
req_version=Version("3.0.0"),
208210
download_url="url-dep",
209-
constraint="dependency-pkg==3.0.0",
211+
constraint=Requirement("dependency-pkg==3.0.0"),
210212
)
211213

212214
# Add dependency without constraint
@@ -225,14 +227,16 @@ def test_graph_constraint_serialization() -> None:
225227

226228
# Verify constraints are preserved
227229
node1 = restored_graph.nodes["pkg-with-constraint==1.5.0"]
228-
assert node1.constraint == "pkg-with-constraint>=1.0,<2.0"
230+
assert node1.constraint is not None
231+
assert str(node1.constraint) == "pkg-with-constraint<2.0,>=1.0"
229232

230233
node2 = restored_graph.nodes["dependency-pkg==3.0.0"]
231-
assert node2.constraint == "dependency-pkg==3.0.0"
234+
assert node2.constraint is not None
235+
assert str(node2.constraint) == "dependency-pkg==3.0.0"
232236

233-
# Verify empty constraint is preserved
237+
# Verify None constraint is preserved
234238
node3 = restored_graph.nodes["build-pkg==1.0.0"]
235-
assert node3.constraint == ""
239+
assert node3.constraint is None
236240

237241

238242
def test_graph_duplicate_node_constraint_behavior() -> None:
@@ -251,7 +255,7 @@ def test_graph_duplicate_node_constraint_behavior() -> None:
251255
req=Requirement("shared-pkg>=1.0"),
252256
req_version=Version("2.0"),
253257
download_url="url1",
254-
constraint="shared-pkg>=1.0,<3.0",
258+
constraint=Requirement("shared-pkg>=1.0,<3.0"),
255259
)
256260

257261
# Add another toplevel
@@ -272,12 +276,13 @@ def test_graph_duplicate_node_constraint_behavior() -> None:
272276
req=Requirement("shared-pkg>=2.0"),
273277
req_version=Version("2.0"),
274278
download_url="url1",
275-
constraint="shared-pkg>=2.0,<4.0", # Different constraint
279+
constraint=Requirement("shared-pkg>=2.0,<4.0"), # Different constraint
276280
)
277281

278282
# The first constraint should be retained (existing node is reused)
279283
node = graph.nodes["shared-pkg==2.0"]
280-
assert node.constraint == "shared-pkg>=1.0,<3.0"
284+
assert node.constraint is not None
285+
assert str(node.constraint) == "shared-pkg<3.0,>=1.0"
281286

282287
# Verify both parents exist
283288
assert len(node.parents) == 2
@@ -294,14 +299,14 @@ def test_graph_constraint_in_to_dict() -> None:
294299
req=Requirement("test-pkg"),
295300
req_version=Version("1.0.0"),
296301
download_url="https://example.com/test-pkg.tar.gz",
297-
constraint="test-pkg>=1.0,<2.0",
302+
constraint=Requirement("test-pkg>=1.0,<2.0"),
298303
)
299304

300305
graph_dict = graph._to_dict()
301306

302-
# Verify constraint is in the serialized format
307+
# Verify constraint is in the serialized format (as string in JSON)
303308
assert "test-pkg==1.0.0" in graph_dict
304-
assert graph_dict["test-pkg==1.0.0"]["constraint"] == "test-pkg>=1.0,<2.0"
309+
assert graph_dict["test-pkg==1.0.0"]["constraint"] == "test-pkg<2.0,>=1.0"
305310

306311

307312
def test_cycles_get_install_dependencies() -> None:

0 commit comments

Comments
 (0)