Add test to cover load_config from dict
@@ -8,6 +8,7 @@ __copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = 'michal.ernst@nokia.com'
import os
+
import pytest
@@ -242,6 +243,75 @@ def test_cannot_load_config_from_when_path_or_from_env_var_not_provide(moler_con
assert "Provide either 'config' or 'from_env_var' parameter (none given)" in str(err.value)
+def test_can_select_device_loaded_from_config_dict(moler_config, device_factory):
+ conn_config = {
+ 'LOGGER': {
+ 'PATH': '/tmp/',
+ 'RAW_LOG': True,
+ 'DATE_FORMAT': '%d %H:%M:%S'
+ },
+ 'DEVICES': {
+ 'UNIX': {
+ 'DEVICE_CLASS': 'moler.device.unixremote.UnixLocal',
+ 'INITIAL_STATE': 'UNIX_LOCAL'
+ }
+ }
+ }
+ moler_config.load_config(config=conn_config, config_type='dict')
+
+ device = device_factory.get_device(name='UNIX')
+
+ assert device.__module__ == 'moler.device.unixlocal'
+ assert device.__class__.__name__ == 'UnixLocal'
+
+
+def test_can_load_configuration_when_already_loaded_from_same_dict(moler_config, device_factory):
+ conn_config = {
+ 'LOGGER': {
+ 'PATH': '/tmp/',
+ 'RAW_LOG': True,
+ 'DATE_FORMAT': '%d %H:%M:%S'
+ },
+ 'DEVICES': {
+ 'UNIX': {
+ 'DEVICE_CLASS': 'moler.device.unixremote.UnixLocal',
+ 'INITIAL_STATE': 'UNIX_LOCAL'
+ }
+ }
+ }
+ moler_config.load_config(config=conn_config, config_type='dict')
+ moler_config.load_config(config=conn_config, config_type='dict')
+
+ device = device_factory.get_device(name='UNIX')
+
+ assert device.__module__ == 'moler.device.unixlocal'
+ assert device.__class__.__name__ == 'UnixLocal'
+
+
+def test_cannot_load_configuration_when_already_loaded_from_another_dict(moler_config):
+ conn_config = {
+ 'LOGGER': {
+ 'PATH': '/tmp/',
+ 'RAW_LOG': True,
+ 'DATE_FORMAT': '%d %H:%M:%S'
+ },
+ 'DEVICES': {
+ 'UNIX': {
+ 'DEVICE_CLASS': 'moler.device.unixremote.UnixLocal',
+ 'INITIAL_STATE': 'UNIX_LOCAL'
+ }
+ }
+ }
+ moler_config.load_config(config=conn_config, config_type='dict')
+
+ from moler.exceptions import MolerException
+
+ with pytest.raises(MolerException) as err:
+ moler_config.load_config(config={}, config_type='dict')
+
+ assert "Reload configuration under one Moler execution not supported!" in str(err.value)
+
+
# --------------------------- resources ---------------------------
@pytest.yield_fixture
