Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This adds a test suite based on the
unittest
module (included in Python by default) that runs some end-to-end tests.The basic principle is that for each test it will instantiate the emulator with a given save state, run some bot code on it (as if you were writing a bot mode) and assert whatever needs to be asserted.
I have already added mocks for the
ask_for_choice()
function (there is aset_next_choice("selection")
utility function to configure what it should return) and thewait_for_unique_rng_value()
helper. The latter can be configured usingset_next_rng_seed(0x1234abcd)
, which will also immediately write that RNG value to memory. I've used this to create test cases that are guaranteed to enocunter shiny Pokémon to test handling for that.Tests can be run by calling
python -m unittest discover -s tests
from the repository root. This is also described in a Readme file in thetests/
directory.Coverage
For now, I've added test cases for some pathfinding features, some battle handling features, the Spin mode and the Starters mode. More will be added in other PRs in the future.
I'm only testing English versions of Emerald, Ruby, and FireRed. I decided against testing Sapphire and LeafGreen just to make things a bit simpler and to improve the runtime of the test suite -- mechanically, these games are so similar to Ruby and FireRed that I don't think we have to test against those too.
Changes to the bot itself
Apart from the test suite (in the
tests/
directory), I had to make some changes:context
has a new flag that indicates the bot is in testing mode. I want to try and use that as little as possible to we don't pollute the bot code with lots of special branches for testing.LibmgbaEmulator
class and thehandle_encounter()
function to disable some features we really don't want, such as creation of a save state on shutdown and when encountering a shiny/CCF match, some console output, and notably the loading of save games (i.e.*.sav
files.)Checklist
--line-length 120
argument