Skip to content

Commit 461d3e5

Browse files
committed
update all the python tests for new api
1 parent 2cf6f54 commit 461d3e5

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

python/tests/test_algorithms.py

+22-26
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_page_rank():
304304
"7": 0.14074777909144864,
305305
"8": 0.11786468661230831,
306306
}
307-
assert actual.get_all_with_names() == expected
307+
assert actual == expected
308308

309309

310310
def test_temporal_reachability():
@@ -326,7 +326,7 @@ def test_temporal_reachability():
326326
"8": [],
327327
}
328328

329-
assert actual.get_all_with_names() == expected
329+
assert actual == expected
330330

331331

332332
def test_degree_centrality():
@@ -339,7 +339,7 @@ def test_degree_centrality():
339339
g.add_edge(0, 1, 4, {})
340340
g.add_edge(0, 2, 3, {})
341341
g.add_edge(0, 2, 4, {})
342-
assert degree_centrality(g).get_all_with_names() == {
342+
assert degree_centrality(g) == {
343343
"1": 1.0,
344344
"2": 1.0,
345345
"3": 2 / 3,
@@ -374,17 +374,15 @@ def test_single_source_shortest_path():
374374
g.add_edge(0, 2, 4, {})
375375
res_one = single_source_shortest_path(g, 1, 1)
376376
res_two = single_source_shortest_path(g, 1, 2)
377-
assert res_one.get_all_with_names() == {
377+
assert res_one == {
378378
"1": ["1"],
379379
"2": ["1", "2"],
380380
"4": ["1", "4"],
381381
}
382382
assert (
383-
res_two.get_all_with_names()
384-
== {"1": ["1"], "2": ["1", "2"], "3": ["1", "2", "3"], "4": ["1", "4"]}
383+
res_two == {"1": ["1"], "2": ["1", "2"], "3": ["1", "2", "3"], "4": ["1", "4"]}
385384
) or (
386-
res_two.get_all_with_names()
387-
== {"1": ["1"], "3": ["1", "4", "3"], "2": ["1", "2"], "4": ["1", "4"]}
385+
res_two == {"1": ["1"], "3": ["1", "4", "3"], "2": ["1", "2"], "4": ["1", "4"]}
388386
)
389387

390388

@@ -404,19 +402,19 @@ def test_dijsktra_shortest_paths():
404402
res_one = dijkstra_single_source_shortest_paths(g, "A", ["F"])
405403
res_two = dijkstra_single_source_shortest_paths(g, "B", ["D", "E", "F"])
406404
assert res_one.get("F")[0] == 8.0
407-
assert res_one.get("F")[1] == ["A", "C", "E", "F"]
405+
assert res_one.get("F")[1].name == ["A", "C", "E", "F"]
408406
assert res_two.get("D")[0] == 5.0
409407
assert res_two.get("F")[0] == 6.0
410-
assert res_two.get("D")[1] == ["B", "C", "D"]
411-
assert res_two.get("F")[1] == ["B", "C", "E", "F"]
408+
assert res_two.get("D")[1].name == ["B", "C", "D"]
409+
assert res_two.get("F")[1].name == ["B", "C", "E", "F"]
412410

413-
with pytest.raises(ValueError) as excinfo:
411+
with pytest.raises(Exception) as excinfo:
414412
dijkstra_single_source_shortest_paths(g, "HH", ["F"])
415-
assert "Source node not found" in str(excinfo.value)
413+
assert "Node HH does not exist" in str(excinfo.value)
416414

417-
with pytest.raises(ValueError) as excinfo:
415+
with pytest.raises(Exception) as excinfo:
418416
dijkstra_single_source_shortest_paths(g, "A", ["F"], weight="NO")
419-
assert "Weight property not found on edges" in str(excinfo.value)
417+
assert "Property NO does not exist" in str(excinfo.value)
420418

421419

422420
def test_betweenness_centrality():
@@ -442,7 +440,7 @@ def test_betweenness_centrality():
442440
g.add_edge(0, e[0], e[1], {})
443441

444442
res = betweenness_centrality(g, normalized=False)
445-
assert res.get_all_with_names() == {
443+
assert res == {
446444
"0": 0.0,
447445
"1": 1.0,
448446
"2": 4.0,
@@ -452,7 +450,7 @@ def test_betweenness_centrality():
452450
}
453451

454452
res = betweenness_centrality(g, normalized=True)
455-
assert res.get_all_with_names() == {
453+
assert res == {
456454
"0": 0.0,
457455
"1": 0.05,
458456
"2": 0.2,
@@ -484,13 +482,13 @@ def test_balance_algorithm():
484482
]
485483
for src, dst, val, time in edges_str:
486484
g.add_edge(time, src, dst, {"value_dec": val})
487-
result = algorithms.balance(g, "value_dec", "both", None).get_all_with_names()
485+
result = algorithms.balance(g, "value_dec", "both")
488486
assert result == {"1": -26.0, "2": 7.0, "3": 12.0, "4": 5.0, "5": 2.0}
489487

490-
result = algorithms.balance(g, "value_dec", "in", None).get_all_with_names()
488+
result = algorithms.balance(g, "value_dec", "in")
491489
assert result == {"1": 6.0, "2": 12.0, "3": 15.0, "4": 20.0, "5": 2.0}
492490

493-
result = algorithms.balance(g, "value_dec", "out", None).get_all_with_names()
491+
result = algorithms.balance(g, "value_dec", "out")
494492
assert result == {"1": -32.0, "2": -5.0, "3": -3.0, "4": -15.0, "5": 0.0}
495493

496494

@@ -530,13 +528,11 @@ def test_temporal_SEIR():
530528
g.add_edge(4, 4, 5)
531529
# Should be seeded with 2 vertices
532530
res = algorithms.temporal_SEIR(g, 2, 1.0, 0, rng_seed=1)
533-
seeded = [v for v in res.get_all_values() if v.infected == 0]
531+
seeded = [v for v in res.values() if v.infected == 0]
534532
assert len(seeded) == 2
535533

536-
res = algorithms.temporal_SEIR(g, [1], 1.0, 0, rng_seed=1).sort_by_value(
537-
reverse=False
538-
)
539-
for i, (n, v) in enumerate(res):
534+
res = algorithms.temporal_SEIR(g, [1], 1.0, 0, rng_seed=1).sorted(reverse=False)
535+
for i, (n, v) in enumerate(res.items()):
540536
assert n == g.node(i + 1)
541537
assert v.infected == i
542538

@@ -584,7 +580,7 @@ def test_fast_rp():
584580
for src, dst, ts in edges:
585581
g.add_edge(ts, src, dst)
586582

587-
result = algorithms.fast_rp(g, 16, 1.0, [1.0, 1.0], 42).get_all_with_names()
583+
result = algorithms.fast_rp(g, 16, 1.0, [1.0, 1.0], 42)
588584
baseline = {
589585
"7": [
590586
0.0,

python/tests/test_graphdb/test_disk_graph.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ def test_disk_graph():
126126
20,
127127
print_result=False,
128128
)
129-
assert len(list(actual.get_all_with_names())) == 1624
129+
assert len(list(actual)) == 1624
130130

131131
# Doesn't work yet (was silently running on only the first layer before but now actually panics because of lack of multilayer edge views)
132132
# actual = measure("Weakly CC", algorithms.weakly_connected_components, g, 20, print_result=False)
133-
# assert len(list(actual.get_all_with_names())) == 1624
133+
# assert len(list(actual)) == 1624
134134

135135
actual = measure(
136136
"Page Rank", algorithms.pagerank, g.layer("netflow"), 100, print_result=False
137137
)
138-
assert len(list(actual.get_all_with_names())) == 1624
138+
assert len(list(actual)) == 1624
139139

140140

141141
def test_disk_graph_type_filter():

0 commit comments

Comments
 (0)