Esempio n. 1
0
 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'))
Esempio n. 2
0
 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")
Esempio n. 3
0
 def test_field_can_be_reassigned(self):
     instance = create_instance(Field())
     instance.attr = 1234
     instance.attr = 5678
     self.assertEqual(5678, instance.attr)
Esempio n. 4
0
 def test_field_assigment_and_retrival(self):
     instance = create_instance(Field())
     instance.attr = 1234
     self.assertEqual(1234, instance.attr)
Esempio n. 5
0
 def test_field_does_not_store_default(self):
     instance = create_instance(Field())
     self.assertFalse(hasattr(instance, '_attr'))
Esempio n. 6
0
 def test_field_knows_its_name(self):
     instance = create_instance(Field())
     assert "attr" == instance.__class__.attr._name
Esempio n. 7
0
 def test_default_respects_type_check(self):
     with self.assertRaises(TypeError):
         create_instance(Field(type=int, default='123'))
Esempio n. 8
0
    def test_type_checking(self):
        instance = create_instance(Field(type=set))
        instance.attr = set()

        with self.assertRaises(TypeError):
            instance.attr = 1234
Esempio n. 9
0
 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")
Esempio n. 10
0
 def test_field_can_be_reassigned(self):
     instance = create_instance(Field())
     instance.attr = 1234
     instance.attr = 5678
     assert 5678 == instance.attr
Esempio n. 11
0
 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")
Esempio n. 12
0
 def test_field_assigment_and_retrival(self):
     instance = create_instance(Field())
     instance.attr = 1234
     assert 1234 == instance.attr
Esempio n. 13
0
 def test_field_does_not_store_default(self):
     instance = create_instance(Field())
     assert not hasattr(instance, "_attr")
Esempio n. 14
0
 def test_field_has_none_as_default(self):
     instance = create_instance(Field())
     assert instance.attr is None
Esempio n. 15
0
 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'))
Esempio n. 16
0
 def test_default_handling(self):
     instance = create_instance(Field(default=1234))
     assert 1234 == instance.attr
Esempio n. 17
0
 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'))
Esempio n. 18
0
 def test_raw_field_accesible_through_class(self):
     field = Field()
     instance = create_instance(field)
     self.assertEqual(field, instance.__class__.attr)
Esempio n. 19
0
 def test_default_handling(self):
     instance = create_instance(Field(default=1234))
     self.assertEqual(1234, instance.attr)
Esempio n. 20
0
 def test_field_knows_its_name(self):
     instance = create_instance(Field())
     self.assertEqual('attr', instance.__class__.attr._name)
Esempio n. 21
0
    def test_choices_checking(self):
        instance = create_instance(Field(choices=(1, 2, 3)))
        instance.attr = 1

        with self.assertRaises(TypeError):
            instance.attr = 4
Esempio n. 22
0
 def test_field_has_none_as_default(self):
     instance = create_instance(Field())
     self.assertIsNone(instance.attr)
Esempio n. 23
0
 def test_default_respects_choices_check(self):
     with self.assertRaises(TypeError):
         create_instance(Field(choices=(1, 2, 3), default=5))
Esempio n. 24
0
 def test_raw_field_accesible_through_class(self):
     field = Field()
     instance = create_instance(field)
     assert field == instance.__class__.attr