def test_setting_callback_stub(): # stubs don't trigger conversion a = Setting('a', int, 'abcx', default_value=-1) def setting_callback_1(value: int, rule, setting: Setting) -> int: if setting.name == 'a' and value == 10: return 12 return value def setting_callback_2(value: int, rule, setting: Setting) -> int: if setting.name == 'a' and value == 12: return 7 return value a.add_validator(setting_callback_1) a.add_validator(setting_callback_2) c1 = SyncStubHeksherClient() c1.set_as_main() c1.set_defaults(a='', b='', c='', x='') c1.patch(a, 10) assert a.get() == 10
def test_setting_rules_collection_callback(): a = Setting('a', int, 'abcx', default_value=-1) def setting_callback_1(value: int, rule, setting: Setting) -> int: if setting.name == 'a' and value == 0: return 3 return value def setting_callback_2(value: int, rule, setting: Setting) -> int: if setting.name == 'a' and value == 3: return 7 return value a.add_validator(setting_callback_1) a.add_validator(setting_callback_2) c1 = SyncStubHeksherClient() c1.set_as_main() c1.set_defaults(a='', b='', c='', x='') c1.patch(a, [ Rule({'x': '0'}, 0) ]) assert a.get(x='0') == 0 assert a.get(x='1') == -1