Skip to content

Commit 86c74da

Browse files
alwaysintrebleNewSoupVi
authored andcommitted
Tests: Clean up some of the fill test helpers a bit (ArchipelagoMW#2935)
* Tests: Clean up some of the fill test helpers a bit * fix some formatting --------- Co-authored-by: NewSoupVi <[email protected]>
1 parent 31f8ee3 commit 86c74da

File tree

2 files changed

+107
-97
lines changed

2 files changed

+107
-97
lines changed

test/general/__init__.py

+62-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from argparse import Namespace
22
from typing import List, Optional, Tuple, Type, Union
33

4-
from BaseClasses import CollectionState, MultiWorld
4+
from BaseClasses import CollectionState, Item, ItemClassification, Location, MultiWorld, Region
55
from worlds.AutoWorld import World, call_all
66

77
gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill")
@@ -17,19 +17,21 @@ def setup_solo_multiworld(
1717
:param steps: The gen steps that should be called on the generated multiworld before returning. Default calls
1818
steps through pre_fill
1919
:param seed: The seed to be used when creating this multiworld
20+
:return: The generated multiworld
2021
"""
2122
return setup_multiworld(world_type, steps, seed)
2223

2324

2425
def setup_multiworld(worlds: Union[List[Type[World]], Type[World]], steps: Tuple[str, ...] = gen_steps,
25-
seed: Optional[int] = None) -> MultiWorld:
26+
seed: Optional[int] = None) -> MultiWorld:
2627
"""
2728
Creates a multiworld with a player for each provided world type, allowing duplicates, setting default options, and
2829
calling the provided gen steps.
2930
30-
:param worlds: type/s of worlds to generate a multiworld for
31-
:param steps: gen steps that should be called before returning. Default calls through pre_fill
31+
:param worlds: Type/s of worlds to generate a multiworld for
32+
:param steps: Gen steps that should be called before returning. Default calls through pre_fill
3233
:param seed: The seed to be used when creating this multiworld
34+
:return: The generated multiworld
3335
"""
3436
if not isinstance(worlds, list):
3537
worlds = [worlds]
@@ -49,3 +51,59 @@ def setup_multiworld(worlds: Union[List[Type[World]], Type[World]], steps: Tuple
4951
for step in steps:
5052
call_all(multiworld, step)
5153
return multiworld
54+
55+
56+
class TestWorld(World):
57+
game = f"Test Game"
58+
item_name_to_id = {}
59+
location_name_to_id = {}
60+
hidden = True
61+
62+
63+
def generate_test_multiworld(players: int = 1) -> MultiWorld:
64+
"""
65+
Generates a multiworld using a special Test Case World class, and seed of 0.
66+
67+
:param players: Number of players to generate the multiworld for
68+
:return: The generated test multiworld
69+
"""
70+
multiworld = setup_multiworld([TestWorld] * players, seed=0)
71+
multiworld.regions += [Region("Menu", player_id + 1, multiworld) for player_id in range(players)]
72+
73+
return multiworld
74+
75+
76+
def generate_locations(count: int, player_id: int, region: Region, address: Optional[int] = None,
77+
tag: str = "") -> List[Location]:
78+
"""
79+
Generates the specified amount of locations for the player and adds them to the specified region.
80+
81+
:param count: Number of locations to create
82+
:param player_id: ID of the player to create the locations for
83+
:param address: Address for the specified locations. They will all share the same address if multiple are created
84+
:param region: Parent region to add these locations to
85+
:param tag: Tag to add to the name of the generated locations
86+
:return: List containing the created locations
87+
"""
88+
prefix = f"player{player_id}{tag}_location"
89+
90+
locations = [Location(player_id, f"{prefix}{i}", address, region) for i in range(count)]
91+
region.locations += locations
92+
return locations
93+
94+
95+
def generate_items(count: int, player_id: int, advancement: bool = False, code: int = None) -> List[Item]:
96+
"""
97+
Generates the specified amount of items for the target player.
98+
99+
:param count: The amount of items to create
100+
:param player_id: ID of the player to create the items for
101+
:param advancement: Whether the created items should be advancement
102+
:param code: The code the items should be created with
103+
:return: List containing the created items
104+
"""
105+
item_type = "prog" if advancement else ""
106+
classification = ItemClassification.progression if advancement else ItemClassification.filler
107+
108+
items = [Item(f"player{player_id}_{item_type}item{i}", classification, code, player_id) for i in range(count)]
109+
return items

0 commit comments

Comments
 (0)