コード例 #1
0
ファイル: test_battle.py プロジェクト: hsahovic/poke-env
def test_battle_from_format():
    assert isinstance(
        Battle.from_format("gen1ou", "battle", "username", None), Gen4Battle
    )
    assert isinstance(
        Battle.from_format("gen2randombattle", "battle", "username", None), Gen4Battle
    )
    assert isinstance(
        Battle.from_format("gen3uber", "battle", "username", None), Gen4Battle
    )
    assert isinstance(
        Battle.from_format("gen4ou", "battle", "username", None), Gen4Battle
    )
    assert isinstance(
        Battle.from_format("gen5randombattle", "battle", "username", None), Gen5Battle
    )
    assert isinstance(
        Battle.from_format("gen6ou", "battle", "username", None), Gen6Battle
    )
    assert isinstance(
        Battle.from_format("gen7randombattle", "battle", "username", None), Gen7Battle
    )
    assert isinstance(
        Battle.from_format("gen8doubleou", "battle", "username", None), Gen8Battle
    )
    assert isinstance(
        Battle.from_format("gen9doubleou", "battle", "username", None), Gen4Battle
    )
コード例 #2
0
    async def _create_battle(self, split_message: List[str]) -> AbstractBattle:
        """Returns battle object corresponding to received message.

        :param split_message: The battle initialisation message.
        :type split_message: List[str]
        :return: The corresponding battle object.
        :rtype: AbstractBattle
        """
        # We check that the battle has the correct format
        if split_message[1] == self._format and len(split_message) >= 2:
            # Battle initialisation
            battle_tag = "-".join(split_message)[1:]

            if battle_tag in self._battles:
                return self._battles[battle_tag]
            else:
                if self.format_is_doubles:
                    battle = DoubleBattle(
                        battle_tag=battle_tag,
                        username=self.username,
                        logger=self.logger,
                        save_replays=self._save_replays,
                    )
                else:
                    battle = Battle.from_format(
                        format_=self._format,
                        battle_tag=battle_tag,
                        username=self.username,
                        logger=self.logger,
                        save_replays=self._save_replays,
                    )
                await self._battle_count_queue.put(None)
                if battle_tag in self._battles:
                    self._battle_count_queue.get()
                    return self._battles[battle_tag]
                async with self._battle_start_condition:
                    self._battle_semaphore.release()
                    self._battle_start_condition.notify_all()
                    self._battles[battle_tag] = battle

                if self._start_timer_on_battle_start:
                    await self._send_message("/timer on", battle.battle_tag)

                return battle

            return self._battles[battle_tag]
        else:
            self.logger.critical(
                "Unmanaged battle initialisation message received: %s", split_message
            )
            raise ShowdownException()