From 95efcf6803c7d60e0994e15dd18d1f00e9ff31a7 Mon Sep 17 00:00:00 2001 From: qwint Date: Thu, 22 May 2025 08:27:18 -0500 Subject: [PATCH] Tests: Create CollectionState after MultiWorld.worlds (#4949) --- BaseClasses.py | 1 + test/bases.py | 2 +- test/benchmark/locations.py | 2 +- test/general/__init__.py | 2 +- worlds/alttp/test/__init__.py | 2 +- worlds/kdl3/test/__init__.py | 2 +- worlds/stardew_valley/test/bases.py | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index f480cbbd..9e1a0a0d 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -736,6 +736,7 @@ class CollectionState(): additional_copy_functions: List[Callable[[CollectionState, CollectionState], CollectionState]] = [] def __init__(self, parent: MultiWorld, allow_partial_entrances: bool = False): + assert parent.worlds, "CollectionState created without worlds initialized in parent" self.prog_items = {player: Counter() for player in parent.get_all_ids()} self.multiworld = parent self.reachable_regions = {player: set() for player in parent.get_all_ids()} diff --git a/test/bases.py b/test/bases.py index a3ea2331..c9610c86 100644 --- a/test/bases.py +++ b/test/bases.py @@ -159,7 +159,6 @@ class WorldTestBase(unittest.TestCase): self.multiworld.game[self.player] = self.game self.multiworld.player_name = {self.player: "Tester"} self.multiworld.set_seed(seed) - self.multiworld.state = CollectionState(self.multiworld) random.seed(self.multiworld.seed) self.multiworld.seed_name = get_seed_name(random) # only called to get same RNG progression as Generate.py args = Namespace() @@ -168,6 +167,7 @@ class WorldTestBase(unittest.TestCase): 1: option.from_any(self.options.get(name, option.default)) }) self.multiworld.set_options(args) + self.multiworld.state = CollectionState(self.multiworld) self.world = self.multiworld.worlds[self.player] for step in gen_steps: call_all(self.multiworld, step) diff --git a/test/benchmark/locations.py b/test/benchmark/locations.py index 857e1882..16667a17 100644 --- a/test/benchmark/locations.py +++ b/test/benchmark/locations.py @@ -59,13 +59,13 @@ def run_locations_benchmark(): multiworld.game[1] = game multiworld.player_name = {1: "Tester"} multiworld.set_seed(0) - multiworld.state = CollectionState(multiworld) args = argparse.Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types[game].options_dataclass.type_hints.items(): setattr(args, name, { 1: option.from_any(getattr(option, "default")) }) multiworld.set_options(args) + multiworld.state = CollectionState(multiworld) gc.collect() for step in self.gen_steps: diff --git a/test/general/__init__.py b/test/general/__init__.py index 6c4d5092..34df741a 100644 --- a/test/general/__init__.py +++ b/test/general/__init__.py @@ -49,7 +49,6 @@ def setup_multiworld(worlds: Union[List[Type[World]], Type[World]], steps: Tuple multiworld.game = {player: world_type.game for player, world_type in enumerate(worlds, 1)} multiworld.player_name = {player: f"Tester{player}" for player in multiworld.player_ids} multiworld.set_seed(seed) - multiworld.state = CollectionState(multiworld) args = Namespace() for player, world_type in enumerate(worlds, 1): for key, option in world_type.options_dataclass.type_hints.items(): @@ -57,6 +56,7 @@ def setup_multiworld(worlds: Union[List[Type[World]], Type[World]], steps: Tuple updated_options[player] = option.from_any(option.default) setattr(args, key, updated_options) multiworld.set_options(args) + multiworld.state = CollectionState(multiworld) for step in steps: call_all(multiworld, step) return multiworld diff --git a/worlds/alttp/test/__init__.py b/worlds/alttp/test/__init__.py index 307e7538..031d5086 100644 --- a/worlds/alttp/test/__init__.py +++ b/worlds/alttp/test/__init__.py @@ -10,12 +10,12 @@ class LTTPTestBase(unittest.TestCase): from worlds.alttp.Options import Medallion self.multiworld = MultiWorld(1) self.multiworld.game[1] = "A Link to the Past" - self.multiworld.state = CollectionState(self.multiworld) self.multiworld.set_seed(None) args = Namespace() for name, option in AutoWorldRegister.world_types["A Link to the Past"].options_dataclass.type_hints.items(): setattr(args, name, {1: option.from_any(getattr(option, "default"))}) self.multiworld.set_options(args) + self.multiworld.state = CollectionState(self.multiworld) self.world = self.multiworld.worlds[1] # by default medallion access is randomized, for unittests we set it to vanilla self.world.options.misery_mire_medallion.value = Medallion.option_ether diff --git a/worlds/kdl3/test/__init__.py b/worlds/kdl3/test/__init__.py index 92f1d726..46f78aad 100644 --- a/worlds/kdl3/test/__init__.py +++ b/worlds/kdl3/test/__init__.py @@ -26,13 +26,13 @@ class KDL3TestBase(WorldTestBase): self.multiworld.game[1] = self.game self.multiworld.player_name = {1: "Tester"} self.multiworld.set_seed(seed) - self.multiworld.state = CollectionState(self.multiworld) args = Namespace() for name, option in AutoWorld.AutoWorldRegister.world_types[self.game].options_dataclass.type_hints.items(): setattr(args, name, { 1: option.from_any(self.options.get(name, getattr(option, "default"))) }) self.multiworld.set_options(args) + self.multiworld.state = CollectionState(self.multiworld) self.multiworld.plando_options = PlandoOptions.connections for step in gen_steps: call_all(self.multiworld, step) diff --git a/worlds/stardew_valley/test/bases.py b/worlds/stardew_valley/test/bases.py index 64ada395..affc20cd 100644 --- a/worlds/stardew_valley/test/bases.py +++ b/worlds/stardew_valley/test/bases.py @@ -293,12 +293,12 @@ def setup_multiworld(test_options: Iterable[Dict[str, int]] = None, seed=None) - multiworld = MultiWorld(len(test_options)) multiworld.player_name = {} multiworld.set_seed(seed) - multiworld.state = CollectionState(multiworld) for i in range(1, len(test_options) + 1): multiworld.game[i] = StardewValleyWorld.game multiworld.player_name.update({i: f"Tester{i}"}) args = fill_namespace_with_default(test_options) multiworld.set_options(args) + multiworld.state = CollectionState(multiworld) for step in gen_steps: call_all(multiworld, step)