Beispiel #1
0
    def test_serialize_modules(self):
        codebase = Codebase.FromModule(dummy_test_module)
        sc = codebase.serializationContext

        self.assertIn('.modules.pytz', sc.nameToObject)

        pytz = dummy_test_module.pytz
        self.assertIs(pytz, sc.deserialize(sc.serialize(pytz)))
Beispiel #2
0
    def test_serialize_lambdas_with_references_in_list_comprehensions(self):
        codebase = Codebase.FromModule(dummy_test_module)
        sc = codebase.serializationContext

        #note that it matters that the 'module_level_testfun' is at the module level,
        #because that induces a freevar in a list-comprehension code object
        def f():
            return [module_level_testfun() for _ in range(1)][0]

        self.assertEqual(f(), "testfunction")

        self.assertEqual(sc.deserialize(sc.serialize(f))(), "testfunction")