本文整理汇总了Python中pants.engine.Engine.cycle方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.cycle方法的具体用法?Python Engine.cycle怎么用?Python Engine.cycle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.engine.Engine
的用法示例。
在下文中一共展示了Engine.cycle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEngineTimers
# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import cycle [as 别名]
class TestEngineTimers(unittest.TestCase):
def setUp(self):
self.engine = Engine()
def test_callback_added(self):
timer = self.engine.callback(MagicMock())
self.assertTrue(timer in self.engine._callbacks)
def test_loop_added(self):
timer = self.engine.loop(MagicMock())
self.assertTrue(timer in self.engine._callbacks)
def test_deferred_added(self):
timer = self.engine.defer(10, MagicMock())
self.assertTrue(timer in self.engine._deferreds)
def test_deferred_with_zero_delay(self):
self.assertRaises(ValueError, self.engine.defer, 0, MagicMock())
def test_deferred_with_negative_delay(self):
self.assertRaises(ValueError, self.engine.defer, -1, MagicMock())
def test_cycle_added(self):
timer = self.engine.cycle(10, MagicMock())
self.assertTrue(timer in self.engine._deferreds)
def test_cycle_with_zero_delay(self):
self.assertRaises(ValueError, self.engine.cycle, 0, MagicMock())
def test_cycle_with_negative_delay(self):
self.assertRaises(ValueError, self.engine.cycle, -1, MagicMock())
def test_remove_timer_with_no_end(self):
timer = self.engine.callback(MagicMock())
self.engine._remove_timer(timer)
def test_remove_nonexistent_timer_with_no_end(self):
timer = MagicMock()
timer.end = None
self.engine._remove_timer(timer)
def test_remove_timer_with_end(self):
timer = self.engine.defer(10, MagicMock())
self.engine._remove_timer(timer)
def test_remove_nonexistent_timer_with_end(self):
timer = MagicMock()
timer.end = 1
self.engine._remove_timer(timer)
示例2: TestTimers
# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import cycle [as 别名]
class TestTimers(unittest.TestCase):
def setUp(self):
self.times_called = []
self.engine = Engine()
def timer(self):
self.times_called.append(self.engine.latest_poll_time)
def test_callback(self):
timer = MagicMock()
self.engine.callback(timer)
self.engine.poll(0.01)
self.engine.poll(0.01)
self.engine.poll(0.01)
timer.assert_called_once_with()
def test_callback_cancel(self):
timer = MagicMock()
cancel_callback = self.engine.callback(timer)
cancel_callback()
self.engine.poll(0.01)
self.engine.poll(0.01)
self.engine.poll(0.01)
self.assertRaises(AssertionError, timer.assert_called_with)
def test_loop(self):
timer = MagicMock()
self.engine.loop(timer)
self.engine.poll(0.01)
self.engine.poll(0.01)
self.engine.poll(0.01)
timer.assert_has_calls([call() for _ in range(3)])
def test_loop_cancel(self):
timer = MagicMock()
cancel_loop = self.engine.loop(timer)
self.engine.poll(0.01)
self.engine.poll(0.01)
timer.assert_has_calls([call() for _ in range(2)])
cancel_loop()
self.engine.poll(0.01)
timer.assert_has_calls([call() for _ in range(2)])
def test_defer(self):
self.engine.poll(0.01)
timer = MagicMock(side_effect=self.timer)
expected_time = self.engine.latest_poll_time + 0.01
self.engine.defer(0.01, timer)
self.engine.poll(0.2)
self.engine.poll(0.2)
self.engine.poll(0.2)
timer.assert_called_once_with()
self.assertLess(abs(expected_time - self.times_called[0]), 0.01)
def test_defer_cancel(self):
timer = MagicMock()
cancel_defer = self.engine.defer(0.01, timer)
cancel_defer()
self.engine.poll(0.2)
self.engine.poll(0.2)
self.engine.poll(0.2)
self.assertRaises(AssertionError, timer.assert_called_with)
def test_cycle(self):
self.engine.poll(0.01)
timer = MagicMock(side_effect=self.timer)
expected_times = [
self.engine.latest_poll_time + 0.01,
self.engine.latest_poll_time + 0.02,
self.engine.latest_poll_time + 0.03
]
self.engine.cycle(0.01, timer)
self.engine.poll(0.2)
self.engine.poll(0.2)
self.engine.poll(0.2)
if sys.platform == "win32": self.engine.poll(0.02) # See issue #40
timer.assert_has_calls([call() for _ in range(3)])
for i in range(3):
self.assertLess(abs(expected_times[i] - self.times_called[i]), 0.01)
def test_cycle_cancel(self):
self.engine.poll(0.01)
timer = MagicMock(side_effect=self.timer)
expected_times = [
self.engine.latest_poll_time + 0.01,
self.engine.latest_poll_time + 0.02
]
cancel_cycle = self.engine.cycle(0.01, timer)
self.engine.poll(0.2)
self.engine.poll(0.2)
if sys.platform == "win32": self.engine.poll(0.02) # See issue #40
timer.assert_has_calls([call() for _ in range(2)])
cancel_cycle()
self.engine.poll(0.2)
timer.assert_has_calls([call() for _ in range(2)])
for i in range(2):
self.assertLess(abs(expected_times[i] - self.times_called[i]), 0.01)