Ejemplo n.º 1
0
class test_BoundedIntVar(unittest.TestCase):
    """ verify functionality of the BoundedIntVar variable class
    """

    def setUp(self):
        self.bivar = BoundedIntVar('name', 'description', min=3, max=10)
        self.defaultminvar = BoundedIntVar('name', 'description', max=10)
        self.defaultmaxvar = BoundedIntVar('name', 'description', min=3)
        self.max = sys.maxint
        self.min = -self.max - 1

    def testValidation(self):
        """ A BoundedIntVar should take values between min and max (inclusive)
            If max is not provided, default to sys.maxint
            if min is not provided, default to -sys.maxint-1
        """
        self.assertEqual(4, self.bivar.validate(4))
        self.assertEqual(5, self.bivar.validate(5.9))
        self.assertEqual(6, self.bivar.validate('6'))

        self.assertRaises(ValidationException, self.bivar.validate, 'four')
        self.assertRaises(ValidationException, self.bivar.validate, 1)
        self.assertRaises(ValidationException, self.bivar.validate, 11)

        self.assertEqual(self.max, self.defaultmaxvar.validate(self.max))
        self.assertEqual(self.min, self.defaultminvar.validate(self.min))
Ejemplo n.º 2
0
class test_BoundedIntVar(unittest.TestCase):
    """ verify functionality of the BoundedIntVar variable class
    """
    def setUp(self):
        self.bivar = BoundedIntVar('name', 'description', min=3, max=10)
        self.defaultminvar = BoundedIntVar('name', 'description', max=10)
        self.defaultmaxvar = BoundedIntVar('name', 'description', min=3)
        self.max = sys.maxint
        self.min = -self.max - 1

    def testValidation(self):
        """ A BoundedIntVar should take values between min and max (inclusive)
            If max is not provided, default to sys.maxint
            if min is not provided, default to -sys.maxint-1
        """
        self.assertEqual(4, self.bivar.validate(4))
        self.assertEqual(5, self.bivar.validate(5.9))
        self.assertEqual(6, self.bivar.validate('6'))

        self.assertRaises(ValidationException, self.bivar.validate, 'four')
        self.assertRaises(ValidationException, self.bivar.validate, 1)
        self.assertRaises(ValidationException, self.bivar.validate, 11)

        self.assertEqual(self.max, self.defaultmaxvar.validate(self.max))
        self.assertEqual(self.min, self.defaultminvar.validate(self.min))
Ejemplo n.º 3
0
 def setUp(self):
     self.bivar = BoundedIntVar('name', 'description', min=3, max=10)
     self.defaultminvar = BoundedIntVar('name', 'description', max=10)
     self.defaultmaxvar = BoundedIntVar('name', 'description', min=3)
     self.max = sys.maxint
     self.min = -self.max - 1
Ejemplo n.º 4
0
 def setUp(self):
     self.bivar = BoundedIntVar('name', 'description', min=3, max=10)
     self.defaultminvar = BoundedIntVar('name', 'description', max=10)
     self.defaultmaxvar = BoundedIntVar('name', 'description', min=3)
     self.max = sys.maxint
     self.min = -self.max - 1