mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 11:04:01 +03:00
Patch Configuration provider to raise AttributeError for special attributes
This commit is contained in:
parent
f8960ddacb
commit
7cb3310c5d
File diff suppressed because it is too large
Load Diff
|
@ -641,11 +641,17 @@ cdef class Configuration(Provider):
|
||||||
"""
|
"""
|
||||||
return represent_provider(provider=self, provides=self.__name)
|
return represent_provider(provider=self, provides=self.__name)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, str name):
|
||||||
"""Return child configuration provider."""
|
"""Return child configuration provider."""
|
||||||
cdef Configuration child_provider
|
cdef Configuration child_provider
|
||||||
cdef object value
|
cdef object value
|
||||||
|
|
||||||
|
if name.startswith('__'):
|
||||||
|
raise AttributeError(
|
||||||
|
'\'{cls}\' object has no attribute '
|
||||||
|
'\'{attribute_name}\''.format(cls=self.__class__.__name__,
|
||||||
|
attribute_name=name))
|
||||||
|
|
||||||
child_provider = self.__children.get(name)
|
child_provider = self.__children.get(name)
|
||||||
|
|
||||||
if child_provider is None:
|
if child_provider is None:
|
||||||
|
|
|
@ -63,6 +63,15 @@ class ConfigTests(unittest.TestCase):
|
||||||
def test_value_of_undefined_option(self):
|
def test_value_of_undefined_option(self):
|
||||||
self.assertIsNone(self.config.a())
|
self.assertIsNone(self.config.a())
|
||||||
|
|
||||||
|
def test_getting_of_special_attributes(self):
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
self.config.__name__
|
||||||
|
|
||||||
|
def test_getting_of_special_attributes_from_child(self):
|
||||||
|
a = self.config.a
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
a.__name__
|
||||||
|
|
||||||
def test_deepcopy(self):
|
def test_deepcopy(self):
|
||||||
provider = providers.Configuration('config')
|
provider = providers.Configuration('config')
|
||||||
provider_copy = providers.deepcopy(provider)
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user