Exemple #1
0
 def test_serialization_context_queries(self):
     sc = SerializationContext({
         'X': False,
         'Y': True,
     })
     self.assertIs(sc.objectFromName('X'), False)
     self.assertIs(sc.nameForObject(False), 'X')
     self.assertIs(sc.objectFromName('Y'), True)
     self.assertIs(sc.nameForObject(True), 'Y')
Exemple #2
0
    def test_inject_exception_into_context(self):
        NT = NamedTuple()

        context = SerializationContext({'NT': NT})
        context2 = SerializationContext({'NT': NT})

        def throws(*args):
            raise Exception("Test Exception")

        context.nameForObject = throws
        context2.objectFromName = throws

        with self.assertRaisesRegex(Exception, "Test Exception"):
            context.serialize(NT)

        data = context2.serialize(NT)
        with self.assertRaisesRegex(Exception, "Test Exception"):
            context2.deserialize(data)