From 9a80332552104966de2e3ada3fc37f412f37fb7d Mon Sep 17 00:00:00 2001 From: hsahovic Date: Thu, 24 Dec 2020 02:50:47 +0100 Subject: [PATCH] Add simple unit test for timing utility --- unit_tests/player/test_player_misc.py | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/unit_tests/player/test_player_misc.py b/unit_tests/player/test_player_misc.py index 2c108b5f5..f1c8bb505 100644 --- a/unit_tests/player/test_player_misc.py +++ b/unit_tests/player/test_player_misc.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import pytest + from poke_env.environment.battle import Battle from poke_env.environment.double_battle import DoubleBattle from poke_env.player.player import Player @@ -12,6 +14,9 @@ class SimplePlayer(Player): def choose_move(self, battle): return self.choose_random_move(battle) + async def _send_message(self, message, room): + self._sent_messages = [message, room] + def test_player_default_order(): assert SimplePlayer().choose_default_move().message == "/choose default" @@ -67,21 +72,6 @@ def test_random_teampreview(): @patch("poke_env.player.player.random.random") def test_choose_random_move_doubles(pseudo_random, example_doubles_request): - # possible_choices_memo = ( - # [] - # ) # this needs to be reset at each start of Player.choose_random_move - - # def count_substrings(substring: str, in_: List[str]) -> int: - # return sum(map(lambda el: substring in el, in_)) - - # def choose_non_dynamax(first_orders,) -> str: - # joined = DoubleBattleOrder.join_orders(possible_choices) - # possible_choices_memo.append(possible_choices.copy()) - # for possible_choice in possible_choices: - # if " dynamax" not in possible_choice: - # return possible_choice - # raise ValueError(f"Only max moves are available in {possible_choices}") - logger = MagicMock() battle = DoubleBattle("tag", "username", logger) player = RandomPlayer() @@ -115,3 +105,19 @@ def test_choose_random_move_doubles(pseudo_random, example_doubles_request): pseudo_random.side_effect = lambda: 0.999 choice = player.choose_random_move(battle) assert choice.message == "/choose move slackoff dynamax, switch thundurus" + + +@pytest.mark.asyncio +async def test_start_timer_on_battle_start(): + # on + player = SimplePlayer(start_listening=False, start_timer_on_battle_start=True) + + await player._create_battle(["", "gen8randombattle", "uuu"]) + assert player._sent_messages == ["/timer on", "gen8randombattle-uuu"] + + # off + player = SimplePlayer(start_listening=False, start_timer_on_battle_start=False) + + await player._create_battle(["", "gen8randombattle", "uuu"]) + with pytest.raises(AttributeError): + player._sent_messages