def test_get(self): f = Field(name="NAME") def func1(instance, value): return "OTHER" f.getters(func1) instance = Typing2() instance._NAME = 10 self.assertEqual(f.direct_get(instance), 10) self.assertEqual(f.__get__(instance, None), "OTHER") f.default(33) self.assertEqual(instance._NAME, 10) del instance._NAME self.assertEqual(f.__get__(instance, None), "OTHER") self.assertEqual(instance._NAME, 33) f.getters(clear=True) self.assertEqual(f.__get__(instance, None), 33)
def test_get_instance(self): f = Field(name="NAME") self.assertIsNone(f.get_instance(None)) f.default("coucou") self.assertEqual(f.get_instance(None), "coucou")
def test_default(self): f = Field(name="NAME", default="name_value") self.assertEqual(f.default_value, "name_value") f.default(None) self.assertEqual(f.default_value, None)