Example #1
0
def test_property_illegal_push(context_mock):
    prop_no_push = Property(name=DEFAULT_PROPERTY_NAME,
                            default_value=DEFAULT_PROPERTY_VALUE,
                            allow_push=False)
    prop_no_push.set_parent_path(DEFAULT_MODULE_NAME)
    wrapper = PropertyWrapper(prop=prop_no_push,
                              ctx=context_mock,
                              allow_read=True,
                              allow_write=True)
    with LogCapture(attributes=strip_prefix) as log_capture:
        assert not wrapper.push(child=Property(name=CHILD_PROPERTY_NAME))
        log_capture.check(
            f'Unauthorized push in property {DEFAULT_MODULE_NAME}:{DEFAULT_PROPERTY_NAME}!',
        )
Example #2
0
def test_property_child(under_test_read_write: PropertyWrapper,
                        default_property_base, context_mock):
    assert under_test_read_write.push(
        Property(name=CHILD_PROPERTY_NAME,
                 default_value=DEFAULT_PROPERTY_VALUE))
    assert list(under_test_read_write.enum())[0] == CHILD_PROPERTY_ID
    assert under_test_read_write.prop.children[CHILD_PROPERTY_NAME].read(
    ) == DEFAULT_PROPERTY_VALUE
Example #3
0
def test_flag_property(context_mock):
    prop_base = Property(name="flag_prop", is_flag_property=True)
    prop_base.set_parent_path(DEFAULT_MODULE_NAME)
    prop_wrapper = PropertyWrapper(prop=prop_base,
                                   ctx=context_mock,
                                   allow_read=True,
                                   allow_write=True)
    assert (prop_base._lock.locked())

    prop_wrapper.set(True)
    assert (prop_wrapper.get() is True)
    context_mock.emit.assert_any_call(
        SignalRef(f"{prop_wrapper.prop.id()}:changed"),
        parents=None,
        wipe=True,
        payload=True,
        boring=False)
    context_mock.emit.assert_any_call(
        SignalRef(f"{prop_wrapper.prop.id()}:true"),
        parents=None,
        wipe=True,
        boring=False)

    context_mock.emit.reset_mock()
    prop_wrapper.set(False)
    assert (prop_wrapper.get() is False)
    context_mock.emit.assert_any_call(
        SignalRef(f"{prop_wrapper.prop.id()}:changed"),
        parents=None,
        wipe=True,
        payload=False,
        boring=False)
    context_mock.emit.assert_any_call(
        SignalRef(f"{prop_wrapper.prop.id()}:false"),
        parents=None,
        wipe=True,
        boring=False)

    context_mock.emit.reset_mock()
    prop_wrapper.set(None)
    assert (prop_wrapper.get() is None)
    context_mock.emit.assert_called_once_with(
        SignalRef(f"{prop_wrapper.prop.id()}:changed"),
        parents=None,
        wipe=True,
        payload=None,
        boring=False)
Example #4
0
def default_property_base():
    prop = Property(name=DEFAULT_PROPERTY_NAME,
                    default_value=DEFAULT_PROPERTY_VALUE)
    prop.set_parent_path(DEFAULT_MODULE_NAME)
    return prop
Example #5
0
CORE_MODULE_CONFIG = {IMPORT_MODULES_CONFIG_KEY: [], TICK_RATE_CONFIG_KEY: 20}

with Module(name="core", config=CORE_MODULE_CONFIG) as core_module:
    """
    The startup signal, which is fired once when `Context.run()` is executed.
    """
    sig_startup = Signal("startup")
    """
    The shutdown signal, which is fired once when `Context.shutdown()` is called.
    """
    sig_shutdown = Signal("shutdown")

    prop_pressure = Property(name="pressure",
                             allow_read=True,
                             allow_write=True,
                             allow_push=False,
                             allow_pop=False,
                             default_value=False,
                             always_signal_changed=False,
                             is_flag_property=True)

    prop_activity = Property(name="activity",
                             allow_read=True,
                             allow_write=True,
                             allow_push=False,
                             allow_pop=False,
                             default_value=0,
                             always_signal_changed=False,
                             boring=True)


def create_and_run_context(*args, runtime_overrides=None):