diff --git a/worlds/stardew_valley/test/TestGeneration.py b/worlds/stardew_valley/test/TestGeneration.py index 5e60f8e8..7b153567 100644 --- a/worlds/stardew_valley/test/TestGeneration.py +++ b/worlds/stardew_valley/test/TestGeneration.py @@ -131,15 +131,13 @@ class TestProgressiveElevator(SVTestBase): 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 @@ -171,27 +169,24 @@ class TestSkullCavernLogic(SVTestBase): 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 diff --git a/worlds/stardew_valley/test/TestWalnutsanity.py b/worlds/stardew_valley/test/TestWalnutsanity.py index 418eaa87..7111174d 100644 --- a/worlds/stardew_valley/test/TestWalnutsanity.py +++ b/worlds/stardew_valley/test/TestWalnutsanity.py @@ -3,6 +3,7 @@ import unittest 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): @@ -48,24 +49,27 @@ class TestWalnutsanityNone(SVWalnutsanityTestBase): 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): @@ -155,9 +159,9 @@ class TestWalnutsanityPuzzlesAndBushes(SVWalnutsanityTestBase): 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): @@ -218,20 +222,20 @@ class TestWalnutsanityAll(SVWalnutsanityTestBase): # 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) diff --git a/worlds/stardew_valley/test/bases.py b/worlds/stardew_valley/test/bases.py index a2852183..4370c05d 100644 --- a/worlds/stardew_valley/test/bases.py +++ b/worlds/stardew_valley/test/bases.py @@ -4,10 +4,10 @@ import os 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 @@ -18,6 +18,7 @@ from ..logic.time_logic import MONTH_COEFFICIENT from ..options import StardewValleyOption, options logger = logging.getLogger(__name__) + DEFAULT_TEST_SEED = get_seed() logger.info(f"Default Test Seed: {DEFAULT_TEST_SEED}") @@ -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, @@ -121,18 +122,17 @@ class SVTestBase(RuleAssertMixin, WorldTestBase, SVTestCase): 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) @@ -162,34 +162,44 @@ class SVTestBase(RuleAssertMixin, WorldTestBase, SVTestCase): 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]]: @@ -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 @@ -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) @@ -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: @@ -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 = [] diff --git a/worlds/stardew_valley/test/options/utils.py b/worlds/stardew_valley/test/options/utils.py index 9f02105d..1ed88974 100644 --- a/worlds/stardew_valley/test/options/utils.py +++ b/worlds/stardew_valley/test/options/utils.py @@ -7,7 +7,7 @@ from ... import StardewValleyWorld 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 {} @@ -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 = {} diff --git a/worlds/stardew_valley/test/rules/TestArcades.py b/worlds/stardew_valley/test/rules/TestArcades.py index 407f2999..b820fda7 100644 --- a/worlds/stardew_valley/test/rules/TestArcades.py +++ b/worlds/stardew_valley/test/rules/TestArcades.py @@ -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") @@ -21,18 +21,18 @@ class TestArcadeMachinesLogic(SVTestBase): 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) @@ -41,9 +41,9 @@ class TestArcadeMachinesLogic(SVTestBase): 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) @@ -57,9 +57,9 @@ class TestArcadeMachinesLogic(SVTestBase): 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) @@ -80,9 +80,9 @@ class TestArcadeMachinesLogic(SVTestBase): 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)