summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-11-09 15:45:03 -0600
committerBryan Bishop <kanzure@gmail.com>2013-11-09 15:45:03 -0600
commit3868fb1e0622e5d3cda0c093ce3114c485fd0096 (patch)
tree184fc43668e7bfda64105693debeb36b9f3b9254
parent54e2b189b8b9765d17d4c0d05675ac70c2bec2ac (diff)
simplify the vba-related tests
The imports for the emulator-related tests are now simplified in the tests/ folder. The bootstrapping.py file contains some shared functions that multiple test files might choose to use. Those functions probably belong in the actual module instead of in tests/. The battle-related tests have been separated from the other emulator tests.
-rw-r--r--tests/bootstrapping.py51
-rw-r--r--tests/setup_vba.py4
-rw-r--r--tests/test_vba.py71
-rw-r--r--tests/test_vba_battle.py51
4 files changed, 114 insertions, 63 deletions
diff --git a/tests/bootstrapping.py b/tests/bootstrapping.py
new file mode 100644
index 0000000..17a2945
--- /dev/null
+++ b/tests/bootstrapping.py
@@ -0,0 +1,51 @@
+"""
+Functions to bootstrap the emulator state
+"""
+
+from setup_vba import (
+ vba,
+ autoplayer,
+)
+
+def bootstrap():
+ """
+ Every test needs to be run against a certain minimum context. That context
+ is constructed by this function.
+ """
+
+ cry = vba.crystal(config=None)
+ runner = autoplayer.SpeedRunner(cry=cry)
+
+ # skip=False means run the skip_intro function instead of just skipping to
+ # a saved state.
+ runner.skip_intro(skip=True)
+
+ state = cry.vba.state
+
+ # clean everything up again
+ cry.vba.shutdown()
+
+ return state
+
+def bootstrap_trainer_battle():
+ """
+ Start a trainer battle.
+ """
+ # setup
+ cry = vba.crystal(config=None)
+ runner = autoplayer.SpeedRunner(cry=cry)
+
+ runner.skip_intro(skip=True)
+ runner.handle_mom(skip=True)
+ runner.walk_into_new_bark_town(skip=True)
+ runner.handle_elm("totodile", skip=True)
+
+ # levelgrind a pokemon
+ # TODO: make new_bark_level_grind able to figure out how to construct its
+ # initial state if none is provided.
+ runner.new_bark_level_grind(17, skip=True)
+
+ # TODO: figure out a better way to start a trainer battle :(
+ runner.cry.start_trainer_battle_lamely()
+
+ return runner.cry.vba.state
diff --git a/tests/setup_vba.py b/tests/setup_vba.py
new file mode 100644
index 0000000..6e615e2
--- /dev/null
+++ b/tests/setup_vba.py
@@ -0,0 +1,4 @@
+import pokemontools.vba.vba as vba
+import pokemontools.vba.keyboard as keyboard
+import pokemontools.vba.autoplayer as autoplayer
+autoplayer.vba = vba
diff --git a/tests/test_vba.py b/tests/test_vba.py
index 9c12cc1..caa1867 100644
--- a/tests/test_vba.py
+++ b/tests/test_vba.py
@@ -4,20 +4,16 @@ Tests for VBA automation tools
import unittest
-import pokemontools.vba.vba as vba
-
-from pokemontools.vba.battle import (
- Battle,
- BattleException,
+from setup_vba import (
+ vba,
+ autoplayer,
+ keyboard,
)
-try:
- import pokemontools.vba.vba_autoplayer as autoplayer
-except ImportError:
- import pokemontools.vba.autoplayer as autoplayer
-autoplayer.vba = vba
-
-import pokemontools.vba.keyboard as keyboard
+from bootstrapping import (
+ bootstrap,
+ bootstrap_trainer_battle,
+)
def setup_wram():
"""
@@ -39,49 +35,6 @@ def setup_wram():
return wram
-def bootstrap():
- """
- Every test needs to be run against a certain minimum context. That context
- is constructed by this function.
- """
-
- cry = vba.crystal(config=None)
- runner = autoplayer.SpeedRunner(cry=cry)
-
- # skip=False means run the skip_intro function instead of just skipping to
- # a saved state.
- runner.skip_intro(skip=True)
-
- state = cry.vba.state
-
- # clean everything up again
- cry.vba.shutdown()
-
- return state
-
-def bootstrap_trainer_battle():
- """
- Start a trainer battle.
- """
- # setup
- cry = vba.crystal(config=None)
- runner = autoplayer.SpeedRunner(cry=cry)
-
- runner.skip_intro(skip=True)
- runner.handle_mom(skip=True)
- runner.walk_into_new_bark_town(skip=True)
- runner.handle_elm("totodile", skip=True)
-
- # levelgrind a pokemon
- # TODO: make new_bark_level_grind able to figure out how to construct its
- # initial state if none is provided.
- runner.new_bark_level_grind(17, skip=True)
-
- # TODO: figure out a better way to start a trainer battle :(
- runner.cry.start_trainer_battle_lamely()
-
- return runner.cry.vba.state
-
class OtherVbaTests(unittest.TestCase):
def test_keyboard_planner(self):
button_sequence = keyboard.plan_typing("an")
@@ -329,13 +282,5 @@ class VbaTests(unittest.TestCase):
pname = self.cry.get_player_name().replace("@", "")
self.assertEqual(name, pname)
- def test_battle_is_player_turn(self):
- state = bootstrap_trainer_battle()
- self.cry.vba.state = state
-
- battle = Battle(emulator=self.cry)
-
- self.assertTrue(battle.is_player_turn())
-
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_vba_battle.py b/tests/test_vba_battle.py
new file mode 100644
index 0000000..6d3b504
--- /dev/null
+++ b/tests/test_vba_battle.py
@@ -0,0 +1,51 @@
+"""
+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
+
+ def test_battle_is_player_turn(self):
+ self.cry.vba.state = self.bootstrap_state
+
+ battle = Battle(emulator=self.cry)
+
+ self.assertTrue(battle.is_player_turn())
+
+if __name__ == "__main__":
+ unittest.main()