Esempio n. 1
0
def test_reloads():
    ALL.clear()
    ALL['name1'] = f1 = HABAppFile(
        'name1', 'path1', FileProperties(reloads_on=['name2', 'asdf']))
    ALL['name2'] = f2 = HABAppFile('name2', 'path2', FileProperties())

    f1.check_properties()
    assert f1.properties.reloads_on == ['name2', 'asdf']
    assert f2.properties.reloads_on == []
Esempio n. 2
0
def test_deps():
    ALL.clear()
    ALL['name1'] = f1 = HABAppFile('name1', 'path1',
                                   FileProperties(depends_on=['name2']))
    ALL['name2'] = f2 = HABAppFile('name2', 'path2', FileProperties())

    f1.check_properties()
    f2.check_properties()

    assert f2.can_be_loaded()
    assert not f1.can_be_loaded()

    f2.is_loaded = True
    assert f1.can_be_loaded()
Esempio n. 3
0
def test_reload_dep(monkeypatch):
    monkeypatch.setattr(HABAppFile, 'from_path', from_path)
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'rules',
                        Path('/my_rules/'))
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'config',
                        Path('/my_config/'))
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'param',
                        Path('/my_param/'))

    order = []

    def process_event(event):
        order.append(event.name)
        file_load_ok(event.name)

    FILE_PROPS.clear()
    FILE_PROPS['params/param1'] = FileProperties(depends_on=['params/param2'],
                                                 reloads_on=['params/param2'])
    FILE_PROPS['params/param2'] = FileProperties()

    with SyncWorker() as sync:
        sync.listen_events(HABApp.core.const.topics.FILES, process_event)

        process([MockFile('param2'), MockFile('param1')])

        assert order == ['params/param2', 'params/param1']
        order.clear()

        process([])
        assert order == []

        process([MockFile('param2')])
        assert order == ['params/param2', 'params/param1']
        order.clear()

        process([MockFile('param1')])
        assert order == ['params/param1']
        order.clear()

        process([MockFile('param2')])
        assert order == ['params/param2', 'params/param1']
        order.clear()
Esempio n. 4
0
def test_missing_dependencies(monkeypatch, caplog):
    monkeypatch.setattr(HABAppFile, 'from_path', from_path)
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'rules',
                        Path('/my_rules/'))
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'config',
                        Path('/my_config/'))
    monkeypatch.setattr(HABApp.config.CONFIG.directories, 'param',
                        Path('/my_param/'))

    order = []

    def process_event(event):
        order.append(event.name)
        file_load_ok(event.name)

    FILE_PROPS['params/param1'] = FileProperties(
        depends_on=['params/param4', 'params/param5'])
    FILE_PROPS['params/param2'] = FileProperties(depends_on=['params/param4'])
    FILE_PROPS['params/param3'] = FileProperties()

    with SyncWorker() as sync:
        sync.listen_events(HABApp.core.const.topics.FILES, process_event)

        process([MockFile('param1'), MockFile('param2'), MockFile('param3')])

        assert order == ['params/param3']
        order.clear()

        process([])
        assert order == []

        msg1 = (
            'HABApp.files', logging.ERROR,
            "File <MockFile param2> depends on file that doesn't exist: params/param4"
        )
        msg2 = (
            'HABApp.files', logging.ERROR,
            "File <MockFile param1> depends on files that don't exist: params/param4, params/param5"
        )

        assert msg1 in caplog.record_tuples
        assert msg2 in caplog.record_tuples
Esempio n. 5
0
def test_circ():
    ALL.clear()
    ALL['name1'] = f1 = HABAppFile('name1', 'path1',
                                   FileProperties(depends_on=['name2']))
    ALL['name2'] = f2 = HABAppFile('name2', 'path2',
                                   FileProperties(depends_on=['name3']))
    ALL['name3'] = f3 = HABAppFile('name3', 'path3',
                                   FileProperties(depends_on=['name1']))

    with pytest.raises(CircularReferenceError) as e:
        f1.check_properties()
    assert str(e.value) == "name1 -> name2 -> name3 -> name1"

    with pytest.raises(CircularReferenceError) as e:
        f2.check_properties()
    assert str(e.value) == "name2 -> name3 -> name1 -> name2"

    with pytest.raises(CircularReferenceError) as e:
        f3.check_properties()
    assert str(e.value) == "name3 -> name1 -> name2 -> name3"