def test_datetime_deferreds(self): thing = tale.base.Item("thing") driver = tale.driver.Driver() now = datetime.datetime.now() driver.game_clock = tale.util.GameDateTime(now, 1) due = driver.game_clock.plus_realtime(datetime.timedelta(seconds=3601)) driver.defer(due, thing.move) deferred = driver.deferreds[0] after = deferred.due_gametime - now self.assertEqual(3601, after.seconds)
def test_numeric_deferreds(self): thing = tale.base.Item("thing") driver = tale.driver.Driver() now = datetime.datetime.now() driver.game_clock = tale.util.GameDateTime(now, 1) with self.assertRaises(ValueError): driver.defer("blerp", thing.move) driver.defer(3601, thing.move) deferred = driver.deferreds[0] after = deferred.due_gametime - now self.assertEqual(3601, after.seconds)
def testTimevalueRanges(self): with self.assertRaises(AssertionError): tale.driver.Deferred(1, os.getcwd, None, None) tale.driver.Deferred(datetime.datetime.now(), os.getcwd, None, None) with self.assertRaises(ValueError): tale.driver.Deferred(datetime.datetime.now(), os.getcwd, None, None, periodical=(0.09, 0.09)) driver = tale.driver.Driver() driver.game_clock = tale.util.GameDateTime(datetime.datetime.now()) driver.defer(0.9, os.getcwd) driver.defer(1.0, os.getcwd) driver.defer(datetime.datetime.now(), os.getcwd) with self.assertRaises(ValueError): driver.defer((0.09, 0.01, 0.09), os.getcwd) with self.assertRaises(ValueError): driver.defer((0.01, 1, 2), os.getcwd) with self.assertRaises(ValueError): driver.defer((1, 0.02, 0.03), os.getcwd) d = driver.defer((1, 2, 3), os.getcwd) self.assertEqual("getcwd", d.action) self.assertTrue(d.owner.startswith("module:")) self.assertEqual((2, 3), d.periodical)