def testCrystalScope(self): """Test to see if the the crystal survives after it is out of scope.""" sp, atom = makeScatterer() makeCrystal(sp, atom) # The crystal is out of scope. Since the lifetime of the atom and # scatterer are linked, the crystal should stay alive in memory. self.assertEqual("Ni", sp.GetName()) self.assertEqual("Ni", atom.GetName()) return
def testGetScatterer(self): """Test GetScatterer.""" sp, atom = makeScatterer() c = makeCrystal(sp, atom) for i in range(c.GetNbScatterer()): c.GetScatterer(i) return
def testDummyAtom(self): """Test dummy atoms.""" c = makeCrystal(*makeScatterer()) c.AddScatterer(Atom(0, 0, 0, "dummy", None)) d = c.GetScatterer("dummy") self.assertTrue(d.GetScatteringPower() is None) return
def testGetScatteringComponentList(self): """Test the RemoveScatterer and RemoveScatteringPower method.""" sp, atom = makeScatterer() c = makeCrystal(sp, atom) scl = c.GetScatteringComponentList() self.assertEqual(1, len(scl)) sclcopy = scl[:] self.assertEqual(1, len(scl)) del sclcopy[0] self.assertEqual(0, len(sclcopy)) self.assertEqual(1, len(scl)) del scl[0] self.assertEqual(0, len(scl)) return
def testGetScatterer(self): """Test GetScatterer and GetScatt.""" sp, atom = makeScatterer() c = makeCrystal(sp, atom) for fget in (c.GetScatterer, c.GetScatt): for i in range(c.GetNbScatterer()): fget(i) a = fget(0) ani = fget("Ni") self.assertEqual([a.X, a.Y, a.Z], [ani.X, ani.Y, ani.Z]) a.X = 0.112 self.assertEqual(a.X, ani.X) aneg = fget(-1) self.assertEqual(a.X, aneg.X) self.assertRaises(ValueError, fget, 'invalid') self.assertRaises(IndexError, fget, 10) self.assertRaises(IndexError, fget, -2) return
def testToFromPython(self): """See if refinable parameters can be created from within python and within c++.""" c = makeCrystal(*makeScatterer()) # Get a parameter created from c++ par = c.GetPar("a") self.assertAlmostEqual(3.52, par.GetValue()) # pass a parameter and pass it into c++ c.AddPar(self.testpar); # get it back testpar2 = c.GetPar("test") self.assertAlmostEqual(self.testpar.GetValue(), testpar2.GetValue()) testpar2.SetValue(2.17) self.assertAlmostEqual(2.17, testpar2.GetValue(), places = 6) self.assertAlmostEqual(self.testpar.GetValue(), testpar2.GetValue()) return
def testEmbedding(self): """Test integrity of mutually-embedded objects.""" c = makeCrystal(*makeScatterer()) class Level1(object): def __init__(self, c): self.c = c self.level2 = Level2(self) return class Level2(object): def __init__(self, level1): self.level1 = level1 return l1 = Level1(c) del l1 return
def testRemoveFunctions(self): """Test the RemoveScatterer and RemoveScatteringPower method.""" sp, atom = makeScatterer() c = makeCrystal(sp, atom) # You can add scatterers with the same name. That should be a no-no. sp2, atom2 = makeScatterer() c.AddScatterer(atom2) c.AddScatteringPower(sp2) # These act according to the library. You can try to remove an object # that is not in the crystal, and it will gladly do nothing for you. # Remove the scatterers c.RemoveScatterer(atom) c.RemoveScatteringPower(sp) # Remove again c.RemoveScatterer(atom) c.RemoveScatteringPower(sp) # Try to remove scatterers that are not in the crystal c.RemoveScatterer(atom2) c.RemoveScatteringPower(sp2) return