report the correct location for an option updated with set_defaults()
Change-Id: Ida9259b56f3f293d9f3cc6848051ab6895310c25 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
a9625c78d3
commit
4010c4b002
|
@ -808,6 +808,7 @@ def set_defaults(opts, **kwargs):
|
||||||
for opt in opts:
|
for opt in opts:
|
||||||
if opt.dest in kwargs:
|
if opt.dest in kwargs:
|
||||||
opt.default = kwargs[opt.dest]
|
opt.default = kwargs[opt.dest]
|
||||||
|
opt._set_location = LocationInfo(Locations.set_default, '')
|
||||||
|
|
||||||
|
|
||||||
def _normalize_group_name(group_name):
|
def _normalize_group_name(group_name):
|
||||||
|
@ -957,6 +958,7 @@ class Opt(object):
|
||||||
self.deprecated_reason = deprecated_reason
|
self.deprecated_reason = deprecated_reason
|
||||||
self.deprecated_since = deprecated_since
|
self.deprecated_since = deprecated_since
|
||||||
self._logged_deprecation = False
|
self._logged_deprecation = False
|
||||||
|
self._set_location = LocationInfo(Locations.opt_default, '')
|
||||||
|
|
||||||
self.deprecated_opts = copy.deepcopy(deprecated_opts) or []
|
self.deprecated_opts = copy.deepcopy(deprecated_opts) or []
|
||||||
for o in self.deprecated_opts:
|
for o in self.deprecated_opts:
|
||||||
|
@ -2972,6 +2974,7 @@ class ConfigOpts(collections.Mapping):
|
||||||
|
|
||||||
info = self._get_opt_info(name, group)
|
info = self._get_opt_info(name, group)
|
||||||
opt = info['opt']
|
opt = info['opt']
|
||||||
|
loc = opt._set_location
|
||||||
|
|
||||||
if isinstance(opt, SubCommandOpt):
|
if isinstance(opt, SubCommandOpt):
|
||||||
return (self.SubCommandAttr(self, group, opt.dest), None)
|
return (self.SubCommandAttr(self, group, opt.dest), None)
|
||||||
|
@ -3016,8 +3019,7 @@ class ConfigOpts(collections.Mapping):
|
||||||
% (opt.name, str(e)))
|
% (opt.name, str(e)))
|
||||||
|
|
||||||
if opt.default is not None:
|
if opt.default is not None:
|
||||||
return (convert(opt.default),
|
return (convert(opt.default), loc)
|
||||||
LocationInfo(Locations.opt_default, ''))
|
|
||||||
|
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,15 @@ class GetLocationTestCase(base.BaseTestCase):
|
||||||
loc.location,
|
loc.location,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_set_defaults_func(self):
|
||||||
|
cfg.set_defaults([self.normal_opt], normal_opt=self.id())
|
||||||
|
self.conf([])
|
||||||
|
loc = self.conf.get_location('normal_opt')
|
||||||
|
self.assertEqual(
|
||||||
|
cfg.Locations.set_default,
|
||||||
|
loc.location,
|
||||||
|
)
|
||||||
|
|
||||||
def test_set_override(self):
|
def test_set_override(self):
|
||||||
self.conf.set_override('normal_opt', self.id())
|
self.conf.set_override('normal_opt', self.id())
|
||||||
self.conf([])
|
self.conf([])
|
||||||
|
|
Loading…
Reference in New Issue