Tests: add a test for worlds to not modify the itempool after `create_items` (#1460)

* Tests: add a test for worlds to only modify the itempool in `create_items`

* extend test multiworld setup instead of a new function

* cleanup the test a bit

* put more strict wording in `create_items` docstring

* list of shame

* Don't call `set_rules` before testing

* remove ChecksFinder from the list of shame

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
Co-authored-by: Fabian Dill <Berserker66@users.noreply.github.com>
This commit is contained in:
Aaron Wagener 2024-01-13 19:15:35 -06:00 committed by GitHub
parent 01fb44c186
commit cfd758168c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import unittest import unittest
from worlds.AutoWorld import AutoWorldRegister
from worlds.AutoWorld import AutoWorldRegister, call_all
from . import setup_solo_multiworld from . import setup_solo_multiworld
@ -53,7 +54,7 @@ class TestBase(unittest.TestCase):
f"{game_name} Item count MUST meet or exceed the number of locations", f"{game_name} Item count MUST meet or exceed the number of locations",
) )
def testItemsInDatapackage(self): def test_items_in_datapackage(self):
"""Test that any created items in the itempool are in the datapackage""" """Test that any created items in the itempool are in the datapackage"""
for game_name, world_type in AutoWorldRegister.world_types.items(): for game_name, world_type in AutoWorldRegister.world_types.items():
with self.subTest("Game", game=game_name): with self.subTest("Game", game=game_name):
@ -69,3 +70,20 @@ class TestBase(unittest.TestCase):
with self.subTest("Name should be valid", game=game_name, item=name): with self.subTest("Name should be valid", game=game_name, item=name):
self.assertIn(name, valid_names, self.assertIn(name, valid_names,
"All item descriptions must match defined item names") "All item descriptions must match defined item names")
def test_itempool_not_modified(self):
"""Test that worlds don't modify the itempool after `create_items`"""
gen_steps = ("generate_early", "create_regions", "create_items")
additional_steps = ("set_rules", "generate_basic", "pre_fill")
excluded_games = ("Links Awakening DX", "Ocarina of Time", "SMZ3")
worlds_to_test = {game: world
for game, world in AutoWorldRegister.world_types.items() if game not in excluded_games}
for game_name, world_type in worlds_to_test.items():
with self.subTest("Game", game=game_name):
multiworld = setup_solo_multiworld(world_type, gen_steps)
created_items = multiworld.itempool.copy()
for step in additional_steps:
with self.subTest("step", step=step):
call_all(multiworld, step)
self.assertEqual(created_items, multiworld.itempool,
f"{game_name} modified the itempool during {step}")

View File

@ -328,7 +328,7 @@ class World(metaclass=AutoWorldRegister):
def create_items(self) -> None: def create_items(self) -> None:
""" """
Method for creating and submitting items to the itempool. Items and Regions should *not* be created and submitted Method for creating and submitting items to the itempool. Items and Regions must *not* be created and submitted
to the MultiWorld after this step. If items need to be placed during pre_fill use `get_prefill_items`. to the MultiWorld after this step. If items need to be placed during pre_fill use `get_prefill_items`.
""" """
pass pass