1- import json
2- from pathlib import Path
31import importlib .resources
4- import pytest
2+ import json
53import logging
6-
74from functools import lru_cache
5+ from pathlib import Path
6+
7+ import pytest
88import diffpy .srfit .equation .literals as literals
99from diffpy .srfit .sas .sasimport import sasimport
1010
1111
1212logger = logging .getLogger (__name__ )
1313
14+
1415@lru_cache ()
1516def has_sas ():
1617 try :
@@ -20,36 +21,45 @@ def has_sas():
2021 except ImportError :
2122 return False
2223
24+
2325# diffpy.structure
2426@lru_cache ()
2527def has_diffpy_structure ():
2628 _msg_nostructure = "No module named 'diffpy.structure'"
2729 try :
2830 import diffpy .structure as m
31+
2932 del m
3033 return True
3134 except ImportError :
3235 return False
33- logger .warning ("Cannot import diffpy.structure, Structure tests skipped." )
36+ logger .warning (
37+ "Cannot import diffpy.structure, Structure tests skipped."
38+ )
39+
3440
3541@lru_cache ()
3642def has_pyobjcryst ():
3743 _msg_nopyobjcryst = "No module named 'pyobjcryst'"
3844 try :
3945 import pyobjcryst as m
46+
4047 del m
4148 return True
4249 except ImportError :
4350 return False
4451 logger .warning ("Cannot import pyobjcryst, pyobjcryst tests skipped." )
4552
53+
4654# diffpy.srreal
4755
56+
4857@lru_cache ()
4958def has_diffpy_srreal ():
5059 _msg_nosrreal = "No module named 'diffpy.srreal'"
5160 try :
5261 import diffpy .srreal .pdfcalculator as m
62+
5363 del m
5464 return True
5565 except ImportError :
@@ -61,14 +71,17 @@ def has_diffpy_srreal():
6171def sas_available ():
6272 return has_sas ()
6373
74+
6475@pytest .fixture (scope = "session" )
6576def diffpy_structure_available ():
6677 return has_diffpy_structure ()
6778
79+
6880@pytest .fixture (scope = "session" )
6981def diffpy_srreal_available ():
7082 return has_diffpy_srreal ()
7183
84+
7285@pytest .fixture (scope = "session" )
7386def pyobjcryst_available ():
7487 return has_pyobjcryst ()
@@ -92,8 +105,12 @@ def user_filesystem(tmp_path):
92105@pytest .fixture
93106def datafile ():
94107 """Fixture to load a test data file from the testdata package directory."""
108+
95109 def _datafile (filename ):
96- return importlib .resources .files ("diffpy.srfit.tests.testdata" ).joinpath (filename )
110+ return importlib .resources .files (
111+ "diffpy.srfit.tests.testdata"
112+ ).joinpath (filename )
113+
97114 return _datafile
98115
99116@pytest .fixture (scope = "session" )
0 commit comments