diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-06-20 22:06:57 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-06-20 22:06:57 +0000 |
commit | d8e71b9d10132a9c134ff79a4ecdc77d17d424be (patch) | |
tree | d9d0839a73fe431bffb38be15ceec8352efd31aa | |
parent | d4b7650ee0a6f51b37ee55d887729602573225ad (diff) | |
parent | bba5a89feb232c6aa272a8d993a321765f220685 (diff) | |
download | oslo-config-d8e71b9d10132a9c134ff79a4ecdc77d17d424be.tar.gz |
Merge "fixture: Provide parameter enforce_type for method config"3.12.0
-rw-r--r-- | oslo_config/fixture.py | 5 | ||||
-rw-r--r-- | oslo_config/tests/test_fixture.py | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/oslo_config/fixture.py b/oslo_config/fixture.py index 8e39023..6f047e8 100644 --- a/oslo_config/fixture.py +++ b/oslo_config/fixture.py @@ -58,11 +58,14 @@ class Config(fixtures.Fixture): the specified configuration option group, otherwise the overrides are applied to the ``default`` group. + If a `enforce_type` is supplied, will convert the override + value to the option's type before overriding. """ group = kw.pop('group', None) + enforce_type = kw.pop('enforce_type', False) for k, v in six.iteritems(kw): - self.conf.set_override(k, v, group) + self.conf.set_override(k, v, group, enforce_type=enforce_type) def _unregister_config_opts(self): for group in self._registered_config_opts: diff --git a/oslo_config/tests/test_fixture.py b/oslo_config/tests/test_fixture.py index 1ea3f50..6e2062d 100644 --- a/oslo_config/tests/test_fixture.py +++ b/oslo_config/tests/test_fixture.py @@ -29,6 +29,10 @@ class ConfigTestCase(base.BaseTestCase): config_fixture.setUp() config_fixture.register_opt(cfg.StrOpt( 'testing_option', default='initial_value')) + config_fixture.register_opt(cfg.IntOpt( + 'test2', min=0, default=5)) + config_fixture.register_opt(cfg.StrOpt( + 'test3', choices=['a', 'b'], default='a')) return config_fixture def test_overridden_value(self): @@ -38,6 +42,19 @@ class ConfigTestCase(base.BaseTestCase): self.assertEqual('changed_value', f.conf.get('testing_option')) + def test_overridden_value_with_enforce_type(self): + f = self._make_fixture() + self.assertEqual(5, f.conf.get('test2')) + self.assertEqual('a', f.conf.get('test3')) + # with enforce_type=False + f.config(test2=-1) + self.assertEqual(-1, f.conf.get('test2')) + f.config(test3='c') + self.assertEqual('c', f.conf.get('test3')) + # with enforce_type=True + self.assertRaises(ValueError, f.config, test2=-1, enforce_type=True) + self.assertRaises(ValueError, f.config, test3='c', enforce_type=True) + def test_cleanup(self): f = self._make_fixture() f.config(testing_option='changed_value') |