Merge "Make set_override/set_default with enforce_type=True by default"

This commit is contained in:
Jenkins 2017-04-10 04:19:02 +00:00 committed by Gerrit Code Review
commit 827bd738dc
3 changed files with 17 additions and 34 deletions

@ -455,7 +455,6 @@ import os
import string
import sys
import debtcollector
from debtcollector import removals
import six
@ -2609,8 +2608,12 @@ class ConfigOpts(collections.Mapping):
__import__(module_str)
self._get_group(group)
@removals.removed_kwarg('enforce_type', "The argument enforce_type has "
"changed its default value to True and then will"
" be removed completely.",
version='3.24', removal_version='4.0')
@__clear_cache
def set_override(self, name, override, group=None, enforce_type=False):
def set_override(self, name, override, group=None, enforce_type=True):
"""Override an opt value.
Override the command line, config file and default values of a
@ -2628,8 +2631,12 @@ class ConfigOpts(collections.Mapping):
opt_info['override'] = self._get_enforced_type_value(
opt_info['opt'], override, enforce_type)
@removals.removed_kwarg('enforce_type', "The argument enforce_type has "
"changed its default value to True and then will"
" be removed completely.",
version='3.24', removal_version='4.0')
@__clear_cache
def set_default(self, name, default, group=None, enforce_type=False):
def set_default(self, name, default, group=None, enforce_type=True):
"""Override an opt's default value.
Override the default value of given option. A command line or
@ -2655,13 +2662,6 @@ class ConfigOpts(collections.Mapping):
except (ValueError, TypeError):
if enforce_type:
raise
debtcollector.deprecate(
"The argument enforce_type is changing its "
"default value to True and then will be removed completely, "
"please fix the invalid %s value '%s' for option '%s'."
% (repr(opt.type), value, opt.name),
version=4.0
)
if enforce_type:
return converted
else:

@ -3134,20 +3134,12 @@ class OverridesTestCase(BaseTestCase):
self.conf.clear_default('foo')
self.assertEqual('foo', self.conf.foo)
@mock.patch('debtcollector.deprecate')
def test_deprecation_wrong_type_default(self, deprecate):
def test_enforce_type_wrong_type_default(self):
self.conf.register_opt(cfg.IntOpt('foo', default=1))
self.conf([])
self.assertEqual(1, self.conf.foo)
self.conf.set_default('foo', "not_really_a_int")
self.assertEqual('not_really_a_int', self.conf.foo)
self.conf.clear_default('foo')
self.assertEqual(1, self.conf.foo)
deprecate.assert_called_once_with(
"The argument enforce_type is changing its default value to True "
"and then will be removed completely, please fix the invalid "
"Integer value 'not_really_a_int' for option 'foo'.",
version=4.0)
self.assertRaises(ValueError, self.conf.set_default,
'foo', 'not_really_a_int')
def test_override(self):
self.conf.register_opt(cfg.StrOpt('foo'))
@ -3235,19 +3227,10 @@ class OverridesTestCase(BaseTestCase):
self.conf.clear_override('foo')
self.assertIsNone(self.conf.foo)
@mock.patch('debtcollector.deprecate')
def test_deprecation_wrong_type_override(self, deprecate):
def test_enforce_type_wrong_type_override(self):
self.conf.register_opt(cfg.IntOpt('foo'))
self.conf.set_override('foo', "not_really_a_int")
self.conf([])
self.assertEqual('not_really_a_int', self.conf.foo)
self.conf.clear_override('foo')
self.assertIsNone(self.conf.foo)
deprecate.assert_called_once_with(
"The argument enforce_type is changing its default value to True "
"and then will be removed completely, please fix the invalid "
"Integer value 'not_really_a_int' for option 'foo'.",
version=4.0)
self.assertRaises(ValueError, self.conf.set_override,
'foo', "not_really_a_int")
def test_set_override_in_choices(self):
self.conf.register_group(cfg.OptGroup('f'))

@ -1164,7 +1164,7 @@ class GeneratorRaiseErrorTestCase(base.BaseTestCase):
fake_ep = FakeEP()
self.conf = cfg.ConfigOpts()
self.conf.register_opts(generator._generator_opts)
self.conf.set_default('namespace', fake_ep.name)
self.conf.set_default('namespace', [fake_ep.name])
fake_eps = mock.Mock(return_value=[fake_ep])
with mock.patch('pkg_resources.iter_entry_points', fake_eps):
self.assertRaises(FakeException, generator.generate, self.conf)