1818 CrystalStructureAdapter )
1919import diffpy .srreal .tests .testutils as testutils
2020
21+ # ----------------------------------------------------------------------------
2122
22- # useful variables
23- nickel = loadDiffPyStructure ('Ni.stru' )
24- rutile_cif = 'TiO2_rutile-fit.cif'
25-
26- ##############################################################################
2723class TestRoutines (unittest .TestCase ):
2824
25+ def setUp (self ):
26+ self .nickel = loadDiffPyStructure ('Ni.stru' )
27+ return
28+
2929 def test_createStructureAdapter (self ):
3030 """check createStructureAdapter() routine.
3131 """
32- adpt = createStructureAdapter (nickel )
32+ adpt = createStructureAdapter (self . nickel )
3333 self .assertEqual (4 , adpt .countSites ())
3434 self .assertTrue (False is adpt .siteAnisotropy (0 ))
3535 self .assertTrue (isinstance (adpt , StructureAdapter ))
@@ -47,23 +47,23 @@ def test_createStructureAdapterTypes(self):
4747 from diffpy .srreal .structureconverters import (
4848 DiffPyStructureAtomicAdapter ,
4949 DiffPyStructurePeriodicAdapter )
50- adpt = createStructureAdapter (nickel )
50+ adpt = createStructureAdapter (self . nickel )
5151 self .assertTrue (type (adpt ) is DiffPyStructurePeriodicAdapter )
52- nickel .pdffit = None
53- adpt1 = createStructureAdapter (nickel )
52+ self . nickel .pdffit = None
53+ adpt1 = createStructureAdapter (self . nickel )
5454 self .assertTrue (type (adpt1 ) is PeriodicStructureAdapter )
55- nickel .lattice .setLatPar (1 , 1 , 1 , 90 , 90 , 90 )
56- adpt2 = createStructureAdapter (nickel )
55+ self . nickel .lattice .setLatPar (1 , 1 , 1 , 90 , 90 , 90 )
56+ adpt2 = createStructureAdapter (self . nickel )
5757 self .assertTrue (type (adpt2 ) is AtomicStructureAdapter )
58- nickel .pdffit = dict (scale = 1 )
59- adpt3 = createStructureAdapter (nickel )
58+ self . nickel .pdffit = dict (scale = 1 )
59+ adpt3 = createStructureAdapter (self . nickel )
6060 self .assertTrue (type (adpt3 ) is DiffPyStructureAtomicAdapter )
6161 return
6262
6363 def test_pickling (self ):
6464 '''check pickling of StructureAdapter instances.
6565 '''
66- adpt = createStructureAdapter (nickel )
66+ adpt = createStructureAdapter (self . nickel )
6767 adpt1 = cPickle .loads (cPickle .dumps (adpt ))
6868 self .assertFalse (adpt is adpt1 )
6969 self .assertEqual (adpt .countSites (), adpt1 .countSites ())
@@ -89,8 +89,8 @@ def test_pickle_nonwrapped(self):
8989
9090# End of class TestStructureAdapter
9191
92+ # ----------------------------------------------------------------------------
9293
93- ##############################################################################
9494class TestDerivedAdapter (unittest .TestCase ):
9595 'Check functionality in a Python-derived StructureAdapter class.'
9696
@@ -137,15 +137,19 @@ class TestDerivedPeriodicAdapter(TestDerivedAdapter):
137137class TestDerivedCrystalAdapter (TestDerivedAdapter ):
138138 DerivedCls = testutils .DerivedCrystalStructureAdapter
139139
140+ # ----------------------------------------------------------------------------
140141
141- ##############################################################################
142142class TestNoMeta (unittest .TestCase ):
143143
144+ def setUp (self ):
145+ self .nickel = loadDiffPyStructure ('Ni.stru' )
146+ return
147+
144148 def test_nometa (self ):
145149 '''check NoMetaStructureAdapter.
146150 '''
147- r0 , g0 = PDFCalculator ()(nickel )
148- ni1 = Structure (nickel )
151+ r0 , g0 = PDFCalculator ()(self . nickel )
152+ ni1 = Structure (self . nickel )
149153 ni1 .pdffit ['scale' ] = 2.0
150154 r1 , g1 = PDFCalculator ()(ni1 )
151155 self .assertTrue (numpy .array_equal (r0 , r1 ))
@@ -155,7 +159,7 @@ def test_nometa(self):
155159 r1nm , g1nm = PDFCalculator ()(ni1nm )
156160 self .assertTrue (numpy .array_equal (r0 , r1nm ))
157161 self .assertTrue (numpy .allclose (g0 , g1nm ))
158- ni2 = Structure (nickel )
162+ ni2 = Structure (self . nickel )
159163 ni2 .pdffit ['delta2' ] = 4
160164 r2 , g2 = PDFCalculator ()(ni2 )
161165 r2 , g2nm = PDFCalculator ()(nometa (ni2 ))
@@ -171,8 +175,8 @@ def test_nometa(self):
171175 def test_nometa_pickling (self ):
172176 '''check pickling of the NoMetaStructureAdapter wrapper.
173177 '''
174- r0 , g0 = PDFCalculator ()(nickel )
175- ni1 = Structure (nickel )
178+ r0 , g0 = PDFCalculator ()(self . nickel )
179+ ni1 = Structure (self . nickel )
176180 ni1 .pdffit ['scale' ] = 2.0
177181 ni1nm = cPickle .loads (cPickle .dumps (nometa (ni1 )))
178182 self .assertFalse (ni1nm is ni1 )
@@ -184,23 +188,27 @@ def test_nometa_pickling(self):
184188 def test_nometa_twice (self ):
185189 '''check that second call of nometa returns the same object.
186190 '''
187- adpt1 = nometa (nickel )
191+ adpt1 = nometa (self . nickel )
188192 adpt2 = nometa (adpt1 )
189193 self .assertTrue (adpt1 is adpt2 )
190194
191195# End of class TestNoMeta
192196
197+ # ----------------------------------------------------------------------------
193198
194- ##############################################################################
195199class TestNoSymmetry (unittest .TestCase ):
196200
201+ def setUp (self ):
202+ self .nickel = loadDiffPyStructure ('Ni.stru' )
203+ return
204+
197205 def test_nosymmetry (self ):
198206 '''check NoSymmetryStructureAdapter.
199207 '''
200208 pdfc0 = PDFCalculator ()
201- r0 , g0 = pdfc0 (nickel )
209+ r0 , g0 = pdfc0 (self . nickel )
202210 rdf0 = pdfc0 .rdf
203- niuc = nosymmetry (nickel )
211+ niuc = nosymmetry (self . nickel )
204212 self .assertTrue (niuc is nosymmetry (niuc ))
205213 pdfc1 = PDFCalculator ()
206214 r1 , g1 = pdfc1 (niuc )
@@ -213,7 +221,7 @@ def test_nosymmetry(self):
213221 head = r0 < 3.0
214222 self .assertAlmostEqual (12.0 , numpy .sum (rdf0 [head ] * pdfc0 .rstep ), 5 )
215223 self .assertAlmostEqual (3.0 , numpy .sum (rdf1 [head ] * pdfc1 .rstep ), 5 )
216- adpt0 = createStructureAdapter (nickel )
224+ adpt0 = createStructureAdapter (self . nickel )
217225 ra2 , ga2 = PDFCalculator ()(nosymmetry (adpt0 ))
218226 self .assertTrue (numpy .array_equal (r0 , ra2 ))
219227 self .assertTrue (numpy .allclose (g1 , ga2 ))
@@ -222,14 +230,14 @@ def test_nosymmetry(self):
222230 def test_nosymmetry_twice (self ):
223231 '''check that second call of nosymmetry returns the same object.
224232 '''
225- adpt1 = nosymmetry (nickel )
233+ adpt1 = nosymmetry (self . nickel )
226234 adpt2 = nosymmetry (adpt1 )
227235 self .assertTrue (adpt1 is adpt2 )
228236
229237 def test_nosymmetry_pickling (self ):
230238 '''check pickling of the NoSymmetryStructureAdapter wrapper.
231239 '''
232- ni1ns = nosymmetry (nickel )
240+ ni1ns = nosymmetry (self . nickel )
233241 r1 , g1 = PDFCalculator ()(ni1ns )
234242 ni2ns = cPickle .loads (cPickle .dumps (ni1ns ))
235243 self .assertFalse (ni1ns is ni2ns )
@@ -240,12 +248,12 @@ def test_nosymmetry_pickling(self):
240248
241249# End of class TestNoSymmetry
242250
251+ # ----------------------------------------------------------------------------
243252
244- ##############################################################################
245253class TestPyObjCrystAdapter (TestCaseObjCrystOptional ):
246254
247255 def setUp (self ):
248- rutile_crystal = loadObjCrystCrystal (rutile_cif )
256+ rutile_crystal = loadObjCrystCrystal ('TiO2_rutile-fit.cif' )
249257 self .rutile = createStructureAdapter (rutile_crystal )
250258 return
251259
@@ -279,7 +287,8 @@ def test_objcryst_pickling(self):
279287
280288# End of class TestNoSymmetry
281289
282- ##############################################################################
290+ # ----------------------------------------------------------------------------
291+
283292class IndexRangeTests (object ):
284293 'Check error handling for site index arguments.'
285294
@@ -354,7 +363,8 @@ class TestAtomicAdapterIndexRange(IndexRangeTests, TestCase):
354363class TestCrystalAdapter (IndexRangeTests , TestCase ):
355364 AdptClass = CrystalStructureAdapter
356365
357- ##############################################################################
366+ # ----------------------------------------------------------------------------
367+
358368class TestDerivedStructureAdapter (IndexRangeTests , TestCase ):
359369 AdptClass = testutils .DerivedStructureAdapter
360370
@@ -414,7 +424,8 @@ def test_siteCartesianUij_valid(self):
414424
415425# End of class TestDerivedStructureAdapter
416426
417- ##############################################################################
427+ # ----------------------------------------------------------------------------
428+
418429class TestStructureAdapter (unittest .TestCase ):
419430
420431 def setUp (self ):
@@ -486,7 +497,8 @@ def test_siteCartesianUij(self):
486497
487498# End of class TestStructureAdapter
488499
489- ##############################################################################
500+ # ----------------------------------------------------------------------------
501+
490502class TestAtom (unittest .TestCase ):
491503
492504 def setUp (self ):
@@ -555,6 +567,8 @@ def test_uij_cartn(self):
555567
556568# End of class TestAtom
557569
570+ # ----------------------------------------------------------------------------
571+
558572if __name__ == '__main__' :
559573 unittest .main ()
560574
0 commit comments