From cfd758168cc46b7fd9981a12de868a9c80a010aa Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Sat, 13 Jan 2024 19:15:35 -0600 Subject: [PATCH] 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 --- test/general/test_items.py | 22 ++++++++++++++++++++-- worlds/AutoWorld.py | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/general/test_items.py b/test/general/test_items.py index 2d8775d5..bd6c3fd8 100644 --- a/test/general/test_items.py +++ b/test/general/test_items.py @@ -1,5 +1,6 @@ import unittest -from worlds.AutoWorld import AutoWorldRegister + +from worlds.AutoWorld import AutoWorldRegister, call_all 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", ) - def testItemsInDatapackage(self): + def test_items_in_datapackage(self): """Test that any created items in the itempool are in the datapackage""" for game_name, world_type in AutoWorldRegister.world_types.items(): 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): self.assertIn(name, valid_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}") diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index f56c39f6..d4e463db 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -328,7 +328,7 @@ class World(metaclass=AutoWorldRegister): 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`. """ pass