Skip to content

Commit

Permalink
add test_config
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Apr 24, 2022
1 parent db1a1db commit 250fded
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dali2mqtt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def load_config_file(self):
)
configuration = {}
self._config = CONF_SCHEMA(configuration)
self._callback()
if self._callback:
self._callback()
except AttributeError:
# No callback configured
pass
Expand All @@ -111,8 +112,8 @@ def load_config_file(self):
def save_config_file(self):
"""Save configuration back to yaml file."""
try:
cfg = self._config.pop(CONF_CONFIG) # temporary displace config file
with open(self._path, "w", encoding="utf8") as outfile:
cfg = self._config.pop(CONF_CONFIG) # temporary displace config file
yaml.dump(
self._config, outfile, default_flow_style=False, allow_unicode=True
)
Expand Down
Empty file added tests/data/config.yaml
Empty file.
17 changes: 17 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Tests for config."""

from dali2mqtt.config import Config
from unittest import mock

def test_load_config():
args = mock.Mock()
args.config = "tests/data/config.yaml"

cfg = Config(args)

assert cfg.mqtt_conf == ('localhost', 1883, None, None, 'dali2mqtt')
assert cfg,dali_driver == "hasseb"
assert cfg.ha_discovery_prefix == "homeassistant"
assert cfg.log_level == "info"
assert cfg.log_color == False
assert cfg.devices_names_file == "devices.yaml"

0 comments on commit 250fded

Please sign in to comment.