Patch Configuration provider to raise AttributeError for special attributes

This commit is contained in:
Roman Mogilatov 2017-03-28 23:50:22 +03:00
parent f8960ddacb
commit 7cb3310c5d
3 changed files with 1295 additions and 1065 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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:

View File

@ -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)