Esempio n. 1
0
    def setUp(self):
        RequiresDevice.setUp(self)
        align1 = _ped.Alignment(10, 5)
        align2 = _ped.Alignment(10, 5)
        geom1 = _ped.Geometry(self._device, 0, 50)
        geom2 = _ped.Geometry(self._device, 25, 50)

        self.c = _ped.Constraint(align1,
                                 align2,
                                 geom1,
                                 geom2,
                                 min_size=10,
                                 max_size=100)
Esempio n. 2
0
    def runTest(self):
        align1 = _ped.Alignment(10, 5)
        align2 = _ped.Alignment(10, 5)
        geom1 = _ped.Geometry(self._device, 0, 50)
        geom2 = _ped.Geometry(self._device, 25, 50)

        # Check that not passing enough args to _ped.Constraint.__init__ is caught.
        self.assertRaises(TypeError, _ped.Constraint)
        self.assertRaises(TypeError, _ped.Constraint, align1, align2)

        # Or the parameters in the wrong order.
        self.assertRaises(TypeError, _ped.Constraint, align1, align2, 10, 100,
                          geom1, geom2)

        # And then the correct way of creating a _ped.Constraint.
        c = _ped.Constraint(align1, align2, geom1, geom2, 10, 100)
        self.assertIsInstance(c, _ped.Constraint)
Esempio n. 3
0
    def runTest(self):
        align1 = parted.Alignment(offset=10, grainSize=5)
        align2 = parted.Alignment(offset=10, grainSize=5)
        geom1 = parted.Geometry(device=self.device, start=0, length=50)
        geom2 = parted.Geometry(device=self.device, start=0, length=100)

        # Check that not passing enough args to parted.Constraint.__init__
        # is caught.
        self.assertRaises(parted.ConstraintException, parted.Constraint)
        self.assertRaises(parted.ConstraintException,
                          parted.Constraint,
                          startAlign=align1,
                          endAlign=align2)

        # And then the correct ways of creating a _ped.Constraint.
        c = parted.Constraint(minGeom=geom1, maxGeom=geom2)
        self.assertIsInstance(c, parted.Constraint)

        c = parted.Constraint(minGeom=geom1)
        self.assertIsInstance(c, parted.Constraint)

        c = parted.Constraint(maxGeom=geom2)
        self.assertIsInstance(c, parted.Constraint)

        c = parted.Constraint(exactGeom=geom1)
        self.assertIsInstance(c, parted.Constraint)

        c = parted.Constraint(device=self.device)
        self.assertIsInstance(c, parted.Constraint)

        c = parted.Constraint(startAlign=align1,
                              endAlign=align2,
                              startRange=geom1,
                              endRange=geom2,
                              minSize=10,
                              maxSize=100)
        self.assertIsInstance(c, parted.Constraint)

        # Use a _ped.Constraint as the initializer
        pc = _ped.Constraint(align1.getPedAlignment(),
                             align2.getPedAlignment(), geom1.getPedGeometry(),
                             geom2.getPedGeometry(), 10, 100)
        c = parted.Constraint(PedConstraint=pc)
        self.assertIsInstance(c, parted.Constraint)
        self.assertEqual(c.getPedConstraint(), pc)
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        """Create a new Constraint object.  There are many different ways to
           create a Constraint, all depending on the parameters passed to
           __init__.  If minGeom and maxGeom are supplied, the constraint will
           be created to satisfy both.  If only one of minGeom or maxGeom are
           supplied, the constraint is only guaranteed to solve the given
           paramter.  If exactGeom is given, the constraint will only be
           satisfied by the given geometry.  If device is given, any region
           on that device will satisfy the constraint.

           If none of the previously mentioned parameters are supplied, all of
           startAlign, EndAlign, startRange, endRange, minSize, and maxSize
           must be given."""
        if "PedConstraint" in kwargs:
            self.__constraint = kwargs.get("PedConstraint")
        elif "minGeom" in kwargs and "maxGeom" in kwargs:
            ming = kwargs.get("minGeom").getPedGeometry()
            maxg = kwargs.get("maxGeom").getPedGeometry()
            self.__constraint = _ped.constraint_new_from_min_max(ming, maxg)
        elif "minGeom" in kwargs:
            ming = kwargs.get("minGeom").getPedGeometry()
            self.__constraint = _ped.constraint_new_from_min(ming)
        elif "maxGeom" in kwargs:
            maxg = kwargs.get("maxGeom").getPedGeometry()
            self.__constraint = _ped.constraint_new_from_max(maxg)
        elif "exactGeom" in kwargs:
            exact = kwargs.get("exactGeom").getPedGeometry()
            self.__constraint = _ped.constraint_exact(exact)
        elif "device" in kwargs:
            dev = kwargs.get("device").getPedDevice()
            self.__constraint = _ped.constraint_any(dev)
        elif "startAlign" in kwargs and "endAlign" in kwargs and \
             "startRange" in kwargs and "endRange" in kwargs and \
             "minSize" in kwargs and "maxSize" in kwargs:
            starta = kwargs.get("startAlign").getPedAlignment()
            enda = kwargs.get("endAlign").getPedAlignment()
            startr = kwargs.get("startRange").getPedGeometry()
            endr = kwargs.get("endRange").getPedGeometry()
            mins = kwargs.get("minSize")
            maxs = kwargs.get("maxSize")
            self.__constraint = _ped.Constraint(starta, enda, startr, endr,
                                                mins, maxs)
        else:
            raise parted.ConstraintException(
                "missing initialization parameters")
Esempio n. 5
0
    def runTest(self):
        startAlign = self.c1.start_align.intersect(self.c2.start_align)
        endAlign = self.c1.end_align.intersect(self.c2.end_align)
        startRange = self.c1.start_range.intersect(self.c2.start_range)
        endRange = self.c1.end_range.intersect(self.c2.end_range)
        minSize = max(self.c1.min_size, self.c2.min_size)
        maxSize = min(self.c1.max_size, self.c2.max_size)

        if not startAlign or not endAlign or not startRange or not endRange:
            expected = None
        else:
            expected = _ped.Constraint(startAlign,
                                       endAlign,
                                       startRange,
                                       endRange,
                                       min_size=minSize,
                                       max_size=maxSize)

        result = self.c1.intersect(self.c2)
        self.assertEqual(result, expected)