Example #1
0
    def __rmatmul__(cls, setting: Any):
        from concrete_settings import Setting

        if not isinstance(setting, Setting):
            setting = Setting(setting)

        bhv = cls()
        return bhv(setting)
Example #2
0
    def _make_setting_from_attribute(
            mcs, name, attr, annotations) -> Union[PropertySetting, Setting]:
        # is it a class method?
        if isinstance(attr, types.FunctionType):
            return PropertySetting(attr)

        type_hint = annotations.get(name, GuessSettingType)
        return Setting(attr, doc="", type_hint=type_hint)
Example #3
0
def test_setting_ctor(v_int):
    validators = (lambda x: x, )
    s = Setting(v_int, type_hint=int, validators=validators, doc="docstring")

    assert s.value == v_int
    assert s.__doc__ == "docstring"
    assert s.validators is validators
    assert s.type_hint is int
def S(name: str, type_hint=str) -> Setting:
    s = Setting(type_hint=type_hint)
    s.__set_name__(s, name)
    return s
Example #5
0
 class TestSettings(Settings):
     MAX_SPEED = Setting(23) @ plus(2) @ div(5)
Example #6
0
 class TestSettings(Settings):
     MAX_SPEED = Setting(10) @ div
     MIN_SPEED = Setting(9) @ div(3)
Example #7
0
 class TestSettings(Settings):
     MAX_SPEED = Setting(10) @ bhv_mock
Example #8
0
def S(name: str, type_hint=str) -> Setting:
    """A helper function which creates a setting and assigns it a name."""
    s = Setting(type_hint=type_hint)
    s.__set_name__(s, name)
    return s
 class AppSettings(Settings):
     AGE: int = Setting(10)
Example #10
0
 def attach_to(self, setting: Setting):
     setting.attach_behavior(self)
Example #11
0
    def __rmatmul__(self, setting: Any):
        if not isinstance(setting, Setting):
            setting = Setting(setting)

        self.attach_to(setting)
        return setting
Example #12
0
    class TestSettings(Settings):
        mandatory_validators = (is_positive,)

        MIN_SPEED: int = Setting(0, validators=(is_less_that_10,))
        MAX_SPEED: int = Setting(11, validators=(is_less_that_10,))
Example #13
0
 class TestSettigs(Settings):
     MAX_SPEED = Setting(10, validators=(validator,))
Example #14
0
 class TestSettings(Settings):
     MAX_SPEED = Setting(10, validators=(validator_with_exception, ))