Example #1
0
 def _update_core_properties(self, debug=False):
     with self._lock:
         pressured_acts = []
         partially_fulfilled_acts = []
         for act in self._state_activations():
             if self[":activity"].changed_signal() not in set(act.constraint.signals()):
                 if act.is_pressured():
                     pressured_acts.append(act.id)
                 if act.spiky():
                     partially_fulfilled_acts.append(act)
     PropertyWrapper(
         prop=self[":pressure"],
         ctx=self,
         allow_write=True,
         allow_read=True
     ).set(len(pressured_acts) > 0)
     PropertyWrapper(
         prop=self[":activity"],
         ctx=self,
         allow_write=True,
         allow_read=True
     ).set(len(partially_fulfilled_acts) > 0)
     if debug:
         partially_fulfilled_info = "; ".join(
             f"{act} -> {', '.join(repr(spike) for spike in act.spikes())}"
             for act in partially_fulfilled_acts)
         if partially_fulfilled_info:
             logger.info(partially_fulfilled_info)
Example #2
0
def test_flag_property(context_mock):
    prop_base = PropertyBase(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(s(f"{prop_wrapper.prop.id()}:changed"),
                                      parents=None,
                                      wipe=True)
    context_mock.emit.assert_any_call(s(f"{prop_wrapper.prop.id()}:true"),
                                      parents=None,
                                      wipe=True)

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

    context_mock.emit.reset_mock()
    prop_wrapper.set(None)
    assert (prop_wrapper.get() is None)
    context_mock.emit.assert_called_once_with(
        s(f"{prop_wrapper.prop.id()}:changed"), parents=None, wipe=True)
Example #3
0
 def _update_core_properties(self):
     with self._lock:
         pressured_acts = False
         partially_fulfilled_acts = 0
         for act in self._state_activations():
             if self[":activity"].changed_signal() not in set(act.constraint.signals()):
                 pressured_acts |= act.is_pressured()
                 partially_fulfilled_acts += act.spiky()
     PropertyWrapper(
         prop=self[":pressure"],
         ctx=self,
         allow_write=True,
         allow_read=True
     ).set(pressured_acts)
     PropertyWrapper(
         prop=self[":activity"],
         ctx=self,
         allow_write=True,
         allow_read=True
     ).set(partially_fulfilled_acts)
Example #4
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 #5
0
def under_test_read_write(default_property_base, context_mock):
    return PropertyWrapper(prop=default_property_base,
                           ctx=context_mock,
                           allow_read=True,
                           allow_write=True)
Example #6
0
def under_test_nothing(default_property_base, context_mock):
    return PropertyWrapper(prop=default_property_base,
                           ctx=context_mock,
                           allow_read=False,
                           allow_write=False)