def test_FailDeserializeWithInvalidTypes(self):
        with self.assertRaises(TypeError):
            deserialize(Rule(Object), {
                'name': 'Karel',
                'full_name': 0.0,
            })

        with self.assertRaises(TypeError):
            deserialize(
                Rule(Object), {
                    'name': 'Rolf',
                    'full_name': 'Rolf van Kleef',
                    'calling_name': False,
                })
예제 #2
0
 def test_SetCorrectValueShouldSucceed(self):
     self.assertEqual(
         Object(name='Rolf'),
         deserialize(Rule(Object), {
            'name': 'Rolf'
         }, try_all=False)
     )
 def test_DictDeserialize(self):
     self.assertEqual(
         DictTest(
             test={
                 1: [
                     User(name='Peter',
                          full_name='Peter Driebergen',
                          calling_name='Unknown')
                 ]
             }),
         deserialize(
             Rule(DictTest), {
                 "test": {
                     1: [{
                         'name': 'Peter',
                         'full_name': 'Peter Driebergen',
                     }],
                 }
             }))
 def test_CorrectDeserializationForNestedWithTypeUnionsAndLists(self):
     # noinspection PyArgumentList
     self.assertEqual(
         Group(
             name='IAPC',
             members=[
                 User(name='Rolf',
                      full_name='Rolf van Kleef',
                      calling_name='Unknown'),
                 Group(name='Syscom',
                       members=[
                           User(name='Kevin',
                                full_name='Kevin Alberts',
                                calling_name='Kevin'),
                       ]),
             ],
         ),
         deserialize(
             Rule(Object), {
                 'name':
                 'IAPC',
                 'members': [
                     {
                         'name': 'Rolf',
                         'full_name': 'Rolf van Kleef'
                     },
                     {
                         'name':
                         'Syscom',
                         'members': [
                             {
                                 'name': 'Kevin',
                                 'full_name': 'Kevin Alberts',
                                 'calling_name': 'Kevin'
                             },
                         ]
                     },
                 ],
             }))
    def test_DeserializeTupleFail(self):
        with self.assertRaises(TypeError):
            deserialize(Rule(NestedTypingStuff), {"test": [[1, 2]]})

        with self.assertRaises(TypeError):
            deserialize(Rule(NestedTypingStuff), {"test": [[1, 2, "boo"]]})
 def test_DeserializeTupleCorrect(self):
     # noinspection PyArgumentList
     self.assertEqual(
         NestedTypingStuff(test=[(1, 2, 3)]),
         deserialize(Rule(NestedTypingStuff), {"test": [[1, 2, 3]]}))
 def test_DeserializeIntoAbstract(self):
     with self.assertRaises(TypeError):
         deserialize(Rule(Object), {'name': 'Test'})
예제 #8
0
 def test_SetWrongValueShouldFail(self):
     with self.assertRaises(TypeError):
         deserialize(Rule(Object), {
             'name': 'abcdefghijklmnopqrstuvwxyz'
         })
예제 #9
0
 def test_SetWrongTypeShouldFail(self):
     with self.assertRaises(TypeError):
         deserialize(Rule(Object), {
             'name': 8
         })