Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9c86808
changes
Jouramie Feb 8, 2025
c885fd1
cherry pick stuff
Jouramie Feb 8, 2025
2fd1f35
use newly create methods more
Jouramie Nov 24, 2024
bdc10f5
use new assets to ease readability
Jouramie Nov 24, 2024
0a161f2
remove unneeded assert
Jouramie Feb 8, 2025
cfc91ec
add assert region adapters
Jouramie Feb 8, 2025
82ac84b
use new asserts yay
Jouramie Feb 8, 2025
333f299
self review
Jouramie Feb 8, 2025
cecb60c
self review
Jouramie Feb 8, 2025
7b4821c
review
Jouramie Feb 8, 2025
808d778
replace parrot express with transportation constant
Jouramie Feb 8, 2025
20b7504
Merge remote-tracking branch 'archipelago/main' into StardewValley/us…
Jouramie Mar 22, 2025
0aedded
Merge remote-tracking branch 'archipelago/main' into StardewValley/us…
Jouramie Mar 24, 2025
d611599
bullshit commit again
Jouramie Mar 24, 2025
3396d60
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie Apr 10, 2025
113d99e
revert a bunch of off topic changes
Jouramie Apr 10, 2025
f9431bb
these changes seems to be on topic
Jouramie Apr 10, 2025
ba55e91
Merge remote-tracking branch 'origin/main' into StardewValley/use-new…
Jouramie Apr 18, 2025
0bcaa2d
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie May 12, 2025
5361fb8
Merge remote-tracking branch 'archipelago/main' into StardewValley/us…
Jouramie May 17, 2025
a3504a6
revert some undesired merge changes
Jouramie May 17, 2025
0c9da83
review imports
Jouramie May 17, 2025
0891e1f
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie May 22, 2025
e6b5a99
Merge remote-tracking branch 'archipelago/main' into StardewValley/us…
Jouramie May 25, 2025
49ea6fe
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie Jun 27, 2025
88d6870
use type instead of instance in some options
Jouramie Jun 28, 2025
b749ed7
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie Jul 19, 2025
e142f29
properly return super
Jouramie Jul 27, 2025
6e9985e
review
Jouramie Aug 31, 2025
fa0d5cd
change one str to use a constnat
Jouramie Aug 31, 2025
3ce37e2
Merge branch 'main' into StardewValley/use-new-asserts-in-tests
Jouramie Aug 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions worlds/stardew_valley/test/TestGeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,13 @@ def test_given_elevator_to_floor_105_when_find_another_elevator_then_has_access_
items_for_115 = self.generate_items_for_mine_115()
last_elevator = self.get_item_by_name("Progressive Mine Elevator")
self.collect(items_for_115)
floor_115 = self.multiworld.get_region("The Mines - Floor 115", self.player)
floor_120 = self.multiworld.get_region("The Mines - Floor 120", self.player)

self.assertTrue(floor_115.can_reach(self.multiworld.state))
self.assertFalse(floor_120.can_reach(self.multiworld.state))
self.assert_can_reach_region(Region.mines_floor_115)
self.assert_cannot_reach_region(Region.mines_floor_120)

self.collect(last_elevator)

self.assertTrue(floor_120.can_reach(self.multiworld.state))
self.assert_can_reach_region(Region.mines_floor_120)

def generate_items_for_mine_115(self) -> List[Item]:
pickaxes = [self.get_item_by_name("Progressive Pickaxe")] * 2
Expand Down Expand Up @@ -171,27 +169,24 @@ def test_given_access_to_floor_115_when_find_more_tools_then_has_access_to_skull
items_for_skull_50 = self.generate_items_for_skull_50()
items_for_skull_100 = self.generate_items_for_skull_100()
self.collect(items_for_115)
floor_115 = self.multiworld.get_region(Region.mines_floor_115, self.player)
skull_25 = self.multiworld.get_region(Region.skull_cavern_25, self.player)
skull_75 = self.multiworld.get_region(Region.skull_cavern_75, self.player)

self.assertTrue(floor_115.can_reach(self.multiworld.state))
self.assertFalse(skull_25.can_reach(self.multiworld.state))
self.assertFalse(skull_75.can_reach(self.multiworld.state))
self.assert_can_reach_region(Region.mines_floor_115)
self.assert_cannot_reach_region(Region.skull_cavern_25)
self.assert_cannot_reach_region(Region.skull_cavern_75)

self.remove(items_for_115)
self.collect(items_for_skull_50)

self.assertTrue(floor_115.can_reach(self.multiworld.state))
self.assertTrue(skull_25.can_reach(self.multiworld.state))
self.assertFalse(skull_75.can_reach(self.multiworld.state))
self.assert_can_reach_region(Region.mines_floor_115)
self.assert_can_reach_region(Region.skull_cavern_25)
self.assert_cannot_reach_region(Region.skull_cavern_75)

self.remove(items_for_skull_50)
self.collect(items_for_skull_100)

self.assertTrue(floor_115.can_reach(self.multiworld.state))
self.assertTrue(skull_25.can_reach(self.multiworld.state))
self.assertTrue(skull_75.can_reach(self.multiworld.state))
self.assert_can_reach_region(Region.mines_floor_115)
self.assert_can_reach_region(Region.skull_cavern_25)
self.assert_can_reach_region(Region.skull_cavern_75)

def generate_items_for_mine_115(self) -> List[Item]:
pickaxes = [self.get_item_by_name("Progressive Pickaxe")] * 2
Expand Down
34 changes: 19 additions & 15 deletions worlds/stardew_valley/test/TestWalnutsanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .bases import SVTestBase
from ..options import ExcludeGingerIsland, Walnutsanity, ToolProgression, SkillProgression
from ..strings.ap_names.ap_option_names import WalnutsanityOptionName
from ..strings.ap_names.transport_names import Transportation


class SVWalnutsanityTestBase(SVTestBase):
Expand Down Expand Up @@ -48,24 +49,27 @@ def test_logic_received_walnuts(self):
self.collect("Island West Turtle")
self.collect("Progressive House")
self.collect("5 Golden Walnuts", 10)
self.assert_cannot_reach_location(Transportation.parrot_express)

self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.collect("Island North Turtle")
self.collect("Island Resort")
self.collect("Open Professor Snail Cave")
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)

self.collect("Dig Site Bridge")
self.collect("Island Farmhouse")
self.collect("Qi Walnut Room")
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)

self.collect("Combat Level", 10)
self.collect("Mining Level", 10)
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)

self.collect("Progressive Slingshot")
self.collect("Progressive Weapon", 5)
self.collect("Progressive Pickaxe", 4)
self.collect("Progressive Watering Can", 4)
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)


class TestWalnutsanityPuzzles(SVWalnutsanityTestBase):
Expand Down Expand Up @@ -155,9 +159,9 @@ def test_logic_received_walnuts(self):
self.collect("Island West Turtle")
self.collect("5 Golden Walnuts", 5)

self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)
self.collect("Island North Turtle")
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)


class TestWalnutsanityDigSpots(SVWalnutsanityTestBase):
Expand Down Expand Up @@ -218,20 +222,20 @@ def test_logic_received_walnuts(self):
# You need to receive 40, and collect 4
self.collect("Island Obelisk")
self.collect("Island West Turtle")
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)
items = self.collect("5 Golden Walnuts", 8)
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)
self.remove(items)
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)
items = self.collect("3 Golden Walnuts", 14)
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)
self.remove(items)
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)
items = self.collect("Golden Walnut", 40)
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)
self.remove(items)
self.assertFalse(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_cannot_reach_location(Transportation.parrot_express)
self.collect("5 Golden Walnuts", 4)
self.collect("3 Golden Walnuts", 6)
self.collect("Golden Walnut", 2)
self.assertTrue(self.multiworld.state.can_reach_location("Parrot Express", self.player))
self.assert_can_reach_location(Transportation.parrot_express)
52 changes: 30 additions & 22 deletions worlds/stardew_valley/test/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import threading
import typing
import unittest
from collections.abc import Iterable
from contextlib import contextmanager
from typing import Optional, Dict, Union, Any, List, Iterable

from BaseClasses import get_seed, MultiWorld, Location, Item, CollectionState, Entrance
from BaseClasses import get_seed, MultiWorld, Location, Item, Region, CollectionState, Entrance
from test.bases import WorldTestBase
from test.general import gen_steps, setup_solo_multiworld as setup_base_solo_multiworld
from worlds.AutoWorld import call_all
Expand All @@ -18,6 +18,7 @@
from ..options import StardewValleyOption, options

logger = logging.getLogger(__name__)

DEFAULT_TEST_SEED = get_seed()
logger.info(f"Default Test Seed: {DEFAULT_TEST_SEED}")

Expand All @@ -39,7 +40,7 @@ class SVTestCase(unittest.TestCase):
@contextmanager
def solo_world_sub_test(self, msg: str | None = None,
/,
world_options: dict[str | type[StardewValleyOption], Any] | None = None,
world_options: dict[str | type[StardewValleyOption], typing.Any] | None = None,
*,
seed=DEFAULT_TEST_SEED,
world_caching=True,
Expand Down Expand Up @@ -121,18 +122,17 @@ def collect_all_except(self, item_to_not_collect: str):
if item.name != item_to_not_collect:
self.multiworld.state.collect(item)

def get_real_locations(self) -> List[Location]:
def get_real_locations(self) -> list[Location]:
return [location for location in self.multiworld.get_locations(self.player) if location.address is not None]

def get_real_location_names(self) -> List[str]:
def get_real_location_names(self) -> list[str]:
return [location.name for location in self.get_real_locations()]

def collect(self, item: Union[str, Item, Iterable[Item]], count: int = 1) -> Union[None, Item, List[Item]]:
def collect(self, item: str | Item | Iterable[Item], count: int = 1) -> Item | list[Item] | None:
assert count > 0

if not isinstance(item, str):
super().collect(item)
return
return super().collect(item)

if count == 1:
item = self.create_item(item)
Expand Down Expand Up @@ -162,34 +162,44 @@ def reset_collection_state(self) -> None:
def assert_rule_true(self, rule: StardewRule, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
super().assert_rule_true(rule, state)
return super().assert_rule_true(rule, state)

def assert_rule_false(self, rule: StardewRule, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
super().assert_rule_false(rule, state)
return super().assert_rule_false(rule, state)

def assert_can_reach_location(self, location: Location | str, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
super().assert_can_reach_location(location, state)
return super().assert_can_reach_location(location, state)

def assert_cannot_reach_location(self, location: Location | str, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
super().assert_cannot_reach_location(location, state)
return super().assert_cannot_reach_location(location, state)

def assert_can_reach_region(self, region: Region | str, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
return super().assert_can_reach_region(region, state)

def assert_cannot_reach_region(self, region: Region | str, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
return super().assert_cannot_reach_region(region, state)

def assert_can_reach_entrance(self, entrance: Entrance | str, state: CollectionState | None = None) -> None:
if state is None:
state = self.multiworld.state
super().assert_can_reach_entrance(entrance, state)
return super().assert_can_reach_entrance(entrance, state)


pre_generated_worlds = {}


@contextmanager
def solo_multiworld(world_options: dict[str | type[StardewValleyOption], Any] | None = None,
def solo_multiworld(world_options: dict[str | type[StardewValleyOption], typing.Any] | None = None,
*,
seed=DEFAULT_TEST_SEED,
world_caching=True) -> Iterable[tuple[MultiWorld, StardewValleyWorld]]:
Expand All @@ -200,13 +210,11 @@ def solo_multiworld(world_options: dict[str | type[StardewValleyOption], Any] |
multiworld = setup_solo_multiworld(world_options, seed)
try:
multiworld.lock.acquire()
world = multiworld.worlds[1]

original_state = multiworld.state.copy()
original_itempool = multiworld.itempool.copy()
unfilled_locations = multiworld.get_unfilled_locations(1)

yield multiworld, typing.cast(StardewValleyWorld, world)
yield multiworld, typing.cast(StardewValleyWorld, multiworld.worlds[1])

multiworld.state = original_state
multiworld.itempool = original_itempool
Expand All @@ -217,9 +225,9 @@ def solo_multiworld(world_options: dict[str | type[StardewValleyOption], Any] |


# Mostly a copy of test.general.setup_solo_multiworld, I just don't want to change the core.
def setup_solo_multiworld(test_options: Optional[Dict[Union[str, StardewValleyOption], str]] = None,
def setup_solo_multiworld(test_options: dict[str | type[StardewValleyOption], str] | None = None,
seed=DEFAULT_TEST_SEED,
_cache: Dict[frozenset, MultiWorld] = {}, # noqa
_cache: dict[frozenset, MultiWorld] = {}, # noqa
_steps=gen_steps) -> MultiWorld:
test_options = parse_class_option_keys(test_options)

Expand Down Expand Up @@ -276,7 +284,7 @@ def make_hashable(test_options, seed):
return frozenset(test_options.items()).union({("seed", seed)})


def search_world_cache(cache: Dict[frozenset, MultiWorld], frozen_options: frozenset) -> Optional[MultiWorld]:
def search_world_cache(cache: dict[frozenset, MultiWorld], frozen_options: frozenset) -> MultiWorld | None:
try:
return cache[frozen_options]
except KeyError:
Expand All @@ -286,12 +294,12 @@ def search_world_cache(cache: Dict[frozenset, MultiWorld], frozen_options: froze
return None


def add_to_world_cache(cache: Dict[frozenset, MultiWorld], frozen_options: frozenset, multi_world: MultiWorld) -> None:
def add_to_world_cache(cache: dict[frozenset, MultiWorld], frozen_options: frozenset, multi_world: MultiWorld) -> None:
# We could complete the key with all the default options, but that does not seem to improve performances.
cache[frozen_options] = multi_world


def setup_multiworld(test_options: Iterable[Dict[str, int]] = None, seed=None) -> MultiWorld: # noqa
def setup_multiworld(test_options: Iterable[dict[str, int]] | None = None, seed=None) -> MultiWorld: # noqa
if test_options is None:
test_options = []

Expand Down
4 changes: 2 additions & 2 deletions worlds/stardew_valley/test/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ...options import StardewValleyOptions, StardewValleyOption


def parse_class_option_keys(test_options: dict[str | StardewValleyOption, Any] | None) -> dict:
def parse_class_option_keys(test_options: dict[str | type[StardewValleyOption], Any] | None) -> dict:
""" Now the option class is allowed as key. """
if test_options is None:
return {}
Expand All @@ -25,7 +25,7 @@ def parse_class_option_keys(test_options: dict[str | StardewValleyOption, Any] |
return parsed_options


def fill_dataclass_with_default(test_options: dict[str | StardewValleyOption, Any] | None) -> StardewValleyOptions:
def fill_dataclass_with_default(test_options: dict[str | type[StardewValleyOption], Any] | None) -> StardewValleyOptions:
test_options = parse_class_option_keys(test_options)

filled_options = {}
Expand Down
36 changes: 18 additions & 18 deletions worlds/stardew_valley/test/rules/TestArcades.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class TestArcadeMachinesLogic(SVTestBase):
}

def test_prairie_king(self):
self.assertFalse(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_cannot_reach_region("JotPK World 1")
self.assert_cannot_reach_region("JotPK World 2")
self.assert_cannot_reach_region("JotPK World 3")
self.assert_cannot_reach_location("Journey of the Prairie King Victory")

boots = self.create_item("JotPK: Progressive Boots")
Expand All @@ -21,18 +21,18 @@ def test_prairie_king(self):

self.multiworld.state.collect(boots)
self.multiworld.state.collect(gun)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_can_reach_region("JotPK World 1")
self.assert_cannot_reach_region("JotPK World 2")
self.assert_cannot_reach_region("JotPK World 3")
self.assert_cannot_reach_location("Journey of the Prairie King Victory")
self.remove(boots)
self.remove(gun)

self.multiworld.state.collect(boots)
self.multiworld.state.collect(boots)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_can_reach_region("JotPK World 1")
self.assert_cannot_reach_region("JotPK World 2")
self.assert_cannot_reach_region("JotPK World 3")
self.assert_cannot_reach_location("Journey of the Prairie King Victory")
self.remove(boots)
self.remove(boots)
Expand All @@ -41,9 +41,9 @@ def test_prairie_king(self):
self.multiworld.state.collect(gun)
self.multiworld.state.collect(ammo)
self.multiworld.state.collect(life)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertFalse(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_can_reach_region("JotPK World 1")
self.assert_can_reach_region("JotPK World 2")
self.assert_cannot_reach_region("JotPK World 3")
self.assert_cannot_reach_location("Journey of the Prairie King Victory")
self.remove(boots)
self.remove(gun)
Expand All @@ -57,9 +57,9 @@ def test_prairie_king(self):
self.multiworld.state.collect(ammo)
self.multiworld.state.collect(life)
self.multiworld.state.collect(drop)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_can_reach_region("JotPK World 1")
self.assert_can_reach_region("JotPK World 2")
self.assert_can_reach_region("JotPK World 3")
self.assert_cannot_reach_location("Journey of the Prairie King Victory")
self.remove(boots)
self.remove(gun)
Expand All @@ -80,9 +80,9 @@ def test_prairie_king(self):
self.multiworld.state.collect(ammo)
self.multiworld.state.collect(life)
self.multiworld.state.collect(drop)
self.assertTrue(self.world.logic.region.can_reach("JotPK World 1")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 2")(self.multiworld.state))
self.assertTrue(self.world.logic.region.can_reach("JotPK World 3")(self.multiworld.state))
self.assert_can_reach_region("JotPK World 1")
self.assert_can_reach_region("JotPK World 2")
self.assert_can_reach_region("JotPK World 3")
self.assert_can_reach_location("Journey of the Prairie King Victory")
self.remove(boots)
self.remove(boots)
Expand Down
Loading