-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
weird hack to make unique names for players that use the name of the …
…function they're in
- Loading branch information
Showing
2 changed files
with
57 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,101 @@ | ||
from __future__ import annotations | ||
|
||
import inspect | ||
|
||
import pytest | ||
from poke_env import PlayerConfiguration | ||
from poke_env.player import SimpleHeuristicsPlayer | ||
|
||
from p2lab.pokemon import pokefactory | ||
from p2lab.pokemon.battles import run_battles | ||
from p2lab.pokemon.teams import Team | ||
|
||
pytest_plugins = ("pytest_asyncio",) | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_battle_eevee_pikachu_pokes(): | ||
p = pokefactory.PokeFactory() | ||
eevee = p.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
pikachu = p.make_pokemon(25, moves=["thundershock", "growl"], level=5) | ||
def test_battle_eevee_pikachu_pokes(event_loop, default_factory): | ||
eevee = default_factory.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
pikachu = default_factory.make_pokemon(25, moves=["thundershock", "growl"], level=5) | ||
team1 = Team([eevee]) | ||
team2 = Team([pikachu]) | ||
teams = [team1, team2] | ||
matches = [[0, 1]] | ||
|
||
player_1 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 1", None), battle_format="gen7anythinggoes" | ||
PlayerConfiguration(inspect.stack()[0][3].split("test_")[1][:15] + " P1", None), | ||
battle_format="gen7anythinggoes", | ||
) | ||
player_2 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 2", None), battle_format="gen7anythinggoes" | ||
PlayerConfiguration(inspect.stack()[0][3].split("test_")[1][:15] + " P2", None), | ||
battle_format="gen7anythinggoes", | ||
) | ||
res = event_loop.run_until_complete( | ||
run_battles(matches, teams, player_1, player_2, battles_per_match=1) | ||
) | ||
res = await run_battles(matches, teams, player_1, player_2, battles_per_match=1) | ||
|
||
assert res is not None | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_battle_mewtwo_obliterates_eevee(): | ||
p = pokefactory.PokeFactory() | ||
eevee = p.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
mewtwo = p.make_pokemon(150, moves=["psychic"], level=100) | ||
def test_battle_mewtwo_obliterates_eevee(event_loop, default_factory): | ||
eevee = default_factory.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
mewtwo = default_factory.make_pokemon(150, moves=["psychic"], level=100) | ||
team1 = Team([eevee]) | ||
team2 = Team([mewtwo]) | ||
teams = [team1, team2] | ||
matches = [[0, 1]] | ||
player_1 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 1", None), battle_format="gen7anythinggoes" | ||
PlayerConfiguration(inspect.stack()[0][3].split("test_")[1][:15] + " P1", None), | ||
battle_format="gen7anythinggoes", | ||
) | ||
player_2 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 2", None), battle_format="gen7anythinggoes" | ||
PlayerConfiguration(inspect.stack()[0][3].split("test_")[1][:15] + " P2", None), | ||
battle_format="gen7anythinggoes", | ||
) | ||
res = event_loop.run_until_complete( | ||
run_battles(matches, teams, player_1, player_2, battles_per_match=1) | ||
) | ||
res = await run_battles(matches, teams, player_1, player_2, battles_per_match=10) | ||
mewtwo_wins = res[0][1] | ||
eevee_wins = res[0][0] | ||
assert mewtwo_wins > eevee_wins | ||
|
||
|
||
@pytest.mark.asyncio() | ||
@pytest.mark.parametrize( | ||
"battle_format", | ||
[ | ||
"gen4anythinggoes", | ||
"gen6anythinggoes", | ||
"gen7anythinggoes", | ||
"gen8anythinggoes", | ||
("gen4anythinggoes"), | ||
("gen6anythinggoes"), | ||
("gen7anythinggoes"), | ||
("gen8anythinggoes"), | ||
], | ||
) | ||
async def test_battle_eevee_pikachu_formats(battle_format): | ||
p = pokefactory.PokeFactory() | ||
eevee = p.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
pikachu = p.make_pokemon(25, moves=["thundershock", "growl"], level=5) | ||
def test_battle_eevee_pikachu_formats(event_loop, battle_format, default_factory): | ||
eevee = default_factory.make_pokemon(133, moves=["tackle", "growl"], level=5) | ||
pikachu = default_factory.make_pokemon(25, moves=["thundershock", "growl"], level=5) | ||
team1 = Team([eevee]) | ||
team2 = Team([pikachu]) | ||
teams = [team1, team2] | ||
matches = [[0, 1]] | ||
|
||
player_1 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 1", None), | ||
PlayerConfiguration( | ||
inspect.stack()[0][3].split("test_")[1][:10] | ||
+ "-" | ||
+ battle_format[:4] | ||
+ " P1", | ||
None, | ||
), | ||
battle_format=battle_format, | ||
) | ||
player_2 = SimpleHeuristicsPlayer( | ||
PlayerConfiguration("Player 2", None), | ||
PlayerConfiguration( | ||
inspect.stack()[0][3].split("test_")[1][:10] | ||
+ "-" | ||
+ battle_format[:4] | ||
+ " P2", | ||
None, | ||
), | ||
battle_format=battle_format, | ||
) | ||
res = await run_battles(matches, teams, player_1, player_2, battles_per_match=1) | ||
res = event_loop.run_until_complete( | ||
run_battles(matches, teams, player_1, player_2, battles_per_match=1) | ||
) | ||
assert res is not None |
fd061c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phinate does this work for you? My tests won't run in
test_battles.py
without@pytest.mark.asyncio()
and await.