コード例 #1
0
    async def test_run_follows_the_clock_tick(self):
        clock = asynctest.MagicMock()
        clock.__aiter__.return_value = range(3)

        with patch.multiple(
                self.task_runner,
                clock=clock,
                can_dispatch_task=CoroutineMock(return_value=False),
        ):
            await self.task_runner._run()
            self.task_runner.can_dispatch_task.assert_has_awaits(
                [call(), call(), call()])
コード例 #2
0
ファイル: test_tick.py プロジェクト: zrebie/battle-city-ai
async def test_do_actions_after_10_ticks():
    game = Game()
    logic = TickLogicPart(game)
    game.ticks = 10

    with patch.multiple(logic,
                        unfreeze_players=DEFAULT,
                        do_it_after_ticks=DEFAULT) as patch_values:
        await logic.do_it()

    assert not patch_values['unfreeze_players'].called
    patch_values['do_it_after_ticks'].assert_called_once_with()
コード例 #3
0
ファイル: test_tick.py プロジェクト: zrebie/battle-city-ai
async def test_do_it_after_ticks():
    game = Game()
    game.time_left = 250
    logic = TickLogicPart(game)

    with patch.multiple(logic,
                        unset_player_actions=DEFAULT,
                        send_info=DEFAULT,
                        do_sth_with_npcs=DEFAULT) as patch_values:
        await logic.do_it_after_ticks()

    patch_values['unset_player_actions'].assert_called_once_with()
    patch_values['do_sth_with_npcs'].assert_called_once_with()
    patch_values['send_info'].assert_called_once_with()

    assert game.time_left == 249
コード例 #4
0
    async def test_run_emits_a_task_i_done_event_for_each_valid_clock_tick(
        self
    ):
        clock = asynctest.MagicMock()
        clock.__aiter__.return_value = range(3)
        wrapped_task = Mock()
        with patch.multiple(
            self.task_runner,
            clock=clock,
            _wrapped_task=wrapped_task,
            task_is_done_event=Mock(),
            can_dispatch_task=CoroutineMock(side_effect=[True, False, True]),
        ), patch("asyncworker.task_runners.asyncio.ensure_future"):
            await self.task_runner._run()

            self.task_runner.task_is_done_event.clear.assert_has_calls(
                [call(), call()]
            )
コード例 #5
0
    async def test_run_adds_the_new_task_for_each_valid_clock_tick(self):
        clock = asynctest.MagicMock()
        clock.__aiter__.return_value = range(3)
        wrapped_task = Mock()
        with patch.multiple(
                self.task_runner,
                clock=clock,
                _wrapped_task=wrapped_task,
                running_tasks=Mock(spec=set),
                can_dispatch_task=CoroutineMock(
                    side_effect=[True, False, True]),
        ), patch("asyncworker.task_runners.asyncio.ensure_future"
                 ) as ensure_future:
            await self.task_runner._run()

            self.task_runner.running_tasks.add.assert_has_calls([
                call(ensure_future.return_value),
                call(ensure_future.return_value),
            ])
コード例 #6
0
 async def test_run_dispatches_a_new_task_for_each_valid_clock_tick(self):
     clock = asynctest.MagicMock()
     clock.__aiter__.return_value = range(3)
     wrapped_task = Mock()
     with patch.multiple(
         self.task_runner,
         clock=clock,
         _wrapped_task=wrapped_task,
         can_dispatch_task=CoroutineMock(side_effect=[True, False, True]),
     ), patch(
         "asyncworker.task_runners.asyncio.ensure_future"
     ) as ensure_future:
         await self.task_runner._run()
         self.assertEqual(
             ensure_future.call_args_list,
             [
                 call(wrapped_task.return_value),
                 call(wrapped_task.return_value),
             ],
         )