Files
Shortumation/api/tests/unittests/automations_v2/test_watchers_config.py
T
2022-08-14 15:31:42 -04:00

38 lines
1.3 KiB
Python

from src.automations_v2.watchers.config import ConfigFileWatcher
from .utils import TestWithDB, make_temp_db
from tests.utils import (
HA_CONFIG_EXAMPLE,
HA_CONFIG2_EXAMPLE,
HA_CONFIG3_EXAMPLE,
HA_CONFIG4_EXAMPLE,
HA_CONFIG5_EXAMPLE,
HA_CONFIG6_EXAMPLE,
create_copy_of_example_config,
)
class config_watcher_tests(TestWithDB):
def test_simple_config_loading(self):
for p, count in [
(HA_CONFIG_EXAMPLE, 32),
(HA_CONFIG2_EXAMPLE, 1),
(HA_CONFIG3_EXAMPLE, 1032),
(HA_CONFIG4_EXAMPLE, 3),
(HA_CONFIG5_EXAMPLE, 10),
(HA_CONFIG6_EXAMPLE, 12),
]:
with self.subTest(config=p.name):
db = make_temp_db()
db.reset()
config_path = create_copy_of_example_config(p)
config_watcher = ConfigFileWatcher(
config_path=config_path,
automation_db_path=db.db_file,
)
self.assertEqual(db.count_automations(), 0)
config_watcher.start()
self.assertEqual(config_watcher.wait_until_next_event(True), "loaded")
self.assertEqual(db.count_automations(), count)
config_watcher.join()