blob: e86b53c624ee550068e5d277fc22b56446473abe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
"""
Tests for the battle controller
"""
import unittest
from setup_vba import (
vba,
autoplayer,
)
from pokemontools.vba.battle import (
Battle,
BattleException,
)
from bootstrapping import (
bootstrap,
bootstrap_trainer_battle,
)
class BattleTests(unittest.TestCase):
cry = None
vba = None
bootstrap_state = None
@classmethod
def setUpClass(cls):
cls.cry = vba.crystal()
cls.vba = cls.cry.vba
cls.bootstrap_state = bootstrap_trainer_battle()
cls.vba.state = cls.bootstrap_state
@classmethod
def tearDownClass(cls):
cls.vba.shutdown()
def setUp(self):
# reset to whatever the bootstrapper created
self.vba.state = self.bootstrap_state
self.battle = Battle(emulator=self.cry)
self.battle.skip_start_text()
def test_is_in_battle(self):
self.assertTrue(self.battle.is_in_battle())
def test_is_player_turn(self):
self.battle.skip_start_text()
self.battle.skip_until_input_required()
# the initial state should be the player's turn
self.assertTrue(self.battle.is_player_turn())
def test_is_mandatory_switch_initial(self):
# should not be asking for a switch so soon in the battle
self.assertFalse(self.battle.is_mandatory_switch())
def test_attack_loop(self):
self.battle.skip_start_text()
self.battle.skip_until_input_required()
# press "FIGHT"
self.vba.press(["a"], after=20)
# press the first move ("SCRATCH")
self.vba.press(["a"], after=20)
self.battle.skip_until_input_required()
self.assertTrue(self.battle.is_player_turn())
if __name__ == "__main__":
unittest.main()
|