Skip to content

Commit 6327b07

Browse files
authored
Merge pull request #784 from hackingmaterials/del-unittest-main
Delete `if __name__ == "__main__": unittest.main()`
2 parents e478072 + a80f3f2 commit 6327b07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+90
-252
lines changed

atomate/common/firetasks/tests/test_glue_tasks.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
from fireworks import Firework, Workflow
54
from fireworks.core.rocket_launcher import rapidfire
@@ -323,7 +322,3 @@ def test_copyfilesfromcalcloc(self):
323322
self.assertTrue(
324323
os.path.exists(get_calc_loc("fw3", calc_locs)["path"] + "/POSCAR_1")
325324
)
326-
327-
328-
if __name__ == "__main__":
329-
unittest.main()

atomate/common/firetasks/tests/test_parse_outputs.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
from fireworks import Firework, Workflow
54
from fireworks.core.rocket_launcher import rapidfire
@@ -49,7 +48,3 @@ def test_ToDbTask(self):
4948
self.assertEqual(task1["task_id"], 1)
5049
self.assertEqual(task1["dir_name"], "/test")
5150
self.assertEqual(task1["drone"], "Test Drone")
52-
53-
54-
if __name__ == "__main__":
55-
unittest.main()

atomate/common/tests/test_powerups.py

-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def test_set_queue_adapter(self):
140140
self.assertDictEqual(wf.id_fw[-3].spec, {})
141141

142142
def test_add_additional_fields_to_taskdocs(self):
143-
144143
my_wf = copy_wf(self.bsboltz_wf)
145144
meta_dict = {"foo": "bar", "baz": 42}
146145
my_wf = add_additional_fields_to_taskdocs(my_wf, meta_dict)
@@ -172,7 +171,3 @@ def test_add_metadata(self):
172171

173172
def copy_wf(wf):
174173
return Workflow.from_dict(wf.to_dict())
175-
176-
177-
if __name__ == "__main__":
178-
unittest.main()

atomate/feff/firetasks/tests/test_tasks.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32
from glob import glob
43

54
from pymatgen.core import Structure
@@ -39,7 +38,3 @@ def test_write_paths_task(self):
3938
t.run_task({})
4039
with open("paths_answer.dat") as answer, open("paths.dat") as tmp:
4140
self.assertEqual(answer.readlines(), tmp.readlines())
42-
43-
44-
if __name__ == "__main__":
45-
unittest.main()

atomate/feff/fireworks/tests/test_fireworks.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
from pymatgen.core import Structure
54

@@ -32,7 +31,3 @@ def test_exafs_paths_fw(self):
3231
"{{atomate.feff.firetasks.parse_outputs.AddPathsToFilepadTask}}",
3332
]
3433
self.assertEqual(answer, [ft["_fw_name"] for ft in fw_dict["spec"]["_tasks"]])
35-
36-
37-
if __name__ == "__main__":
38-
unittest.main()

atomate/feff/workflows/tests/test_eels_workflows.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
from fireworks.core.fworker import FWorker
54
from fireworks.core.rocket_launcher import rapidfire
@@ -122,7 +121,3 @@ def _check_run(self, d):
122121
self.assertEqual(d["absorbing_atom"], self.absorbing_atom)
123122
tags = Tags.from_file(os.path.join(run_dir, "feff.inp"))
124123
self.assertEqual(d["input_parameters"], tags.as_dict())
125-
126-
127-
if __name__ == "__main__":
128-
unittest.main()

atomate/feff/workflows/tests/test_exafs_scattering_paths.py

-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,3 @@ def test_feff_input_sets(self):
6565
def test_paths(self):
6666
paths = [[249, 0], [85, 0]]
6767
self.assertEqual(paths, self.fw2_dict["spec"]["_tasks"][2]["paths"])
68-
69-
70-
if __name__ == "__main__":
71-
unittest.main()

atomate/feff/workflows/tests/test_xas_workflows.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
import numpy as np
54
from fireworks.core.fworker import FWorker
@@ -126,7 +125,3 @@ def _check_run(self, d):
126125
self.assertEqual(d["input_parameters"], tags.as_dict())
127126
xmu = np.loadtxt(os.path.join(run_dir, "xmu.dat"))
128127
self.assertEqual(d["spectrum"], xmu.tolist())
129-
130-
131-
if __name__ == "__main__":
132-
unittest.main()

atomate/lammps/tests/test_drone.py

-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,3 @@ def test_assimilate(self):
6363
# 145.4361,
6464
# ]
6565
# self.assertEqual(lmps_output.as_dict()["thermo_data"]["enthalpy"], enthalpy)
66-
67-
68-
if __name__ == "__main__":
69-
unittest.main()

atomate/lammps/tests/test_workflows.py

-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def setUp(self):
4444
)
4545

4646
def test_lammps_wflow(self):
47-
4847
wf = get_wf_basic(
4948
self.input_file_template,
5049
self.user_settings,
@@ -94,7 +93,3 @@ def _check_run(self, d):
9493
f"{self.reference_files_path}/peo.dcd",
9594
)
9695
)
97-
98-
99-
if __name__ == "__main__":
100-
unittest.main()

atomate/qchem/firetasks/tests/test_critic2.py

-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,3 @@ def test_ProcessCritic2(self):
119119
with open("processed_critic2.json") as f:
120120
just_built = json.load(f)
121121
self.assertEqual(reference, just_built)
122-
123-
124-
if __name__ == "__main__":
125-
unittest.main()

atomate/qchem/firetasks/tests/test_fragmenter.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import unittest
43

54
from monty.serialization import loadfn # , dumpfn
65

@@ -468,7 +467,3 @@ def test_EC_neg(self):
468467
frags = ft.unique_fragments
469468
self.assertEqual(len(frags), 7)
470469
self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 14)
471-
472-
473-
if __name__ == "__main__":
474-
unittest.main()

atomate/qchem/firetasks/tests/test_geo_transformations.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32

43
import numpy as np
54
from pymatgen.core.structure import Molecule
@@ -17,7 +16,6 @@
1716
class TestGeoTransformations(AtomateTest):
1817
@classmethod
1918
def setUpClass(cls):
20-
2119
cls.pt_mol = Molecule.from_file(
2220
os.path.join(
2321
module_dir, "..", "..", "test_files", "pt_gs_wb97mv_tz_initial.xyz"
@@ -52,7 +50,6 @@ def test_rotate_torsion(self):
5250
class TestPerturbGeometry(AtomateTest):
5351
@classmethod
5452
def setUpClass(cls):
55-
5653
cls.ts_init = Molecule.from_file(
5754
os.path.join(module_dir, "..", "..", "test_files", "ts_init.xyz")
5855
)
@@ -81,7 +78,3 @@ def test_perturb(self):
8178
np.testing.assert_allclose(
8279
self.ts_perturbed.cart_coords, test_mol.cart_coords, atol=0.0001
8380
)
84-
85-
86-
if __name__ == "__main__":
87-
unittest.main()

atomate/qchem/firetasks/tests/test_parse_outputs.py

+84-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import os
22
import shutil
3-
import unittest
43

5-
from pymatgen.core import Molecule
6-
from pymatgen.io.qchem.inputs import QCInput
4+
from monty.serialization import loadfn
75

86
from atomate.qchem.firetasks.parse_outputs import QChemToDb
97
from atomate.utils.testing import AtomateTest
108

11-
from monty.serialization import loadfn
12-
139
__author__ = "Samuel Blau"
1410
__email__ = "[email protected]"
1511

@@ -24,62 +20,122 @@ def tearDown(self):
2420
pass
2521

2622
def test_parse_grad_good(self):
27-
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_good")
23+
my_calc_dir = os.path.join(
24+
module_dir, "..", "..", "test_files", "parse_grad_good"
25+
)
2826
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
2927
ft.run_task({})
30-
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
28+
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
3129
self.assertEqual(task_doc["output"]["final_energy"], -274.6893362188)
3230
self.assertEqual(len(task_doc["output"]["precise_gradients"]), 10)
33-
self.assertEqual(task_doc["output"]["precise_gradients"][0], [0.0090906486788787, 0.016150932052898, 0.0054568671405536])
34-
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0014495621906601, -0.0018570062958895, 0.0012478282193499])
31+
self.assertEqual(
32+
task_doc["output"]["precise_gradients"][0],
33+
[0.0090906486788787, 0.016150932052898, 0.0054568671405536],
34+
)
35+
self.assertEqual(
36+
task_doc["output"]["precise_gradients"][-1],
37+
[0.0014495621906601, -0.0018570062958895, 0.0012478282193499],
38+
)
3539
os.remove(os.path.join(my_calc_dir, "task.json"))
3640

3741
def test_parse_grad_131(self):
38-
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","tmqm_grad_pcm")
42+
my_calc_dir = os.path.join(
43+
module_dir, "..", "..", "test_files", "tmqm_grad_pcm"
44+
)
3945
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
4046
ft.run_task({})
41-
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
47+
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
4248
self.assertEqual(task_doc["output"]["final_energy"], -2791.8404057999)
4349
self.assertEqual(len(task_doc["output"]["precise_gradients"]), 25)
44-
self.assertEqual(task_doc["output"]["precise_gradients"][0], [-2.7425178677332305e-05, 1.8017443772144412e-06, -2.3689773769176685e-06])
45-
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0028753270363098644, -0.000392640066359285, 0.004405091870637312])
50+
self.assertEqual(
51+
task_doc["output"]["precise_gradients"][0],
52+
[-2.7425178677332305e-05, 1.8017443772144412e-06, -2.3689773769176685e-06],
53+
)
54+
self.assertEqual(
55+
task_doc["output"]["precise_gradients"][-1],
56+
[0.0028753270363098644, -0.000392640066359285, 0.004405091870637312],
57+
)
4658
os.remove(os.path.join(my_calc_dir, "task.json"))
4759

4860
def test_parse_grad_bad(self):
49-
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_bad")
61+
my_calc_dir = os.path.join(
62+
module_dir, "..", "..", "test_files", "parse_grad_bad"
63+
)
5064
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
5165
ft.run_task({})
52-
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
66+
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
5367
self.assertEqual(task_doc["warnings"]["grad_file_missing"], True)
5468
os.remove(os.path.join(my_calc_dir, "task.json"))
5569

5670

5771
class TestParseOutputQChem_hess(AtomateTest):
5872
def setUp(self, lpad=False):
59-
os.makedirs(os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch"))
73+
os.makedirs(
74+
os.path.join(
75+
module_dir, "..", "..", "test_files", "freq_save_hess", "scratch"
76+
)
77+
)
6078
shutil.copyfile(
61-
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "BUP_scratch", "132.0"),
62-
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch", "132.0"),
79+
os.path.join(
80+
module_dir,
81+
"..",
82+
"..",
83+
"test_files",
84+
"freq_save_hess",
85+
"BUP_scratch",
86+
"132.0",
87+
),
88+
os.path.join(
89+
module_dir,
90+
"..",
91+
"..",
92+
"test_files",
93+
"freq_save_hess",
94+
"scratch",
95+
"132.0",
96+
),
6397
)
6498
shutil.copyfile(
65-
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "BUP_scratch", "HESS"),
66-
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch", "HESS"),
99+
os.path.join(
100+
module_dir,
101+
"..",
102+
"..",
103+
"test_files",
104+
"freq_save_hess",
105+
"BUP_scratch",
106+
"HESS",
107+
),
108+
os.path.join(
109+
module_dir,
110+
"..",
111+
"..",
112+
"test_files",
113+
"freq_save_hess",
114+
"scratch",
115+
"HESS",
116+
),
67117
)
68118
super().setUp(lpad=False)
69119

70120
def test_parse_hess(self):
71-
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","freq_save_hess")
121+
my_calc_dir = os.path.join(
122+
module_dir, "..", "..", "test_files", "freq_save_hess"
123+
)
72124
ft = QChemToDb(calc_dir=my_calc_dir, parse_hess_file=True)
73125
ft.run_task({})
74-
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
126+
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
75127
self.assertEqual(task_doc["output"]["final_energy"], -151.3244603665)
76-
self.assertEqual(task_doc["output"]["hess_data"]["scratch/132.0"][0],0.12636293260949633)
77-
self.assertEqual(task_doc["output"]["hess_data"]["scratch/132.0"][-2],-0.2025032138024329)
78-
self.assertEqual(task_doc["output"]["hess_data"]["scratch/HESS"][-2], ' -0.175476533300377 -0.202503213802433 0.205623571433770 \n')
128+
self.assertEqual(
129+
task_doc["output"]["hess_data"]["scratch/132.0"][0], 0.12636293260949633
130+
)
131+
self.assertEqual(
132+
task_doc["output"]["hess_data"]["scratch/132.0"][-2], -0.2025032138024329
133+
)
134+
self.assertEqual(
135+
task_doc["output"]["hess_data"]["scratch/HESS"][-2],
136+
" -0.175476533300377 -0.202503213802433 0.205623571433770 \n",
137+
)
79138
os.remove(os.path.join(my_calc_dir, "task.json"))
80139

81140
def tearDown(self):
82141
pass
83-
84-
if __name__ == "__main__":
85-
unittest.main()

atomate/qchem/firetasks/tests/test_run_calc.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import unittest
43

54
try:
65
from unittest.mock import patch
@@ -545,7 +544,9 @@ def test_RunQChemFake(self):
545544
for key in ref_out:
546545
if key == "dipoles":
547546
self.assertEqual(ref_out[key]["total"], this_out[key]["total"])
548-
np.testing.assert_array_equal(ref_out[key]["dipole"], this_out[key]["dipole"])
547+
np.testing.assert_array_equal(
548+
ref_out[key]["dipole"], this_out[key]["dipole"]
549+
)
549550
else:
550551
try:
551552
self.assertEqual(ref_out[key], this_out[key])
@@ -556,7 +557,3 @@ def test_RunQChemFake(self):
556557
):
557558
self.assertEqual(os.path.isfile(filename), True)
558559
os.chdir(module_dir)
559-
560-
561-
if __name__ == "__main__":
562-
unittest.main()

atomate/qchem/firetasks/tests/test_write_inputs.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import unittest
43

54
from pymatgen.core import Molecule
65
from pymatgen.io.qchem.inputs import QCInput
@@ -21,7 +20,6 @@
2120
class TestWriteInputQChem(AtomateTest):
2221
@classmethod
2322
def setUpClass(cls):
24-
2523
co_species = ["C", "O"]
2624
co_coords = [[0.0, 0.0, 0.0], [1.3, 0.0, 0.0]]
2725
cls.co_mol = Molecule(co_species, co_coords)
@@ -191,7 +189,3 @@ def test_write_custom_input(self):
191189
test_dict = QCInput.from_file("mol.qin").as_dict()
192190
for k, v in self.co_opt_diff_in.as_dict().items():
193191
self.assertEqual(v, test_dict[k])
194-
195-
196-
if __name__ == "__main__":
197-
unittest.main()

0 commit comments

Comments
 (0)