Пример #1
0
    def __init__(self, name = "sgpars"):
        """Create the BaseSpaceGroupParameters object.

        This initializes the attributes.

        """
        RecipeContainer.__init__(self, name)
        return
Пример #2
0
    def addParameter(self, par, check = True):
        """Store a Parameter.

        par     --  The Parameter to be stored.
        check   --  If True (default), a ValueError is raised a Parameter of
                    the specified name has already been inserted.

        Raises ValueError if the Parameter has no name.

        """
        # Store the Parameter
        RecipeContainer._addObject(self, par, self._parameters, check)
        return
Пример #3
0
 def __iter__(self):
     """Iterate over top-level parameters."""
     if self._latpars is None or\
             self._xyzpars is None or\
             self._adppars is None:
                 self._makeConstraints()
     return RecipeContainer.__iter__(self)
    def setUp(self):
        self.m = RecipeContainer("test")

        # Add another managed dictionary
        self.m._containers = {}
        self.m._manage(self.m._containers)

        return
    def testLocateManagedObject(self):
        """Test the locateManagedObject method."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        p3 = Parameter("p3", 3)

        # Locate m2 in m1 (m1.m2)
        loc = m1._locateManagedObject(m2)
        self.assertEquals(loc, [m1, m2])

        # Locate p1 (m1.p1)
        loc = m1._locateManagedObject(p1)
        self.assertEquals(loc, [m1, p1])

        # Locate p2 in m2 (m2.p2)
        loc = m2._locateManagedObject(p2)
        self.assertEquals(loc, [m2, p2])

        # Locate p2 in m1 (m1.m2.p2)
        loc = m1._locateManagedObject(p2)
        self.assertEquals(loc, [m1, m2, p2])

        # Locate p3 in m1 (not there)
        loc = m1._locateManagedObject(p3)
        self.assertEquals(loc, [])

        # Locate p3 in m2 (not there)
        loc = m2._locateManagedObject(p3)
        self.assertEquals(loc, [])

        return
    def testAccessors(self):
        """Test accessors."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        self.assertTrue(m1.m2 is m2)
        self.assertTrue(m1.p1 is p1)
        self.assertTrue(m2.p2 is p2)
        self.assertTrue(m1.m2.p2 is p2)

        self.assertTrue(m1[0] is p1)
        self.assertTrue(m1[0:] == [p1,])
        self.assertTrue(m2[0] is p2)

        self.assertEqual(1, len(m1))
        self.assertEqual(1, len(m2))
        return
Пример #7
0
    def testRemoveParameter(self):
        """Test removeParameter method."""

        m = self.m

        p1 = Parameter("p1", 1)
        p2 = Parameter("p1", 2)

        m._addParameter(p1)

        # Check for bad remove
        self.assertRaises(ValueError, m._removeParameter, p2)

        # Remove p1
        m._removeParameter(p1)
        self.assertTrue(p1.name not in m._eqfactory.builders)

        # Try to remove it again
        self.assertRaises(ValueError, m._removeParameter, p1)

        # Try to remove a RecipeContainer
        c = RecipeContainer("test")
        self.assertRaises(ValueError, m._removeParameter, c)
        return
Пример #8
0
    def testLocateManagedObject(self):
        """Test the locateManagedObject method."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        p3 = Parameter("p3", 3)

        # Locate m2 in m1 (m1.m2)
        loc = m1._locateManagedObject(m2)
        self.assertEqual(loc, [m1, m2])

        # Locate p1 (m1.p1)
        loc = m1._locateManagedObject(p1)
        self.assertEqual(loc, [m1, p1])

        # Locate p2 in m2 (m2.p2)
        loc = m2._locateManagedObject(p2)
        self.assertEqual(loc, [m2, p2])

        # Locate p2 in m1 (m1.m2.p2)
        loc = m1._locateManagedObject(p2)
        self.assertEqual(loc, [m1, m2, p2])

        # Locate p3 in m1 (not there)
        loc = m1._locateManagedObject(p3)
        self.assertEqual(loc, [])

        # Locate p3 in m2 (not there)
        loc = m2._locateManagedObject(p3)
        self.assertEqual(loc, [])

        return
Пример #9
0
class TestRecipeContainer(unittest.TestCase):
    def setUp(self):
        self.m = RecipeContainer("test")

        # Add another managed dictionary
        self.m._containers = {}
        self.m._manage(self.m._containers)

        return

    def testAccessors(self):
        """Test accessors."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        self.assertTrue(m1.m2 is m2)
        self.assertTrue(m1.p1 is p1)
        self.assertTrue(m2.p2 is p2)
        self.assertTrue(m1.m2.p2 is p2)

        self.assertTrue(m1[0] is p1)
        self.assertTrue(m1[0:] == [
            p1,
        ])
        self.assertTrue(m2[0] is p2)

        self.assertEqual(1, len(m1))
        self.assertEqual(1, len(m2))
        return

    def testLocateManagedObject(self):
        """Test the locateManagedObject method."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        p3 = Parameter("p3", 3)

        # Locate m2 in m1 (m1.m2)
        loc = m1._locateManagedObject(m2)
        self.assertEqual(loc, [m1, m2])

        # Locate p1 (m1.p1)
        loc = m1._locateManagedObject(p1)
        self.assertEqual(loc, [m1, p1])

        # Locate p2 in m2 (m2.p2)
        loc = m2._locateManagedObject(p2)
        self.assertEqual(loc, [m2, p2])

        # Locate p2 in m1 (m1.m2.p2)
        loc = m1._locateManagedObject(p2)
        self.assertEqual(loc, [m1, m2, p2])

        # Locate p3 in m1 (not there)
        loc = m1._locateManagedObject(p3)
        self.assertEqual(loc, [])

        # Locate p3 in m2 (not there)
        loc = m2._locateManagedObject(p3)
        self.assertEqual(loc, [])

        return
class TestRecipeContainer(unittest.TestCase):

    def setUp(self):
        self.m = RecipeContainer("test")

        # Add another managed dictionary
        self.m._containers = {}
        self.m._manage(self.m._containers)

        return

    def testAccessors(self):
        """Test accessors."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        self.assertTrue(m1.m2 is m2)
        self.assertTrue(m1.p1 is p1)
        self.assertTrue(m2.p2 is p2)
        self.assertTrue(m1.m2.p2 is p2)

        self.assertTrue(m1[0] is p1)
        self.assertTrue(m1[0:] == [p1,])
        self.assertTrue(m2[0] is p2)

        self.assertEqual(1, len(m1))
        self.assertEqual(1, len(m2))
        return


    def testLocateManagedObject(self):
        """Test the locateManagedObject method."""
        m1 = self.m
        p1 = Parameter("p1", 1)
        m1._addObject(p1, m1._parameters)

        m2 = RecipeContainer("m2")
        p2 = Parameter("p2", 2)
        m2._addObject(p2, m2._parameters)

        m1._addObject(m2, m1._containers)

        p3 = Parameter("p3", 3)

        # Locate m2 in m1 (m1.m2)
        loc = m1._locateManagedObject(m2)
        self.assertEquals(loc, [m1, m2])

        # Locate p1 (m1.p1)
        loc = m1._locateManagedObject(p1)
        self.assertEquals(loc, [m1, p1])

        # Locate p2 in m2 (m2.p2)
        loc = m2._locateManagedObject(p2)
        self.assertEquals(loc, [m2, p2])

        # Locate p2 in m1 (m1.m2.p2)
        loc = m1._locateManagedObject(p2)
        self.assertEquals(loc, [m1, m2, p2])

        # Locate p3 in m1 (not there)
        loc = m1._locateManagedObject(p3)
        self.assertEquals(loc, [])

        # Locate p3 in m2 (not there)
        loc = m2._locateManagedObject(p3)
        self.assertEquals(loc, [])

        return