def test_included_node_is_merged(self): mock_test = mock.Mock() mock_cnfg = mock.Mock() cnfgr = ConfigLoader() cnfgr._map = {'.test': mock_test, '.cnfg': mock_cnfg} cnfgr._load_file = mock.Mock(side_effect=[ { # data from /folder/config.cnfg 'api': { '!include': 'secrets.test', '!include_node': 'object1', 'channel': 5 }, 'name': 'wayne' }, { # data from secrets.test 'object1': { 'secret': 'ssshh' }, 'object2': { 'secret': 'password1' } } ]) cfg_data = cnfgr.load_config_file('/folder/config.cnfg') assert cfg_data == { 'api': { 'secret': 'ssshh', 'channel': 5 }, 'name': 'wayne' }
def test_includes_are_merged(self): mock_test = mock.Mock() mock_cnfg = mock.Mock() cnfgr = ConfigLoader() cnfgr._map = {'.test': mock_test, '.cnfg': mock_cnfg} cnfgr._load_file = mock.Mock(side_effect=[ { # data from /folder/config.cnfg 'api': { '!include': 'secrets.test', 'channel': 5 }, 'name': 'wayne' }, { # data from secrets.test 'secret': 'ssshh' } ]) cfg_data = cnfgr.load_config_file('/folder/config.cnfg') assert cfg_data == { 'api': { 'secret': 'ssshh', 'channel': 5 }, 'name': 'wayne' } cnfgr._load_file.assert_has_calls([ mock.call('/folder/config.cnfg', mock_cnfg), mock.call('secrets.test', mock_test) ])
def test_rasies_when_included_node_is_missing(self): mock_test = mock.Mock() mock_cnfg = mock.Mock() cnfgr = ConfigLoader() cnfgr._map = {'.test': mock_test, '.cnfg': mock_cnfg} cnfgr._load_file = mock.Mock(side_effect=[ { # data from /folder/config.cnfg 'api': { '!include': 'secrets.test', '!include_node': 'object1', 'channel': 5 }, 'name': 'wayne' }, { # data from secrets.test 'object2': { 'secret': 'password1' } } ]) with pytest.raises(KeyError): cfg_data = cnfgr.load_config_file('/folder/config.cnfg')
def test_can_read_empty_json_file(self): test_data = {} cnfgr = ConfigLoader() mock_file = mock.mock_open(read_data=json.dumps(test_data)) with mock.patch('builtins.open', mock_file): cfg_data = cnfgr.load_config_file('config.json') assert cfg_data == test_data
def test_can_read_yaml_config_file(self): test_data = {'name': 'test_thing', 'key': 'ABCDEFGHIJ', 'feed': {'field1': 'A'}} read_data = yaml.dump(test_data) cnfgr = ConfigLoader() mock_file = mock.mock_open(read_data=read_data) with mock.patch('builtins.open', mock_file): cfg_data = cnfgr.load_config_file('config.yaml') assert cfg_data == test_data
def test_selects_correct_loader(self): mock_test = mock.Mock() mock_cnfg = mock.Mock() cnfgr = ConfigLoader() cnfgr._map = {'.test': mock_test, '.cnfg': mock_cnfg} cnfgr._load_file = mock.Mock(return_value={}) cfg_data = cnfgr.load_config_file('/folder/config.cnfg') assert cfg_data == {} cnfgr._load_file.assert_called_once_with('/folder/config.cnfg', mock_cnfg)
from sensormesh.application import Controller from sensormesh.sources import DataSourceWrapper from sensormesh.console import ConsoleDisplay from sensormesh.thingspeak import ThingSpeakLogger from sensormesh.text import TextLogger from sensormesh.twitter import TwitterUpdate # Configure logging with open('conf_logging.yaml', 'r') as f: log_config = yaml.load(f) log_config['disable_existing_loggers'] = False logging.config.dictConfig(log_config) # Configuration loader class cfgr = ConfigLoader() config = cfgr.load_config_file('conf_therm.yaml') # Configure App app = Controller() tgr_config = config['trigger'] app.set_steps(**tgr_config) # Source o = W1ThermSensor() print(o) s = DataSourceWrapper( fields=['temperature'], source=o.get_temperature, name=str(o)
from sensormesh.sources import DataSourceWrapper from sensormesh.console import ConsoleDisplay from sensormesh.thingspeak import ThingSpeakLogger from sensormesh.text import TextLogger # from sensormesh.twitter import TwitterUpdate # Configure logging with open("conf_logging.yaml", "r") as f: log_config = yaml.load(f) log_config["disable_existing_loggers"] = False logging.config.dictConfig(log_config) # Configuration loader class cfgr = ConfigLoader() config = cfgr.load_config_file("conf_random.yaml") # Configure App app = Controller() tgr_config = config["trigger"] app.set_steps(**tgr_config) # Source 1 s = DataSourceWrapper(source=random.random, name="rand 1", fields=("value1",)) app.add_source(s) # Source 2 s = DataSourceWrapper(source=random.random, name="rand 2", fields=("value2",)) app.add_source(s)
from sensormesh.application import Controller from sensormesh.sources import DataSourceWrapper from sensormesh.console import ConsoleDisplay from sensormesh.thingspeak import ThingSpeakLogger from sensormesh.text import TextLogger # from sensormesh.twitter import TwitterUpdate # Configure logging with open('conf_logging.yaml', 'r') as f: log_config = yaml.load(f) log_config['disable_existing_loggers'] = False logging.config.dictConfig(log_config) # Configuration loader class cfgr = ConfigLoader() config = cfgr.load_config_file('conf_random.yaml') # Configure App app = Controller() tgr_config = config['trigger'] app.set_steps(**tgr_config) # Source 1 s = DataSourceWrapper(source=random.random, name='rand 1', fields=('value1',)) app.add_source(s) # Source 2 s = DataSourceWrapper(source=random.random, name='rand 2', fields=('value2',)) app.add_source(s)