Beispiel #1
0
    def test_set(self):
        f = Field(name="NAME")

        def func1(instance, value):
            return value + 10

        f.setters(func1)
        f.setters(func1)

        instance = Typing2()

        f.direct_set(instance, 10)
        self.assertEqual(instance._NAME, 10)

        f.__set__(instance, 40)
        self.assertEqual(instance._NAME, 60)

        f.setters(clear=True)
        f.__set__(instance, 40)
        self.assertEqual(instance._NAME, 40)
Beispiel #2
0
    def test_setters(self):
        f = Field(name="NAME")

        def func1(instance, value):
            return value

        def func2(instance, value):
            return value

        f.setters(func1)
        self.assertEqual(f.setters_funcs[0], func1)

        f.setters(func2)
        self.assertEqual(f.setters_funcs[0], func1)
        self.assertEqual(f.setters_funcs[1], func2)

        f.setters(clear=True)
        self.assertEqual(len(f.setters_funcs), 0)