Exemplo n.º 1
0
 def test_deferreds(self):
     target = Thing()
     item = base.Item("key")
     now = datetime.datetime.now()
     deferreds = [
         driver.Deferred(now, target.append, [1, 2, 3], {"kwarg": 42}),
         driver.Deferred(now, os.getcwd, [], None),
         driver.Deferred(now, module_level_func, [], None),
         driver.Deferred(now, item.init, [], None, periodical=(11.1, 22.2))
     ]
     x1, x2, x3, x4 = serializecycle(deferreds)
     assert x1["__class__"] == "tale.driver.Deferred"
     assert x1["action"] == "append"
     assert x1["vargs"] == [1, 2, 3]
     assert x1["kwargs"] == {"kwarg": 42}
     assert x1["periodical"] is None
     assert x1["owner"] == "class:tests.supportstuff.Thing"
     assert x1["due_gametime"] == now.isoformat()
     assert x2["action"] == "getcwd"
     assert x2["owner"] in ("module:os", "module:nt", "module:posix")
     assert x3["action"] == "module_level_func"
     assert x3["owner"] == "module:tests.test_serialize"
     assert x4["action"] == "init"
     assert len(x4["owner"]) == 4
     assert x4["owner"][1] == "key"
     assert x4["periodical"] == (11.1, 22.2)
Exemplo n.º 2
0
 def testSerializable(self):
     target = Thing()
     deferreds = [the_driver.Deferred(datetime.datetime.now(), target.append, [1, 2, 3], {"kwarg": 42}),
                  the_driver.Deferred(datetime.datetime.now(), os.getcwd, [], None),
                  the_driver.Deferred(datetime.datetime.now(), module_level_func, [], None)]
     ser = pickle.dumps(deferreds, pickle.HIGHEST_PROTOCOL)
     data = pickle.loads(ser)
     self.assertEqual(deferreds, data)
Exemplo n.º 3
0
 def testCallable(self):
     def scoped_function():
         pass
     t = Thing()
     d = the_driver.Deferred(None, t.append, [42], None)
     ctx = tale.util.Context(driver="driver", clock=None, config=None, player_connection=None)
     d(ctx=ctx)
     self.assertEqual([42], t.x)
     d = the_driver.Deferred(None, module_level_func, [], None)
     d(ctx=ctx)
     d = the_driver.Deferred(None, module_level_func_without_ctx, [], None)
     d(ctx=ctx)
     with self.assertRaises(ValueError):
         the_driver.Deferred(None, scoped_function, [], None)
     with self.assertRaises(ValueError):
         d = the_driver.Deferred(None, lambda a, ctx=None: 1, [42], None)