Skip to content

Commit

Permalink
Add simple unit test for timing utility
Browse files Browse the repository at this point in the history
  • Loading branch information
hsahovic committed Dec 24, 2020
1 parent 53a0fdf commit 9a80332
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions unit_tests/player/test_player_misc.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit 9a80332

Please sign in to comment.