forked from materialsproject/atomate2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
177 lines (138 loc) · 3.95 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import logging
import os
import shutil
import sys
import tempfile
from pathlib import Path
from unittest import mock
import pytest
from fireworks import LaunchPad
from jobflow import JobStore
from jobflow.settings import JobflowSettings
from maggma.stores import MemoryStore
from monty.serialization import loadfn
from pymatgen.core import Structure
from atomate2.utils.log import initialize_logger
@pytest.fixture(scope="session")
def test_dir():
module_dir = Path(__file__).resolve().parent
test_dir = module_dir / "test_data"
return test_dir.resolve()
@pytest.fixture(scope="session")
def log_to_stdout():
# Set Logging
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
root.addHandler(ch)
@pytest.fixture(scope="session")
def clean_dir(debug_mode):
old_cwd = os.getcwd()
new_path = tempfile.mkdtemp()
os.chdir(new_path)
yield
if debug_mode:
print(f"Tests ran in {new_path}") # noqa: T201
else:
os.chdir(old_cwd)
shutil.rmtree(new_path)
@pytest.fixture
def tmp_dir():
"""Same as clean_dir but is fresh for every test"""
old_cwd = os.getcwd()
new_path = tempfile.mkdtemp()
os.chdir(new_path)
yield
os.chdir(old_cwd)
shutil.rmtree(new_path)
@pytest.fixture(scope="session")
def debug_mode():
return False
@pytest.fixture(scope="session")
def lpad(database, debug_mode):
lpad = LaunchPad(name=database)
lpad.reset("", require_password=False)
yield lpad
if not debug_mode:
lpad.reset("", require_password=False)
for coll in lpad.db.list_collection_names():
lpad.db[coll].drop()
@pytest.fixture
def memory_jobstore():
store = JobStore(MemoryStore(), additional_stores={"data": MemoryStore()})
store.connect()
return store
@pytest.fixture(scope="session", autouse=True)
def log_to_stdout_auto_use():
initialize_logger()
@pytest.fixture
def si_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "Si.cif")
@pytest.fixture
def si_diamond(test_dir):
return Structure.from_file(test_dir / "structures" / "Si_diamond.cif")
@pytest.fixture
def al2_au_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "Al2Au.cif")
@pytest.fixture
def sr_ti_o3_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "SrTiO3.cif")
@pytest.fixture
def ba_ti_o3_structure(test_dir):
return Structure.from_file(test_dir / "structures" / "BaTiO3.cif")
@pytest.fixture(autouse=True)
def mock_jobflow_settings(memory_jobstore):
"""Mock the jobflow settings to use our specific jobstore (with data store)."""
settings = JobflowSettings(JOB_STORE=memory_jobstore)
with mock.patch("jobflow.SETTINGS", settings):
yield
@pytest.fixture(
params=[
"Si_227",
"Fe_229",
"S_58",
"Rb2P3_69",
"K2Au3_71",
"LaI3_63",
"KCeF4_123",
"RbO2_129",
"BaN2_15",
"TiNi_11",
"CaC2_2",
"KNO3_160",
"ZnO_186",
],
ids=[
"F cubic",
"I cubic",
"P orth",
"I orth",
"F orth",
"C orth",
"P tet",
"I tet",
"C mono",
"P mono",
"tri",
"rhom",
"hex",
],
scope="session",
)
def symmetry_structure(test_dir, request):
"""The structures are copied from amset.
See https://github.com/hackingmaterials/amset/blob/main/tests/conftest.py
"""
return loadfn(test_dir / "symmetry_structures" / f"{request.param}.json.gz")
def pytest_addoption(parser):
parser.addoption(
"--abinit-integration",
action="store_true",
default=False,
help="Run abinit integration tests. "
"This basically runs the same tests but without the mocking.",
)