Skip to content

Commit dc995f7

Browse files
dlarendtryan.danehy@pnnl.gov
authored andcommitted
This test is occasionally failing when checking the id of the new hypergraph against the original. This is potentially due to the original getting garbage collected and the new new hypergraph being assigned to the original. The test was rewritten to prevent garbage collecting the original hg in the test.
1 parent ff514c8 commit dc995f7

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

tests/classes/test_hypergraph.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -978,45 +978,44 @@ def test_remove_edges_nodes_incidences_inplace(triloop2):
978978
def test_remove_edges_nodes_incidences_not_inplace(triloop2):
979979
# triloop2 is a hypergraph of the following shape:
980980
# {AB: {A, B}, BC: {B, C}, ACD: {A, C, D, E}, ACD2: {A, C, D, E}}
981-
hg = Hypergraph(triloop2.edgedict, name=triloop2.name)
981+
original_hg = hg = Hypergraph(triloop2.edgedict, name=triloop2.name)
982982
assert hg.shape == (5, 4)
983-
original_hg_id = id(hg)
984983
original_hg_name = hg.name
985984
new_name = f"{triloop2.name}_new"
986985

987986
# removing a duplicate edge should not affect the number of nodes
988987
duplicate_edge = ["ACD2"]
989988
hg = hg.remove_edges(duplicate_edge, name=new_name, inplace=False)
990989
assert hg.shape == (5, 3)
991-
assert id(hg) != original_hg_id
990+
assert id(hg) != id(original_hg)
992991
assert hg.name != original_hg_name
993992
assert hg.name == new_name
994993

995994
# number of nodes should drop by 1
996995
hg = hg.remove_nodes(["E"], name=new_name, inplace=False)
997996
assert hg.shape == (4, 3)
998-
assert id(hg) != original_hg_id
997+
assert id(hg) != id(original_hg)
999998
assert hg.name != original_hg_name
1000999
assert hg.name == new_name
10011000

10021001
# number of edges should drop by 1
10031002
hg = hg.remove_edges(["ACD"], name=new_name, inplace=False)
10041003
assert hg.shape == (3, 2)
1005-
assert id(hg) != original_hg_id
1004+
assert id(hg) != id(original_hg)
10061005
assert hg.name != original_hg_name
10071006
assert hg.name == new_name
10081007

10091008
# remove an incidence that no longer exists; no change
10101009
hg = hg.remove_incidences([("ACD", "E")], name=new_name, inplace=False)
10111010
assert hg.shape == (3, 2)
1012-
assert id(hg) != original_hg_id
1011+
assert id(hg) != id(original_hg)
10131012
assert hg.name != original_hg_name
10141013
assert hg.name == new_name
10151014

10161015
# removing the last two remaining edges will remove all the nodes from the hypergraph
10171016
hg = hg.remove_edges(["AB", "BC"], name=new_name, inplace=False)
10181017
assert hg.shape == (0, 0)
1019-
assert id(hg) != original_hg_id
1018+
assert id(hg) != id(original_hg)
10201019
assert hg.name != original_hg_name
10211020
assert hg.name == new_name
10221021

0 commit comments

Comments
 (0)