Stardew Valley: add assert_can_reach_region_* for better tests (#4556)
* add assert_reach_region_*; refactor existing assert_reach_location_* to allow string * rename asserts
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from typing import List
|
||||
from unittest import TestCase
|
||||
|
||||
from BaseClasses import CollectionState, Location
|
||||
from BaseClasses import CollectionState, Location, Region
|
||||
from ...stardew_rule import StardewRule, false_, MISSING_ITEM, Reach
|
||||
from ...stardew_rule.rule_explain import explain
|
||||
|
||||
@@ -40,19 +40,42 @@ class RuleAssertMixin(TestCase):
|
||||
raise AssertionError(f"Error while checking rule {rule}: {e}"
|
||||
f"\nExplanation: {expl}")
|
||||
|
||||
def assert_reach_location_true(self, location: Location, state: CollectionState):
|
||||
expl = explain(Reach(location.name, "Location", 1), state)
|
||||
def assert_can_reach_location(self, location: Location | str, state: CollectionState) -> None:
|
||||
location_name = location.name if isinstance(location, Location) else location
|
||||
expl = explain(Reach(location_name, "Location", 1), state)
|
||||
try:
|
||||
can_reach = location.can_reach(state)
|
||||
can_reach = state.can_reach_location(location_name, 1)
|
||||
self.assertTrue(can_reach, expl)
|
||||
except KeyError as e:
|
||||
raise AssertionError(f"Error while checking location {location.name}: {e}"
|
||||
raise AssertionError(f"Error while checking location {location_name}: {e}"
|
||||
f"\nExplanation: {expl}")
|
||||
|
||||
def assert_reach_location_false(self, location: Location, state: CollectionState):
|
||||
expl = explain(Reach(location.name, "Location", 1), state, expected=False)
|
||||
def assert_cannot_reach_location(self, location: Location | str, state: CollectionState) -> None:
|
||||
location_name = location.name if isinstance(location, Location) else location
|
||||
expl = explain(Reach(location_name, "Location", 1), state, expected=False)
|
||||
try:
|
||||
self.assertFalse(location.can_reach(state), expl)
|
||||
can_reach = state.can_reach_location(location_name, 1)
|
||||
self.assertFalse(can_reach, expl)
|
||||
except KeyError as e:
|
||||
raise AssertionError(f"Error while checking location {location.name}: {e}"
|
||||
raise AssertionError(f"Error while checking location {location_name}: {e}"
|
||||
f"\nExplanation: {expl}")
|
||||
|
||||
def assert_can_reach_region(self, region: Region | str, state: CollectionState) -> None:
|
||||
region_name = region.name if isinstance(region, Region) else region
|
||||
expl = explain(Reach(region_name, "Region", 1), state)
|
||||
try:
|
||||
can_reach = state.can_reach_region(region_name, 1)
|
||||
self.assertTrue(can_reach, expl)
|
||||
except KeyError as e:
|
||||
raise AssertionError(f"Error while checking region {region_name}: {e}"
|
||||
f"\nExplanation: {expl}")
|
||||
|
||||
def assert_cannot_reach_region(self, region: Region | str, state: CollectionState) -> None:
|
||||
region_name = region.name if isinstance(region, Region) else region
|
||||
expl = explain(Reach(region_name, "Region", 1), state, expected=False)
|
||||
try:
|
||||
can_reach = state.can_reach_region(region_name, 1)
|
||||
self.assertFalse(can_reach, expl)
|
||||
except KeyError as e:
|
||||
raise AssertionError(f"Error while checking region {region_name}: {e}"
|
||||
f"\nExplanation: {expl}")
|
||||
|
||||
@@ -53,7 +53,7 @@ class WorldAssertMixin(RuleAssertMixin, TestCase):
|
||||
|
||||
def assert_can_reach_everything(self, multiworld: MultiWorld):
|
||||
for location in multiworld.get_locations():
|
||||
self.assert_reach_location_true(location, multiworld.state)
|
||||
self.assert_can_reach_location(location, multiworld.state)
|
||||
|
||||
def assert_basic_checks(self, multiworld: MultiWorld):
|
||||
self.assert_same_number_items_locations(multiworld)
|
||||
|
||||
Reference in New Issue
Block a user