Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bound_config(self):
config = ConfigManager.from_dict({"foo": 12345})
class ComponentA(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option("foo", parser=int)
required_config.add_option("bar", parser=int, default="1")
def __init__(self, config):
self.config = config.with_options(self)
comp = ComponentA(config)
assert list(comp.get_runtime_config()) == [
([], "foo", "12345", Option(key="foo", parser=int)),
([], "bar", "1", Option(key="bar", parser=int, default="1")),
]
def __init__(self, config):
self.config = config.with_options(self)
self.comp = ComponentB(config.with_namespace("biff"))
def get_runtime_config(self, namespace=None):
for item in super(ComponentA, self).get_runtime_config(namespace):
yield item
for item in self.comp.get_runtime_config(["biff"]):
yield item
comp = ComponentA(config)
assert list(comp.get_runtime_config()) == [
([], "baz", "abc", Option(key="baz", default="abc")),
(["biff"], "foo", "2", Option(key="foo", parser=int, default="2")),
(["biff"], "bar", "1", Option(key="bar", parser=int, default="1")),
]
def test_bound_config(self):
config = ConfigManager.from_dict({"foo": 12345})
class ComponentA(RequiredConfigMixin):
required_config = ConfigOptions()
required_config.add_option("foo", parser=int)
required_config.add_option("bar", parser=int, default="1")
def __init__(self, config):
self.config = config.with_options(self)
comp = ComponentA(config)
assert list(comp.get_runtime_config()) == [
([], "foo", "12345", Option(key="foo", parser=int)),
([], "bar", "1", Option(key="bar", parser=int, default="1")),
]
self.config = config.with_options(self)
self.comp = ComponentB(config.with_namespace("biff"))
def get_runtime_config(self, namespace=None):
for item in super(ComponentA, self).get_runtime_config(namespace):
yield item
for item in self.comp.get_runtime_config(["biff"]):
yield item
comp = ComponentA(config)
assert list(comp.get_runtime_config()) == [
([], "baz", "abc", Option(key="baz", default="abc")),
(["biff"], "foo", "2", Option(key="foo", parser=int, default="2")),
(["biff"], "bar", "1", Option(key="bar", parser=int, default="1")),
]
def __eq__(self, obj):
return (
isinstance(obj, Option)
and obj.key == self.key
and obj.default == self.default
and obj.alternate_keys == self.alternate_keys
and obj.doc == self.doc
and obj.parser == self.parser
and obj.meta == self.meta
)
:arg default: the default value (if any); must be a string that is
parseable by the specified parser
:arg alternate_keys: the list of alternate keys to look up;
supports a ``root:`` key prefix which will cause this to look at
the configuration root rather than the current namespace
:arg doc: documentation for this config option
:arg parser: the parser for converting this value to a Python object
:arg meta: catch-all for other key/value pairs you want to association
with this option
"""
option = Option(
key=key,
default=default,
alternate_keys=alternate_keys,
doc=doc,
parser=parser,
meta=meta,
)
self.options[key] = option