11import json
2+ import logging
23from pathlib import Path
34
45import pytest
56
7+ from diffpy .srreal .structureconverters import convertObjCrystCrystal
8+ import diffpy .structure as mod_structure
9+
610
711@pytest .fixture
812def user_filesystem (tmp_path ):
@@ -17,3 +21,55 @@ def user_filesystem(tmp_path):
1721 json .dump (home_config_data , f )
1822
1923 yield tmp_path
24+
25+
26+ # Resolve availability of optional packages.
27+
28+ # pyobjcryst
29+
30+
31+ @pytest .fixture (scope = "session" )
32+ def _msg_nopyobjcryst ():
33+ return "No module named 'pyobjcryst'"
34+
35+
36+ @pytest .fixture (scope = "session" )
37+ def has_pyobjcryst ():
38+ try :
39+ import pyobjcryst .crystal
40+ convertObjCrystCrystal (pyobjcryst .crystal .Crystal ())
41+ has_pyobjcryst = True
42+ except ImportError :
43+ has_pyobjcryst = False
44+ logging .warning ("Cannot import pyobjcryst, pyobjcryst tests skipped." )
45+ print ("Cannot import pyobjcryst, pyobjcryst tests skipped." )
46+ except TypeError :
47+ has_pyobjcryst = False
48+ logging .warning ("Compiled without ObjCryst, pyobjcryst tests skipped." )
49+ print ("Compiled without ObjCryst, pyobjcryst tests skipped." )
50+
51+ return has_pyobjcryst
52+
53+
54+ # periodictable
55+
56+
57+ @pytest .fixture (scope = "session" )
58+ def _msg_noperiodictable ():
59+ return "No module named 'periodictable'"
60+
61+
62+ @pytest .fixture (scope = "session" )
63+ def has_periodictable ():
64+ try :
65+ import periodictable
66+
67+ has_periodictable = True
68+
69+ # silence the pyflakes syntax checker
70+ del periodictable
71+ except ImportError :
72+ has_periodictable = False
73+ logging .warning ("Cannot import periodictable, periodictable tests skipped." )
74+
75+ return has_periodictable
0 commit comments