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)
def test_property_no_read(under_test_nothing: PropertyWrapper, default_property_base: Property): assert (not default_property_base._lock.locked()) with LogCapture(attributes=strip_prefix) as log_capture: under_test_nothing.get() log_capture.check( f"Unauthorized read access in property-wrapper for {under_test_nothing.prop.id()}!", )
def test_property_read_only(under_test_read_only: PropertyWrapper, default_property_base): # Make sure that writing to read-only wrapper is ineffective assert (not default_property_base._lock.locked()) with LogCapture(attributes=strip_prefix) as log_capture: under_test_read_only.set(NEW_PROPERTY_VALUE) log_capture.check( f"Unauthorized write access in property-wrapper {under_test_read_only.prop.id()}!", ) assert (under_test_read_only.get() == DEFAULT_PROPERTY_VALUE)
def test_property_write(under_test_read_write: PropertyWrapper, default_property_base, context_mock): # Make sure that writing to writable wrapper is effective assert (default_property_base._lock.locked()) under_test_read_write.set(NEW_PROPERTY_VALUE) assert (under_test_read_write.get() == NEW_PROPERTY_VALUE) context_mock.emit.assert_called_once_with( s(f"{under_test_read_write.prop.id()}:changed"), parents=None, wipe=True)
def test_property_get(under_test_read_only: PropertyWrapper, default_property_base: Property): assert (not default_property_base._lock.locked()) assert (under_test_read_only.get() == DEFAULT_PROPERTY_VALUE)