Tests: Create CollectionState after MultiWorld.worlds (#4949)

This commit is contained in:
qwint
2025-05-22 08:27:18 -05:00
committed by GitHub
parent 44a78cc821
commit 95efcf6803
7 changed files with 7 additions and 6 deletions

View File

@@ -736,6 +736,7 @@ class CollectionState():
additional_copy_functions: List[Callable[[CollectionState, CollectionState], CollectionState]] = [] additional_copy_functions: List[Callable[[CollectionState, CollectionState], CollectionState]] = []
def __init__(self, parent: MultiWorld, allow_partial_entrances: bool = False): 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.prog_items = {player: Counter() for player in parent.get_all_ids()}
self.multiworld = parent self.multiworld = parent
self.reachable_regions = {player: set() for player in parent.get_all_ids()} self.reachable_regions = {player: set() for player in parent.get_all_ids()}

View File

@@ -159,7 +159,6 @@ class WorldTestBase(unittest.TestCase):
self.multiworld.game[self.player] = self.game self.multiworld.game[self.player] = self.game
self.multiworld.player_name = {self.player: "Tester"} self.multiworld.player_name = {self.player: "Tester"}
self.multiworld.set_seed(seed) self.multiworld.set_seed(seed)
self.multiworld.state = CollectionState(self.multiworld)
random.seed(self.multiworld.seed) random.seed(self.multiworld.seed)
self.multiworld.seed_name = get_seed_name(random) # only called to get same RNG progression as Generate.py self.multiworld.seed_name = get_seed_name(random) # only called to get same RNG progression as Generate.py
args = Namespace() args = Namespace()
@@ -168,6 +167,7 @@ class WorldTestBase(unittest.TestCase):
1: option.from_any(self.options.get(name, option.default)) 1: option.from_any(self.options.get(name, option.default))
}) })
self.multiworld.set_options(args) self.multiworld.set_options(args)
self.multiworld.state = CollectionState(self.multiworld)
self.world = self.multiworld.worlds[self.player] self.world = self.multiworld.worlds[self.player]
for step in gen_steps: for step in gen_steps:
call_all(self.multiworld, step) call_all(self.multiworld, step)

View File

@@ -59,13 +59,13 @@ def run_locations_benchmark():
multiworld.game[1] = game multiworld.game[1] = game
multiworld.player_name = {1: "Tester"} multiworld.player_name = {1: "Tester"}
multiworld.set_seed(0) multiworld.set_seed(0)
multiworld.state = CollectionState(multiworld)
args = argparse.Namespace() args = argparse.Namespace()
for name, option in AutoWorld.AutoWorldRegister.world_types[game].options_dataclass.type_hints.items(): for name, option in AutoWorld.AutoWorldRegister.world_types[game].options_dataclass.type_hints.items():
setattr(args, name, { setattr(args, name, {
1: option.from_any(getattr(option, "default")) 1: option.from_any(getattr(option, "default"))
}) })
multiworld.set_options(args) multiworld.set_options(args)
multiworld.state = CollectionState(multiworld)
gc.collect() gc.collect()
for step in self.gen_steps: for step in self.gen_steps:

View File

@@ -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.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.player_name = {player: f"Tester{player}" for player in multiworld.player_ids}
multiworld.set_seed(seed) multiworld.set_seed(seed)
multiworld.state = CollectionState(multiworld)
args = Namespace() args = Namespace()
for player, world_type in enumerate(worlds, 1): for player, world_type in enumerate(worlds, 1):
for key, option in world_type.options_dataclass.type_hints.items(): 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) updated_options[player] = option.from_any(option.default)
setattr(args, key, updated_options) setattr(args, key, updated_options)
multiworld.set_options(args) multiworld.set_options(args)
multiworld.state = CollectionState(multiworld)
for step in steps: for step in steps:
call_all(multiworld, step) call_all(multiworld, step)
return multiworld return multiworld

View File

@@ -10,12 +10,12 @@ class LTTPTestBase(unittest.TestCase):
from worlds.alttp.Options import Medallion from worlds.alttp.Options import Medallion
self.multiworld = MultiWorld(1) self.multiworld = MultiWorld(1)
self.multiworld.game[1] = "A Link to the Past" self.multiworld.game[1] = "A Link to the Past"
self.multiworld.state = CollectionState(self.multiworld)
self.multiworld.set_seed(None) self.multiworld.set_seed(None)
args = Namespace() args = Namespace()
for name, option in AutoWorldRegister.world_types["A Link to the Past"].options_dataclass.type_hints.items(): 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"))}) setattr(args, name, {1: option.from_any(getattr(option, "default"))})
self.multiworld.set_options(args) self.multiworld.set_options(args)
self.multiworld.state = CollectionState(self.multiworld)
self.world = self.multiworld.worlds[1] self.world = self.multiworld.worlds[1]
# by default medallion access is randomized, for unittests we set it to vanilla # by default medallion access is randomized, for unittests we set it to vanilla
self.world.options.misery_mire_medallion.value = Medallion.option_ether self.world.options.misery_mire_medallion.value = Medallion.option_ether

View File

@@ -26,13 +26,13 @@ class KDL3TestBase(WorldTestBase):
self.multiworld.game[1] = self.game self.multiworld.game[1] = self.game
self.multiworld.player_name = {1: "Tester"} self.multiworld.player_name = {1: "Tester"}
self.multiworld.set_seed(seed) self.multiworld.set_seed(seed)
self.multiworld.state = CollectionState(self.multiworld)
args = Namespace() args = Namespace()
for name, option in AutoWorld.AutoWorldRegister.world_types[self.game].options_dataclass.type_hints.items(): for name, option in AutoWorld.AutoWorldRegister.world_types[self.game].options_dataclass.type_hints.items():
setattr(args, name, { setattr(args, name, {
1: option.from_any(self.options.get(name, getattr(option, "default"))) 1: option.from_any(self.options.get(name, getattr(option, "default")))
}) })
self.multiworld.set_options(args) self.multiworld.set_options(args)
self.multiworld.state = CollectionState(self.multiworld)
self.multiworld.plando_options = PlandoOptions.connections self.multiworld.plando_options = PlandoOptions.connections
for step in gen_steps: for step in gen_steps:
call_all(self.multiworld, step) call_all(self.multiworld, step)

View File

@@ -293,12 +293,12 @@ def setup_multiworld(test_options: Iterable[Dict[str, int]] = None, seed=None) -
multiworld = MultiWorld(len(test_options)) multiworld = MultiWorld(len(test_options))
multiworld.player_name = {} multiworld.player_name = {}
multiworld.set_seed(seed) multiworld.set_seed(seed)
multiworld.state = CollectionState(multiworld)
for i in range(1, len(test_options) + 1): for i in range(1, len(test_options) + 1):
multiworld.game[i] = StardewValleyWorld.game multiworld.game[i] = StardewValleyWorld.game
multiworld.player_name.update({i: f"Tester{i}"}) multiworld.player_name.update({i: f"Tester{i}"})
args = fill_namespace_with_default(test_options) args = fill_namespace_with_default(test_options)
multiworld.set_options(args) multiworld.set_options(args)
multiworld.state = CollectionState(multiworld)
for step in gen_steps: for step in gen_steps:
call_all(multiworld, step) call_all(multiworld, step)