diff options
author | Eric Brown <browne@vmware.com> | 2015-06-29 22:53:48 -0700 |
---|---|---|
committer | Eric Brown <browne@vmware.com> | 2015-07-07 00:12:11 -0700 |
commit | 366ca45ef2f46b4a3eb50b283b9b745242aa4bf9 (patch) | |
tree | fb33b72b993e118cceb5208af8da55427e0e2580 /tests/test_cfg.py | |
parent | ac7c55dee3d5b27d45ab31456d5182902c95164b (diff) | |
download | oslo-config-366ca45ef2f46b4a3eb50b283b9b745242aa4bf9.tar.gz |
Expose min and max to IntOpt
The IntOpt class utilizes the types.Integer class which has
parameters for setting the minimum and maximum value. These min
and max values are not exposed through IntOpt and should be ideally.
In the docstring help for cfg.py, it gives an example of creating a
PortType instance of types.Integer to create a new type with a range.
Rather than projects having to define this new instance, seems better
to just expose the min and max to IntOpt.
Another advantage of adding min and max to IntOpt is the ability to
generate a useful sample config file that displays the range of
valid integer values.
Change-Id: Icce7b6799061711ea512d60facc57bf7d6f6c9cc
Diffstat (limited to 'tests/test_cfg.py')
-rw-r--r-- | tests/test_cfg.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_cfg.py b/tests/test_cfg.py index 5d85e1c..6b65788 100644 --- a/tests/test_cfg.py +++ b/tests/test_cfg.py @@ -982,6 +982,19 @@ class ConfigFileOptsTestCase(BaseTestCase): self.assertTrue(hasattr(self.conf, 'foo')) self.assertEqual(self.conf.foo, 666) + def test_conf_file_int_min_max(self): + self.conf.register_opt(cfg.IntOpt('foo', min=1, max=5)) + + paths = self.create_tempfiles([('test', + '[DEFAULT]\n' + 'foo = 10\n')]) + + self.conf(['--config-file', paths[0]]) + self.assertRaises(cfg.ConfigFileValueError, self.conf._get, 'foo') + + def test_conf_file_int_min_greater_max(self): + self.assertRaises(ValueError, cfg.IntOpt, 'foo', min=5, max=1) + def test_conf_file_int_use_dname(self): self._do_dname_test_use(cfg.IntOpt, '66', 66) |