Exemple #1
0
    def test_max(self):
        val = NumberValue(name='foo', max=100)
        with self.assertRaises(ValueError) as cm:
            val.set(100.001)
        self.assertIn('Too large', str(cm.exception))
        self.assertIn('maximum is 100', str(cm.exception))

        val = NumberValue(name='foo', default=100)
        val.max = 50
        self.assertEqual(val.max, 50)
        self.assertEqual(val.get(), 50)
        self.assertEqual(val.get_default(), 50)
        with self.assertRaises(ValueError) as cm:
            val.set(51)
        self.assertIn('Too large', str(cm.exception))
        self.assertIn('maximum is 50', str(cm.exception))
Exemple #2
0
    def test_min(self):
        val = NumberValue(name='foo', min=10)
        with self.assertRaises(ValueError) as cm:
            val.set(9)
        self.assertIn('Too small', str(cm.exception))
        self.assertIn('minimum is 10', str(cm.exception))

        val = NumberValue(name='foo', default=100)
        val.min = 150
        self.assertEqual(val.min, 150)
        self.assertEqual(val.get(), 150)
        self.assertEqual(val.get_default(), 150)
        with self.assertRaises(ValueError) as cm:
            val.set(149)
        self.assertIn('Too small', str(cm.exception))
        self.assertIn('minimum is 150', str(cm.exception))