Skip to content

Commit 40fce4f

Browse files
authored
Recover commented out code in tests and mark with pytest.mark.skip instead (#4027)
* recover some commented out test unit * replace legacy random generator * recover more commented out test * avoid code-like comment in case we want to enable ERA someday
1 parent c06abf1 commit 40fce4f

File tree

13 files changed

+559
-529
lines changed

13 files changed

+559
-529
lines changed

tests/analysis/chemenv/coordination_environments/test_coordination_geometry_finder.py

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from __future__ import annotations
22

3+
import json
4+
import os
5+
36
import numpy as np
47
import pytest
58
from numpy.testing import assert_allclose
69
from pytest import approx
710

11+
from pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies import (
12+
SimpleAbundanceChemenvStrategy,
13+
SimplestChemenvStrategy,
14+
)
815
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import AllCoordinationGeometries
916
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import (
1017
AbstractGeometry,
@@ -27,7 +34,7 @@ def setUp(self):
2734
structure_refinement=self.lgf.STRUCTURE_REFINEMENT_NONE,
2835
)
2936

30-
# self.strategies = [SimplestChemenvStrategy(), SimpleAbundanceChemenvStrategy()]
37+
# self.strategies = [SimplestChemenvStrategy(), SimpleAbundanceChemenvStrategy()]
3138

3239
def test_abstract_geometry(self):
3340
cg_ts3 = self.lgf.allcg["TS:3"]
@@ -117,45 +124,47 @@ def test_abstract_geometry(self):
117124
for perm_csm_dict in permutations_symmetry_measures:
118125
assert perm_csm_dict["symmetry_measure"] == approx(0.140355832317)
119126

120-
# def _strategy_test(self, strategy):
121-
# files = []
122-
# for _dirpath, _dirnames, filenames in os.walk(json_dir):
123-
# files.extend(filenames)
124-
# break
125-
126-
# for _ifile, json_file in enumerate(files):
127-
# with self.subTest(json_file=json_file):
128-
# with open(f"{json_dir}/{json_file}") as file:
129-
# dct = json.load(file)
130-
131-
# atom_indices = dct["atom_indices"]
132-
# expected_geoms = dct["expected_geoms"]
133-
134-
# struct = Structure.from_dict(dct["structure"])
135-
136-
# struct = self.lgf.setup_structure(struct)
137-
# se = self.lgf.compute_structure_environments_detailed_voronoi(
138-
# only_indices=atom_indices, maximum_distance_factor=1.5
139-
# )
140-
141-
# # All strategies should get the correct environment with their default parameters
142-
# strategy.set_structure_environments(se)
143-
# for ienv, isite in enumerate(atom_indices):
144-
# ce = strategy.get_site_coordination_environment(struct[isite])
145-
# try:
146-
# coord_env = ce[0]
147-
# except TypeError:
148-
# coord_env = ce
149-
# # Check that the environment found is the expected one
150-
# assert coord_env == expected_geoms[ienv]
151-
152-
# def test_simplest_chemenv_strategy(self):
153-
# strategy = SimplestChemenvStrategy()
154-
# self._strategy_test(strategy)
155-
156-
# def test_simple_abundance_chemenv_strategy(self):
157-
# strategy = SimpleAbundanceChemenvStrategy()
158-
# self._strategy_test(strategy)
127+
def _strategy_test(self, strategy):
128+
files = []
129+
for _dirpath, _dirnames, filenames in os.walk(json_dir):
130+
files.extend(filenames)
131+
break
132+
133+
for _ifile, json_file in enumerate(files):
134+
with self.subTest(json_file=json_file):
135+
with open(f"{json_dir}/{json_file}") as file:
136+
dct = json.load(file)
137+
138+
atom_indices = dct["atom_indices"]
139+
expected_geoms = dct["expected_geoms"]
140+
141+
struct = Structure.from_dict(dct["structure"])
142+
143+
struct = self.lgf.setup_structure(struct)
144+
se = self.lgf.compute_structure_environments_detailed_voronoi(
145+
only_indices=atom_indices, maximum_distance_factor=1.5
146+
)
147+
148+
# All strategies should get the correct environment with their default parameters
149+
strategy.set_structure_environments(se)
150+
for ienv, isite in enumerate(atom_indices):
151+
ce = strategy.get_site_coordination_environment(struct[isite])
152+
try:
153+
coord_env = ce[0]
154+
except TypeError:
155+
coord_env = ce
156+
# Check that the environment found is the expected one
157+
assert coord_env == expected_geoms[ienv]
158+
159+
@pytest.mark.skip("TODO: need someone to fix this")
160+
def test_simplest_chemenv_strategy(self):
161+
strategy = SimplestChemenvStrategy()
162+
self._strategy_test(strategy)
163+
164+
@pytest.mark.skip("TODO: need someone to fix this")
165+
def test_simple_abundance_chemenv_strategy(self):
166+
strategy = SimpleAbundanceChemenvStrategy()
167+
self._strategy_test(strategy)
159168

160169
def test_perfect_environments(self):
161170
allcg = AllCoordinationGeometries()

tests/analysis/test_molecule_structure_comparator.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
from unittest import TestCase
44

5+
import pytest
6+
57
from pymatgen.analysis.molecule_structure_comparator import MoleculeStructureComparator
68
from pymatgen.core.structure import Molecule
9+
from pymatgen.io.qchem.outputs import QCOutput
710
from pymatgen.util.testing import TEST_FILES_DIR
811

912
__author__ = "xiaohuiqu"
@@ -129,14 +132,15 @@ def test_to_and_from_dict(self):
129132
d2 = MoleculeStructureComparator.from_dict(d1).as_dict()
130133
assert d1 == d2
131134

132-
# def test_structural_change_in_geom_opt(self):
133-
# qcout_path = f"{TEST_DIR}/mol_1_3_bond.qcout"
134-
# qcout = QcOutput(qcout_path)
135-
# mol1 = qcout.data[0]["molecules"][0]
136-
# mol2 = qcout.data[0]["molecules"][-1]
137-
# priority_bonds = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 7], [2, 5], [2, 6], [2, 8], [4, 6], [4, 10], [6, 9]]
138-
# msc = MoleculeStructureComparator(priority_bonds=priority_bonds)
139-
# assert msc.are_equal(mol1, mol2)
135+
@pytest.mark.skip("TODO: need someone to fix this")
136+
def test_structural_change_in_geom_opt(self):
137+
qcout_path = f"{TEST_DIR}/mol_1_3_bond.qcout"
138+
qcout = QCOutput(qcout_path)
139+
mol1 = qcout.data[0]["molecules"][0]
140+
mol2 = qcout.data[0]["molecules"][-1]
141+
priority_bonds = [[0, 1], [0, 2], [1, 3], [1, 4], [1, 7], [2, 5], [2, 6], [2, 8], [4, 6], [4, 10], [6, 9]]
142+
msc = MoleculeStructureComparator(priority_bonds=priority_bonds)
143+
assert msc.are_equal(mol1, mol2)
140144

141145
def test_get_13_bonds(self):
142146
priority_bonds = [

tests/analysis/test_surface_analysis.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44

5+
import pytest
56
from numpy.testing import assert_allclose
67
from pytest import approx
78
from sympy import Number, Symbol
@@ -248,41 +249,43 @@ def test_entry_dict_from_list(self):
248249
surf_ene_plotter = SurfaceEnergyPlotter(all_Pt_slab_entries, self.Pt_analyzer.ucell_entry)
249250
assert surf_ene_plotter.list_of_chempots == self.Pt_analyzer.list_of_chempots
250251

251-
# def test_monolayer_vs_BE(self):
252-
# for el in self.Oads_analyzer_dict:
253-
# # Test WulffShape for adsorbed surfaces
254-
# analyzer = self.Oads_analyzer_dict[el]
255-
# plt = analyzer.monolayer_vs_BE()
256-
#
257-
# def test_area_frac_vs_chempot_plot(self):
258-
#
259-
# for el in self.Oads_analyzer_dict:
260-
# # Test WulffShape for adsorbed surfaces
261-
# analyzer = self.Oads_analyzer_dict[el]
262-
# plt = analyzer.area_frac_vs_chempot_plot(x_is_u_ads=True)
263-
#
264-
# def test_chempot_vs_gamma_clean(self):
265-
#
266-
# plt = self.Cu_analyzer.chempot_vs_gamma_clean()
267-
# for el in self.Oads_analyzer_dict:
268-
# # Test WulffShape for adsorbed surfaces
269-
# analyzer = self.Oads_analyzer_dict[el]
270-
# plt = analyzer.chempot_vs_gamma_clean(x_is_u_ads=True)
271-
#
272-
# def test_chempot_vs_gamma_facet(self):
273-
#
274-
# for el, val in self.metals_O_entry_dict.items():
275-
# for hkl in val:
276-
# # Test WulffShape for adsorbed surfaces
277-
# analyzer = self.Oads_analyzer_dict[el]
278-
# plt = analyzer.chempot_vs_gamma_facet(hkl)
279-
# def test_surface_chempot_range_map(self):
280-
#
281-
# for el, val in self.metals_O_entry_dict.items():
282-
# for hkl in val:
283-
# # Test WulffShape for adsorbed surfaces
284-
# analyzer = self.Oads_analyzer_dict[el]
285-
# plt = analyzer.chempot_vs_gamma_facet(hkl)
252+
@pytest.mark.skip("TODO: need someone to fix this")
253+
def test_monolayer_vs_BE(self):
254+
for el in self.Oads_analyzer_dict:
255+
# Test WulffShape for adsorbed surfaces
256+
analyzer = self.Oads_analyzer_dict[el]
257+
analyzer.monolayer_vs_BE()
258+
259+
@pytest.mark.skip("TODO: need someone to fix this")
260+
def test_area_frac_vs_chempot_plot(self):
261+
for el in self.Oads_analyzer_dict:
262+
# Test WulffShape for adsorbed surfaces
263+
analyzer = self.Oads_analyzer_dict[el]
264+
analyzer.area_frac_vs_chempot_plot(x_is_u_ads=True)
265+
266+
@pytest.mark.skip("TODO: need someone to fix this")
267+
def test_chempot_vs_gamma_clean(self):
268+
self.Cu_analyzer.chempot_vs_gamma_clean()
269+
for el in self.Oads_analyzer_dict:
270+
# Test WulffShape for adsorbed surfaces
271+
analyzer = self.Oads_analyzer_dict[el]
272+
analyzer.chempot_vs_gamma_clean(x_is_u_ads=True)
273+
274+
@pytest.mark.skip("TODO: need someone to fix this")
275+
def test_chempot_vs_gamma_facet(self):
276+
for el, val in self.metals_O_entry_dict.items():
277+
for hkl in val:
278+
# Test WulffShape for adsorbed surfaces
279+
analyzer = self.Oads_analyzer_dict[el]
280+
analyzer.chempot_vs_gamma_facet(hkl)
281+
282+
@pytest.mark.skip("TODO: need someone to fix this")
283+
def test_surface_chempot_range_map(self):
284+
for el, val in self.metals_O_entry_dict.items():
285+
for hkl in val:
286+
# Test WulffShape for adsorbed surfaces
287+
analyzer = self.Oads_analyzer_dict[el]
288+
analyzer.chempot_vs_gamma_facet(hkl)
286289

287290

288291
class TestWorkFunctionAnalyzer(PymatgenTest):

tests/command_line/test_critic2_caller.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ def setUp(self):
9090
self.c2o_new_format = Critic2Analysis(structure, reference_stdout_new_format)
9191

9292
def test_to_from_dict(self):
93+
"""
94+
reference dictionary for c2o.critical_points[0].as_dict()
95+
{'@class': 'CriticalPoint',
96+
'@module': 'pymatgen.command_line.critic2_caller',
97+
'coords': None,
98+
'field': 93848.0413,
99+
'field_gradient': 0.0,
100+
'field_hessian': [[-2593274446000.0, -3.873587547e-19, -1.704530713e-08],
101+
[-3.873587547e-19, -2593274446000.0, 1.386877485e-18],
102+
[-1.704530713e-08, 1.386877485e-18, -2593274446000.0]],
103+
'frac_coords': [0.333333, 0.666667, 0.213295],
104+
'index': 0,
105+
'multiplicity': 1.0,
106+
'point_group': 'D3h',
107+
'type': < CriticalPointType.nucleus: 'nucleus' >}
108+
"""
93109
assert len(self.c2o.critical_points) == 6
94110
assert len(self.c2o.nodes) == 14
95111
assert len(self.c2o.edges) == 10
@@ -98,21 +114,6 @@ def test_to_from_dict(self):
98114
assert len(self.c2o_new_format.nodes) == 14
99115
assert len(self.c2o_new_format.edges) == 10
100116

101-
# reference dictionary for c2o.critical_points[0].as_dict()
102-
# {'@class': 'CriticalPoint',
103-
# '@module': 'pymatgen.command_line.critic2_caller',
104-
# 'coords': None,
105-
# 'field': 93848.0413,
106-
# 'field_gradient': 0.0,
107-
# 'field_hessian': [[-2593274446000.0, -3.873587547e-19, -1.704530713e-08],
108-
# [-3.873587547e-19, -2593274446000.0, 1.386877485e-18],
109-
# [-1.704530713e-08, 1.386877485e-18, -2593274446000.0]],
110-
# 'frac_coords': [0.333333, 0.666667, 0.213295],
111-
# 'index': 0,
112-
# 'multiplicity': 1.0,
113-
# 'point_group': 'D3h',
114-
# 'type': < CriticalPointType.nucleus: 'nucleus' >}
115-
116117
assert str(self.c2o.critical_points[0].type) == "CriticalPointType.nucleus"
117118

118119
# test connectivity

0 commit comments

Comments
 (0)