Skip to content

Commit

Permalink
Added comparators parameter to ConfigFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
Erez Eshkol committed Jan 3, 2018
1 parent d24dd47 commit c69ec4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
16 changes: 14 additions & 2 deletions staticconf/config.py
Expand Up @@ -582,7 +582,14 @@ def __init__(self, watcher):
self.callback_chain = watcher.get_reloader()

@classmethod
def load(cls, filename, namespace, loader_func, min_interval=0):
def load(
cls,
filename,
namespace,
loader_func,
min_interval=0,
comparators=None,
):
"""Create a new :class:`ConfigurationWatcher` and load the initial
configuration by calling `loader_func`.
Expand All @@ -597,13 +604,18 @@ def load(cls, filename, namespace, loader_func, min_interval=0):
:param min_interval: minimum number of seconds to wait between calls to
:func:`os.path.getmtime` to check if a file has
been modified.
:param comparators: a list of classes which support the
:class:`IComparator` interface which are used to determine if a config
file has been modified. See ConfigurationWatcher::__init__.
:returns: a :class:`ConfigFacade`
"""
watcher = ConfigurationWatcher(
build_loader_callable(loader_func, filename, namespace=namespace),
filename,
min_interval=min_interval,
reloader=ReloadCallbackChain(namespace=namespace))
reloader=ReloadCallbackChain(namespace=namespace),
comparators=comparators,
)
watcher.load_config()
return cls(watcher)

Expand Down
2 changes: 1 addition & 1 deletion staticconf/version.py
@@ -1,2 +1,2 @@

version = "0.10.3"
version = "0.10.4"
12 changes: 12 additions & 0 deletions tests/config_test.py
Expand Up @@ -598,6 +598,18 @@ def test_load(self):
reloader = facade.callback_chain
assert_equal(reloader, facade.watcher.get_reloader())

def test_load_passes_comparators_to_configuration_watcher(self):
filename, namespace = "filename", "namespace"
loader = mock.Mock()
comparator = mock.Mock(name='MockComparator')

with mock.patch(
'staticconf.config.ConfigurationWatcher',
autospec=True
) as mock_watcher_class:
config.ConfigFacade.load(filename, namespace, loader, comparators=[comparator])
mock_watcher_class.assert_called_with(mock.ANY, filename, min_interval=mock.ANY, reloader=mock.ANY, comparators=[comparator])

def test_add_callback(self):
name, func = 'name', mock.Mock()
self.facade.add_callback(name, func)
Expand Down

0 comments on commit c69ec4a

Please sign in to comment.