def test_field_can_be_set_default(self): default = object() instance = create_instance(Field(default=default)) instance.attr = 1234 instance.attr = default self.assertEqual(default, instance.attr) self.assertFalse(hasattr(instance, '_attr'))
def test_field_can_be_set_default(self): default = object() instance = create_instance(Field(default=default)) instance.attr = 1234 instance.attr = default assert default == instance.attr assert not hasattr(instance, "_attr")
def test_field_can_be_reassigned(self): instance = create_instance(Field()) instance.attr = 1234 instance.attr = 5678 self.assertEqual(5678, instance.attr)
def test_field_assigment_and_retrival(self): instance = create_instance(Field()) instance.attr = 1234 self.assertEqual(1234, instance.attr)
def test_field_does_not_store_default(self): instance = create_instance(Field()) self.assertFalse(hasattr(instance, '_attr'))
def test_field_knows_its_name(self): instance = create_instance(Field()) assert "attr" == instance.__class__.attr._name
def test_default_respects_type_check(self): with self.assertRaises(TypeError): create_instance(Field(type=int, default='123'))
def test_type_checking(self): instance = create_instance(Field(type=set)) instance.attr = set() with self.assertRaises(TypeError): instance.attr = 1234
def test_field_can_be_set_to_none(self): instance = create_instance(Field()) instance.attr = 1234 instance.attr = None assert instance.attr is None assert not hasattr(instance, "_attr")
def test_field_can_be_reassigned(self): instance = create_instance(Field()) instance.attr = 1234 instance.attr = 5678 assert 5678 == instance.attr
def test_field_can_be_deleted(self): instance = create_instance(Field()) instance.attr = 1234 del instance.attr assert instance.attr is None assert not hasattr(instance, "_attr")
def test_field_assigment_and_retrival(self): instance = create_instance(Field()) instance.attr = 1234 assert 1234 == instance.attr
def test_field_does_not_store_default(self): instance = create_instance(Field()) assert not hasattr(instance, "_attr")
def test_field_has_none_as_default(self): instance = create_instance(Field()) assert instance.attr is None
def test_field_can_be_deleted(self): instance = create_instance(Field()) instance.attr = 1234 del instance.attr self.assertEqual(None, instance.attr) self.assertFalse(hasattr(instance, '_attr'))
def test_default_handling(self): instance = create_instance(Field(default=1234)) assert 1234 == instance.attr
def test_field_can_be_set_to_none(self): instance = create_instance(Field()) instance.attr = 1234 instance.attr = None self.assertEqual(None, instance.attr) self.assertFalse(hasattr(instance, '_attr'))
def test_raw_field_accesible_through_class(self): field = Field() instance = create_instance(field) self.assertEqual(field, instance.__class__.attr)
def test_default_handling(self): instance = create_instance(Field(default=1234)) self.assertEqual(1234, instance.attr)
def test_field_knows_its_name(self): instance = create_instance(Field()) self.assertEqual('attr', instance.__class__.attr._name)
def test_choices_checking(self): instance = create_instance(Field(choices=(1, 2, 3))) instance.attr = 1 with self.assertRaises(TypeError): instance.attr = 4
def test_field_has_none_as_default(self): instance = create_instance(Field()) self.assertIsNone(instance.attr)
def test_default_respects_choices_check(self): with self.assertRaises(TypeError): create_instance(Field(choices=(1, 2, 3), default=5))
def test_raw_field_accesible_through_class(self): field = Field() instance = create_instance(field) assert field == instance.__class__.attr