Merge branch 'release/3.5.0' into master

This commit is contained in:
Roman Mogilatov 2017-07-07 18:06:29 +03:00
commit 73f34b66be
6 changed files with 1291 additions and 1222 deletions

View File

@ -60,7 +60,7 @@ check:
publish: cythonize publish: cythonize
# Merge release to master branch # Merge release to master branch
git checkout master git checkout master
git merge --no-ff release/$(VERSION) -m 'Merge branch release/$(VERSION)' git merge --no-ff release/$(VERSION) -m "Merge branch 'release/$(VERSION)' into master"
git push origin master git push origin master
# Create and upload tag # Create and upload tag
git tag -a $(VERSION) -m 'version $(VERSION)' git tag -a $(VERSION) -m 'version $(VERSION)'

View File

@ -7,9 +7,10 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_ follows `Semantic versioning`_
Development version 3.5.0
------------------- -----
- No features. - Add functionality for initializing ``Configuration`` provider with default
values.
3.4.8 3.4.8
----- -----

View File

@ -1,6 +1,6 @@
"""Dependency injector top-level package.""" """Dependency injector top-level package."""
__version__ = '3.4.8' __version__ = '3.5.0'
"""Version number that follows semantic versioning. """Version number that follows semantic versioning.
:type: str :type: str

File diff suppressed because it is too large Load Diff

View File

@ -667,15 +667,20 @@ cdef class Configuration(Provider):
print(config.section1.option2()) # 2 print(config.section1.option2()) # 2
""" """
def __init__(self, name): def __init__(self, name, default=None):
"""Initializer. """Initializer.
:param name: Name of configuration unit. :param name: Name of configuration unit.
:type name: str :type name: str
:param default: Default values of configuration unit.
:type default: dict
""" """
self.__name = name self.__name = name
self.__value = None self.__value = None
self.__children = dict() self.__children = dict()
if default is not None:
self.update(default)
super(Configuration, self).__init__() super(Configuration, self).__init__()
def __deepcopy__(self, memo): def __deepcopy__(self, memo):

View File

@ -60,6 +60,21 @@ class ConfigTests(unittest.TestCase):
self.assertEqual(abc(), 1) self.assertEqual(abc(), 1)
self.assertEqual(abd(), 2) self.assertEqual(abd(), 2)
def test_providers_with_default_value(self):
self.config = providers.Configuration(
name='config', default={'a': {'b': {'c': 1, 'd': 2}}})
a = self.config.a
ab = self.config.a.b
abc = self.config.a.b.c
abd = self.config.a.b.d
self.assertEqual(a(), {'b': {'c': 1, 'd': 2}})
self.assertEqual(ab(), {'c': 1, 'd': 2})
self.assertEqual(abc(), 1)
self.assertEqual(abd(), 2)
def test_value_of_undefined_option(self): def test_value_of_undefined_option(self):
self.assertIsNone(self.config.a()) self.assertIsNone(self.config.a())