1717import gc
1818import unittest
1919
20+ import pytest
2021from numpy import pi
21- from utils import datafile , loadcifdata
2222
2323from pyobjcryst .crystal import CreateCrystalFromCIF
2424from pyobjcryst .diffractiondatasinglecrystal import (
2929
3030class TestCif (unittest .TestCase ):
3131
32+ @pytest .fixture (autouse = True )
33+ def prepare_fixture (self , loadcifdata , datafile ):
34+ self .loadcifdata = loadcifdata
35+ self .datafile = datafile
36+
3237 def test_Ag_silver_cif (self ):
3338 """Check loading of Ag_silver.cif."""
34- c = loadcifdata ("Ag_silver.cif" )
39+ c = self . loadcifdata ("Ag_silver.cif" )
3540 self .assertTrue (c is not None )
3641 return
3742
3843 def test_BaTiO3_cif (self ):
3944 """Check loading of BaTiO3.cif."""
40- c = loadcifdata ("BaTiO3.cif" )
45+ c = self . loadcifdata ("BaTiO3.cif" )
4146 self .assertTrue (c is not None )
4247 return
4348
4449 def test_C_graphite_hex_cif (self ):
4550 """Check loading of C_graphite_hex.cif."""
46- c = loadcifdata ("C_graphite_hex.cif" )
51+ c = self . loadcifdata ("C_graphite_hex.cif" )
4752 self .assertTrue (c is not None )
4853 return
4954
5055 def test_CaF2_fluorite_cif (self ):
5156 """Check loading of CaF2_fluorite.cif."""
52- c = loadcifdata ("CaF2_fluorite.cif" )
57+ c = self . loadcifdata ("CaF2_fluorite.cif" )
5358 self .assertTrue (c is not None )
5459 return
5560
5661 def test_caffeine_cif (self ):
5762 """Check loading of caffeine.cif and the data inside."""
58- c = loadcifdata ("caffeine.cif" )
63+ c = self . loadcifdata ("caffeine.cif" )
5964 self .assertTrue (c is not None )
6065 self .assertEqual (24 , c .GetNbScatterer ())
6166 self .assertAlmostEqual (14.9372 , c .a , 6 )
@@ -103,7 +108,7 @@ def test_caffeine_cif(self):
103108
104109 def test_CaTiO3_cif (self ):
105110 """Check loading of CaTiO3.cif and its ADPs."""
106- c = loadcifdata ("CaTiO3.cif" )
111+ c = self . loadcifdata ("CaTiO3.cif" )
107112 self .assertTrue (c is not None )
108113 s = c .GetScatt (3 )
109114 name = s .GetName ()
@@ -125,79 +130,79 @@ def test_CaTiO3_cif(self):
125130
126131 def test_CdSe_cadmoselite_cif (self ):
127132 """Check loading of CdSe_cadmoselite.cif."""
128- c = loadcifdata ("CdSe_cadmoselite.cif" )
133+ c = self . loadcifdata ("CdSe_cadmoselite.cif" )
129134 self .assertTrue (c is not None )
130135 return
131136
132137 def test_CeO2_cif (self ):
133138 """Check loading of CeO2.cif."""
134- c = loadcifdata ("CeO2.cif" )
139+ c = self . loadcifdata ("CeO2.cif" )
135140 self .assertTrue (c is not None )
136141 return
137142
138143 def test_lidocainementhol_cif (self ):
139144 """Check loading of lidocainementhol.cif."""
140- c = loadcifdata ("lidocainementhol.cif" )
145+ c = self . loadcifdata ("lidocainementhol.cif" )
141146 self .assertTrue (c is not None )
142147 return
143148
144149 def test_NaCl_cif (self ):
145150 """Check loading of NaCl.cif."""
146- c = loadcifdata ("NaCl.cif" )
151+ c = self . loadcifdata ("NaCl.cif" )
147152 self .assertTrue (c is not None )
148153 return
149154
150155 def test_Ni_cif (self ):
151156 """Check loading of Ni.cif."""
152- c = loadcifdata ("Ni.cif" )
157+ c = self . loadcifdata ("Ni.cif" )
153158 self .assertTrue (c is not None )
154159 return
155160
156161 def test_paracetamol_cif (self ):
157162 """Check loading of paracetamol.cif."""
158- c = loadcifdata ("paracetamol.cif" )
163+ c = self . loadcifdata ("paracetamol.cif" )
159164 self .assertTrue (c is not None )
160165 return
161166
162167 def test_PbS_galena_cif (self ):
163168 """Check loading of PbS_galena.cif."""
164- c = loadcifdata ("PbS_galena.cif" )
169+ c = self . loadcifdata ("PbS_galena.cif" )
165170 self .assertTrue (c is not None )
166171 return
167172
168173 def test_PbTe_cif (self ):
169174 """Check loading of PbTe.cif."""
170- c = loadcifdata ("PbTe.cif" )
175+ c = self . loadcifdata ("PbTe.cif" )
171176 self .assertTrue (c is not None )
172177 return
173178
174179 def test_Si_cif (self ):
175180 """Check loading of Si.cif."""
176- c = loadcifdata ("Si.cif" )
181+ c = self . loadcifdata ("Si.cif" )
177182 self .assertTrue (c is not None )
178183 return
179184
180185 def test_Si_setting2_cif (self ):
181186 """Check loading of Si_setting2.cif."""
182- c = loadcifdata ("Si_setting2.cif" )
187+ c = self . loadcifdata ("Si_setting2.cif" )
183188 self .assertTrue (c is not None )
184189 return
185190
186191 def test_SrTiO3_tausonite_cif (self ):
187192 """Check loading of SrTiO3_tausonite.cif."""
188- c = loadcifdata ("SrTiO3_tausonite.cif" )
193+ c = self . loadcifdata ("SrTiO3_tausonite.cif" )
189194 self .assertTrue (c is not None )
190195 return
191196
192197 def test_TiO2_anatase_cif (self ):
193198 """Check loading of TiO2_anatase.cif."""
194- c = loadcifdata ("TiO2_anatase.cif" )
199+ c = self . loadcifdata ("TiO2_anatase.cif" )
195200 self .assertTrue (c is not None )
196201 return
197202
198203 def test_TiO2_rutile_cif (self ):
199204 """Check loading of TiO2_rutile.cif and its ADP data."""
200- c = loadcifdata ("TiO2_rutile.cif" )
205+ c = self . loadcifdata ("TiO2_rutile.cif" )
201206 self .assertTrue (c is not None )
202207 s = c .GetScatt (0 )
203208 name = s .GetName ()
@@ -210,50 +215,56 @@ def test_TiO2_rutile_cif(self):
210215
211216 def test_Zn_zinc_cif (self ):
212217 """Check loading of Zn_zinc.cif."""
213- c = loadcifdata ("Zn_zinc.cif" )
218+ c = self . loadcifdata ("Zn_zinc.cif" )
214219 self .assertTrue (c is not None )
215220 return
216221
217222 def test_ZnS_sphalerite_cif (self ):
218223 """Check loading of ZnS_sphalerite.cif."""
219- c = loadcifdata ("ZnS_sphalerite.cif" )
224+ c = self . loadcifdata ("ZnS_sphalerite.cif" )
220225 self .assertTrue (c is not None )
221226 return
222227
223228 def test_ZnS_wurtzite_cif (self ):
224229 """Check loading of ZnS_wurtzite.cif."""
225- c = loadcifdata ("ZnS_wurtzite.cif" )
230+ c = self . loadcifdata ("ZnS_wurtzite.cif" )
226231 self .assertTrue (c is not None )
227232 return
228233
229234 def testBadCif (self ):
230235 """Make sure we can read all cif files."""
231236 from pyobjcryst import ObjCrystException
232237
233- fname = datafile ("ni.stru" )
238+ fname = self . datafile ("ni.stru" )
234239 infile = open (fname , "rb" )
235240 self .assertRaises (ObjCrystException , CreateCrystalFromCIF , infile )
236241 infile .close ()
237242 return
238243
239244 def test_paracetamol_monomethanolate (self ):
240245 """Test loading crystal and diffraction data."""
241- c = loadcifdata ("paracetamol_monomethanolate.cif" )
246+ c = self . loadcifdata ("paracetamol_monomethanolate.cif" )
242247 d = create_singlecrystaldata_from_cif (
243- datafile ("paracetamol_monomethanolate_data_single_crystal.cif" ), c
248+ self .datafile (
249+ "paracetamol_monomethanolate_data_single_crystal.cif"
250+ ),
251+ c ,
244252 )
245253 self .assertTrue (d is not None )
246254
247255 def test_paracetamol_monomethanolate_ward (self ):
248256 """Test loading crystal and diffraction data, make sure
249257 custodian & ward works."""
250- c = loadcifdata ("paracetamol_monomethanolate.cif" )
258+ c = self . loadcifdata ("paracetamol_monomethanolate.cif" )
251259 d = create_singlecrystaldata_from_cif (
252- datafile ("paracetamol_monomethanolate_data_single_crystal.cif" ), c
260+ self .datafile (
261+ "paracetamol_monomethanolate_data_single_crystal.cif"
262+ ),
263+ c ,
253264 )
254265 n = d .GetCrystal ().GetName ()
255266 # Replace c by another Crystal object
256- c = loadcifdata ("ZnS_sphalerite.cif" )
267+ c = self . loadcifdata ("ZnS_sphalerite.cif" )
257268 gc .collect ()
258269 self .assertTrue (gCrystalRegistry .GetObj (n ) is not None )
259270
0 commit comments