Skip to content

Commit 2ca5798

Browse files
committed
fix test order dependence in pymatgen/analysis/tests/test_graphs.py
seems to have been caused by test_edge_editing(), now using deep copy instead in-place edit
1 parent 52ffbc6 commit 2ca5798

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

pymatgen/analysis/tests/test_graphs.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,7 @@ def setUp(self):
528528
self.cyclohexene.add_edge(5, 14, weight=1.0)
529529
self.cyclohexene.add_edge(5, 15, weight=1.0)
530530

531-
butadiene = Molecule.from_file(
532-
os.path.join(
533-
PymatgenTest.TEST_FILES_DIR,
534-
"graphs/butadiene.xyz",
535-
)
536-
)
531+
butadiene = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs/butadiene.xyz"))
537532
self.butadiene = MoleculeGraph.with_empty_graph(butadiene, edge_weight_name="strength", edge_weight_units="")
538533
self.butadiene.add_edge(0, 1, weight=2.0)
539534
self.butadiene.add_edge(1, 2, weight=1.0)
@@ -545,12 +540,7 @@ def setUp(self):
545540
self.butadiene.add_edge(3, 8, weight=1.0)
546541
self.butadiene.add_edge(3, 9, weight=1.0)
547542

548-
ethylene = Molecule.from_file(
549-
os.path.join(
550-
PymatgenTest.TEST_FILES_DIR,
551-
"graphs/ethylene.xyz",
552-
)
553-
)
543+
ethylene = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs/ethylene.xyz"))
554544
self.ethylene = MoleculeGraph.with_empty_graph(ethylene, edge_weight_name="strength", edge_weight_units="")
555545
self.ethylene.add_edge(0, 1, weight=2.0)
556546
self.ethylene.add_edge(0, 2, weight=1.0)
@@ -669,16 +659,17 @@ def test_coordination(self):
669659
assert self.cyclohexene.get_coordination_of_site(0) == 4
670660

671661
def test_edge_editing(self):
672-
self.cyclohexene.alter_edge(0, 1, new_weight=0.0, new_edge_properties={"foo": "bar"})
673-
new_edge = self.cyclohexene.graph.get_edge_data(0, 1)[0]
662+
cyclohexene = copy.deepcopy(self.cyclohexene)
663+
cyclohexene.alter_edge(0, 1, new_weight=0.0, new_edge_properties={"foo": "bar"})
664+
new_edge = cyclohexene.graph.get_edge_data(0, 1)[0]
674665
assert new_edge["weight"] == 0.0
675666
assert new_edge["foo"] == "bar"
676667

677-
self.cyclohexene.break_edge(0, 1)
678-
assert self.cyclohexene.graph.get_edge_data(0, 1) is None
668+
cyclohexene.break_edge(0, 1)
669+
assert cyclohexene.graph.get_edge_data(0, 1) is None
679670

680671
# Replace the now-broken edge
681-
self.cyclohexene.add_edge(0, 1, weight=1.0)
672+
cyclohexene.add_edge(0, 1, weight=1.0)
682673

683674
def test_insert_remove(self):
684675
mol_copy = copy.deepcopy(self.ethylene.molecule)

0 commit comments

Comments
 (0)