forked from diffpy/diffpy.srreal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
75 lines (51 loc) · 1.83 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
import json
import logging
from pathlib import Path
import pytest
from diffpy.srreal.structureconverters import convertObjCrystCrystal
@pytest.fixture
def user_filesystem(tmp_path):
base_dir = Path(tmp_path)
home_dir = base_dir / "home_dir"
home_dir.mkdir(parents=True, exist_ok=True)
cwd_dir = base_dir / "cwd_dir"
cwd_dir.mkdir(parents=True, exist_ok=True)
home_config_data = {"username": "home_username", "email": "[email protected]"}
with open(home_dir / "diffpyconfig.json", "w") as f:
json.dump(home_config_data, f)
yield tmp_path
# Resolve availability of optional packages.
# pyobjcryst
@pytest.fixture(scope="session")
def _msg_nopyobjcryst():
return "No module named 'pyobjcryst'"
@pytest.fixture(scope="session")
def has_pyobjcryst():
try:
import pyobjcryst.crystal
convertObjCrystCrystal(pyobjcryst.crystal.Crystal())
has_pyobjcryst = True
except ImportError:
has_pyobjcryst = False
logging.warning("Cannot import pyobjcryst, pyobjcryst tests skipped.")
print("Cannot import pyobjcryst, pyobjcryst tests skipped.")
except TypeError:
has_pyobjcryst = False
logging.warning("Compiled without ObjCryst, pyobjcryst tests skipped.")
print("Compiled without ObjCryst, pyobjcryst tests skipped.")
return has_pyobjcryst
# periodictable
@pytest.fixture(scope="session")
def _msg_noperiodictable():
return "No module named 'periodictable'"
@pytest.fixture(scope="session")
def has_periodictable():
try:
import periodictable
has_periodictable = True
# silence the pyflakes syntax checker
del periodictable
except ImportError:
has_periodictable = False
logging.warning("Cannot import periodictable, periodictable tests skipped.")
return has_periodictable