diff options
author | Adit Sarfaty <asarfaty@vmware.com> | 2016-07-20 15:14:05 +0300 |
---|---|---|
committer | Adit Sarfaty <asarfaty@vmware.com> | 2016-07-21 14:38:23 +0300 |
commit | 15d3ab88f2ddf0c2b7ef60f499d029683a11d513 (patch) | |
tree | a67d8fda3be0dd6385fc747b450a32d2ad37e49f /oslo_config/tests/test_types.py | |
parent | 61224ce932a520367f8836adbb2220e29b73d54a (diff) | |
download | oslo-config-15d3ab88f2ddf0c2b7ef60f499d029683a11d513.tar.gz |
Add min and max values to Float type and Opt
Just like Integers, Floats configuration should also have a minimum and
maximum possible values.
For example, the vmware-nsx plugin needs it for the QoS support.
See https://review.openstack.org/#/c/344763/
Change-Id: If1c47444e0c12b68d9d9cb645b8251e4462cfd49
Diffstat (limited to 'oslo_config/tests/test_types.py')
-rw-r--r-- | oslo_config/tests/test_types.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/oslo_config/tests/test_types.py b/oslo_config/tests/test_types.py index b1b18cb..b53817d 100644 --- a/oslo_config/tests/test_types.py +++ b/oslo_config/tests/test_types.py @@ -394,12 +394,90 @@ class FloatTypeTests(TypeTestHelper, unittest.TestCase): def test_repr(self): self.assertEqual('Float', repr(types.Float())) + def test_repr_with_min(self): + t = types.Float(min=1.1) + self.assertEqual('Float(min=1.1)', repr(t)) + + def test_repr_with_max(self): + t = types.Float(max=2.2) + self.assertEqual('Float(max=2.2)', repr(t)) + + def test_repr_with_min_and_max(self): + t = types.Float(min=1.1, max=2.2) + self.assertEqual('Float(min=1.1, max=2.2)', repr(t)) + t = types.Float(min=1.0, max=2) + self.assertEqual('Float(min=1, max=2)', repr(t)) + t = types.Float(min=0, max=0) + self.assertEqual('Float(min=0, max=0)', repr(t)) + def test_equal(self): self.assertTrue(types.Float() == types.Float()) + def test_equal_with_same_min_and_no_max(self): + self.assertTrue(types.Float(min=123.1) == types.Float(min=123.1)) + + def test_equal_with_same_max_and_no_min(self): + self.assertTrue(types.Float(max=123.1) == types.Float(max=123.1)) + + def test_not_equal(self): + self.assertFalse(types.Float(min=123.1) == types.Float(min=456.1)) + self.assertFalse(types.Float(max=123.1) == types.Float(max=456.1)) + self.assertFalse(types.Float(min=123.1) == types.Float(max=123.1)) + self.assertFalse(types.Float(min=123.1, max=456.1) == + types.Float(min=123.1, max=456.2)) + def test_not_equal_to_other_class(self): self.assertFalse(types.Float() == types.Integer()) + def test_equal_with_same_min_and_max(self): + t1 = types.Float(min=1.1, max=2.2) + t2 = types.Float(min=1.1, max=2.2) + self.assertTrue(t1 == t2) + + def test_min_greater_max(self): + self.assertRaises(ValueError, + types.Float, + min=100.1, max=50) + self.assertRaises(ValueError, + types.Float, + min=-50, max=-100.1) + self.assertRaises(ValueError, + types.Float, + min=0.1, max=-50.0) + self.assertRaises(ValueError, + types.Float, + min=50.0, max=0.0) + + def test_with_max_and_min(self): + t = types.Float(min=123.45, max=678.9) + self.assertRaises(ValueError, t, 123) + self.assertRaises(ValueError, t, 123.1) + t(124.1) + t(300) + t(456.0) + self.assertRaises(ValueError, t, 0) + self.assertRaises(ValueError, t, 800.5) + + def test_with_min_zero(self): + t = types.Float(min=0, max=456.1) + self.assertRaises(ValueError, t, -1) + t(0.0) + t(123.1) + t(300.2) + t(456.1) + self.assertRaises(ValueError, t, -201.0) + self.assertRaises(ValueError, t, 457.0) + + def test_with_max_zero(self): + t = types.Float(min=-456.1, max=0) + self.assertRaises(ValueError, t, 1) + t(0.0) + t(-123.0) + t(-300.0) + t(-456.0) + self.assertRaises(ValueError, t, 201.0) + self.assertRaises(ValueError, t, -457.0) + class ListTypeTests(TypeTestHelper, unittest.TestCase): type = types.List() |