Skip to content

Commit

Permalink
fix huge memory leak in long tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouramie authored and agilbert1412 committed Feb 28, 2024
1 parent 8a5810c commit bd5c589
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 351 deletions.
5 changes: 3 additions & 2 deletions worlds/stardew_valley/test/TestCrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@


class TestCropsanityRules(SVTestBase):
options = {options.Cropsanity.internal_name: options.Cropsanity.option_enabled}
options = {
options.Cropsanity.internal_name: options.Cropsanity.option_enabled
}

def test_need_greenhouse_for_cactus(self):
harvest_cactus = self.world.logic.region.can_reach_location("Harvest Cactus Fruit")
Expand All @@ -16,4 +18,3 @@ def test_need_greenhouse_for_cactus(self):

self.multiworld.state.collect(self.world.create_item("Greenhouse"), event=False)
self.assert_rule_true(harvest_cactus, self.multiworld.state)

24 changes: 15 additions & 9 deletions worlds/stardew_valley/test/TestDynamicGoals.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def create_and_collect_fishing_access_items(tester: SVTestBase) -> List[Tuple[St


class TestMasterAnglerNoFishsanity(WorldAssertMixin, SVTestBase):
options = {options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_none,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_false}
options = {
options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_none,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_false
}

def test_need_all_fish_to_win(self):
collect_fishing_abilities(self)
Expand All @@ -63,9 +65,11 @@ def test_need_all_fish_to_win(self):


class TestMasterAnglerNoFishsanityNoGingerIsland(WorldAssertMixin, SVTestBase):
options = {options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_none,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_true}
options = {
options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_none,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_true
}

def test_need_fish_to_win(self):
collect_fishing_abilities(self)
Expand All @@ -83,9 +87,11 @@ def test_need_fish_to_win(self):


class TestMasterAnglerFishsanityNoHardFish(WorldAssertMixin, SVTestBase):
options = {options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_exclude_hard_fish,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_false}
options = {
options.Goal.internal_name: options.Goal.option_master_angler,
options.Fishsanity.internal_name: options.Fishsanity.option_exclude_hard_fish,
options.ExcludeGingerIsland.internal_name: options.ExcludeGingerIsland.option_false
}

def test_need_fish_to_win(self):
collect_fishing_abilities(self)
Expand Down
101 changes: 51 additions & 50 deletions worlds/stardew_valley/test/TestGeneration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import typing
from typing import List

from BaseClasses import ItemClassification, MultiWorld, Item
from . import setup_solo_multiworld, SVTestBase, get_minsanity_options, allsanity_options_without_mods, \
allsanity_options_with_mods, minimal_locations_maximal_items, SVTestCase, default_options, minimal_locations_maximal_items_with_island
from BaseClasses import ItemClassification, Item
from . import SVTestBase, allsanity_options_without_mods, \
allsanity_options_with_mods, minimal_locations_maximal_items, minimal_locations_maximal_items_with_island, get_minsanity_options, default_options
from .. import items, location_table, options
from ..data.villagers_data import all_villagers_by_name, all_villagers_by_mod_by_name
from ..items import Group, item_table
Expand All @@ -14,14 +13,6 @@
from ..strings.region_names import Region


def get_real_locations(tester: typing.Union[SVTestBase, SVTestCase], multiworld: MultiWorld):
return [location for location in multiworld.get_locations(tester.player) if not location.event]


def get_real_location_names(tester: typing.Union[SVTestBase, SVTestCase], multiworld: MultiWorld):
return [location.name for location in multiworld.get_locations(tester.player) if not location.event]


class TestBaseItemGeneration(SVTestBase):
options = {
Friendsanity.internal_name: Friendsanity.option_all_with_marriage,
Expand Down Expand Up @@ -49,9 +40,7 @@ def test_all_progression_items_are_added_to_the_pool(self):
self.assertIn(progression_item.name, all_created_items)

def test_creates_as_many_item_as_non_event_locations(self):
non_event_locations = [location for location in get_real_locations(self, self.multiworld) if
not location.event]

non_event_locations = self.get_real_locations()
self.assertEqual(len(non_event_locations), len(self.multiworld.itempool))

def test_does_not_create_deprecated_items(self):
Expand Down Expand Up @@ -103,8 +92,7 @@ def test_all_progression_items_except_island_are_added_to_the_pool(self):
self.assertIn(progression_item.name, all_created_items)

def test_creates_as_many_item_as_non_event_locations(self):
non_event_locations = [location for location in get_real_locations(self, self.multiworld) if
not location.event]
non_event_locations = self.get_real_locations()

self.assertEqual(len(non_event_locations), len(self.multiworld.itempool))

Expand Down Expand Up @@ -172,7 +160,7 @@ def test_when_generate_world_then_4_shoes_in_the_pool(self):
self.assertEqual(item_pool.count("Progressive Footwear"), 4)

def test_when_generate_world_then_all_monster_checks_are_inaccessible(self):
for location in get_real_locations(self, self.multiworld):
for location in self.get_real_locations():
if LocationTags.MONSTERSANITY not in location_table[location.name].tags:
continue
with self.subTest(location.name):
Expand Down Expand Up @@ -201,7 +189,7 @@ def test_when_generate_world_then_4_shoes_in_the_pool(self):
self.assertEqual(item_pool.count("Progressive Footwear"), 4)

def test_when_generate_world_then_all_monster_checks_are_inaccessible(self):
for location in get_real_locations(self, self.multiworld):
for location in self.get_real_locations():
if LocationTags.MONSTERSANITY not in location_table[location.name].tags:
continue
with self.subTest(location.name):
Expand Down Expand Up @@ -236,7 +224,7 @@ def test_when_generate_world_then_many_rings_in_the_pool(self):
self.assertIn("Slime Charmer Ring", item_pool)

def test_when_generate_world_then_all_monster_checks_are_inaccessible(self):
for location in get_real_locations(self, self.multiworld):
for location in self.get_real_locations():
if LocationTags.MONSTERSANITY not in location_table[location.name].tags:
continue
with self.subTest(location.name):
Expand Down Expand Up @@ -271,7 +259,7 @@ def test_when_generate_world_then_many_rings_in_the_pool(self):
self.assertIn("Slime Charmer Ring", item_pool)

def test_when_generate_world_then_all_monster_checks_are_inaccessible(self):
for location in get_real_locations(self, self.multiworld):
for location in self.get_real_locations():
if LocationTags.MONSTERSANITY not in location_table[location.name].tags:
continue
with self.subTest(location.name):
Expand All @@ -281,7 +269,7 @@ def test_when_generate_world_then_all_monster_checks_are_inaccessible(self):
class TestProgressiveElevator(SVTestBase):
options = {
options.ElevatorProgression.internal_name: options.ElevatorProgression.option_progressive,
ToolProgression.internal_name: ToolProgression.option_progressive,
options.ToolProgression.internal_name: options.ToolProgression.option_progressive,
options.SkillProgression.internal_name: options.SkillProgression.option_progressive,
}

Expand Down Expand Up @@ -382,38 +370,44 @@ def generate_items_for_skull_100(self) -> List[Item]:
class TestLocationGeneration(SVTestBase):

def test_all_location_created_are_in_location_table(self):
for location in get_real_locations(self, self.multiworld):
for location in self.get_real_locations():
if not location.event:
self.assertIn(location.name, location_table)


class TestLocationAndItemCount(SVTestCase):
class TestMinLocationAndMaxItem(SVTestBase):
options = minimal_locations_maximal_items()

# They do not pass and I don't know why.
skip_base_tests = True

def test_minimal_location_maximal_items_still_valid(self):
min_max_options = minimal_locations_maximal_items()
multiworld = setup_solo_multiworld(min_max_options)
valid_locations = get_real_locations(self, multiworld)
valid_locations = self.get_real_locations()
number_locations = len(valid_locations)
number_items = len([item for item in multiworld.itempool
number_items = len([item for item in self.multiworld.itempool
if Group.RESOURCE_PACK not in item_table[item.name].groups and Group.TRAP not in item_table[item.name].groups])
self.assertGreaterEqual(number_locations, number_items)
print(f"Stardew Valley - Minimum Locations: {number_locations}, Maximum Items: {number_items} [ISLAND EXCLUDED]")


class TestMinLocationAndMaxItemWithIsland(SVTestBase):
options = minimal_locations_maximal_items_with_island()

def test_minimal_location_maximal_items_with_island_still_valid(self):
min_max_options = minimal_locations_maximal_items_with_island()
multiworld = setup_solo_multiworld(min_max_options)
valid_locations = get_real_locations(self, multiworld)
valid_locations = self.get_real_locations()
number_locations = len(valid_locations)
number_items = len([item for item in multiworld.itempool
number_items = len([item for item in self.multiworld.itempool
if Group.RESOURCE_PACK not in item_table[item.name].groups and Group.TRAP not in item_table[item.name].groups])
self.assertGreaterEqual(number_locations, number_items)
print(f"Stardew Valley - Minimum Locations: {number_locations}, Maximum Items: {number_items} [ISLAND INCLUDED]")


class TestMinSanityHasAllExpectedLocations(SVTestBase):
options = get_minsanity_options()

def test_minsanity_has_fewer_than_locations(self):
expected_locations = 76
minsanity_options = get_minsanity_options()
multiworld = setup_solo_multiworld(minsanity_options)
real_locations = get_real_locations(self, multiworld)
real_locations = self.get_real_locations()
number_locations = len(real_locations)
self.assertLessEqual(number_locations, expected_locations)
print(f"Stardew Valley - Minsanity Locations: {number_locations}")
Expand All @@ -423,10 +417,13 @@ def test_minsanity_has_fewer_than_locations(self):
f"\n\t\tExpected: {expected_locations}"
f"\n\t\tActual: {number_locations}")


class TestDefaultSettingsHasAllExpectedLocations(SVTestBase):
options = default_options()

def test_default_settings_has_exactly_locations(self):
expected_locations = 422
multiworld = setup_solo_multiworld(default_options())
real_locations = get_real_locations(self, multiworld)
real_locations = self.get_real_locations()
number_locations = len(real_locations)
print(f"Stardew Valley - Default options locations: {number_locations}")
if number_locations != expected_locations:
Expand All @@ -435,11 +432,13 @@ def test_default_settings_has_exactly_locations(self):
f"\n\t\tExpected: {expected_locations}"
f"\n\t\tActual: {number_locations}")


class TestAllSanitySettingsHasAllExpectedLocations(SVTestBase):
options = allsanity_options_without_mods()

def test_allsanity_without_mods_has_at_least_locations(self):
expected_locations = 1956
allsanity_options = allsanity_options_without_mods()
multiworld = setup_solo_multiworld(allsanity_options)
real_locations = get_real_locations(self, multiworld)
real_locations = self.get_real_locations()
number_locations = len(real_locations)
self.assertGreaterEqual(number_locations, expected_locations)
print(f"Stardew Valley - Allsanity Locations without mods: {number_locations}")
Expand All @@ -449,11 +448,13 @@ def test_allsanity_without_mods_has_at_least_locations(self):
f"\n\t\tExpected: {expected_locations}"
f"\n\t\tActual: {number_locations}")


class TestAllSanityWithModsSettingsHasAllExpectedLocations(SVTestBase):
options = allsanity_options_with_mods()

def test_allsanity_with_mods_has_at_least_locations(self):
expected_locations = 2804
allsanity_options = allsanity_options_with_mods()
multiworld = setup_solo_multiworld(allsanity_options)
real_locations = get_real_locations(self, multiworld)
real_locations = self.get_real_locations()
number_locations = len(real_locations)
self.assertGreaterEqual(number_locations, expected_locations)
print(f"\nStardew Valley - Allsanity Locations with all mods: {number_locations}")
Expand Down Expand Up @@ -485,7 +486,7 @@ def check_no_friendsanity_items(self):
self.assertFalse(item.name.endswith(" <3"))

def check_no_friendsanity_locations(self):
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
self.assertFalse(location_name.startswith("Friendsanity"))


Expand Down Expand Up @@ -513,7 +514,7 @@ def check_only_bachelors_items(self):
def check_only_bachelors_locations(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if location_name.startswith(prefix):
name_no_prefix = location_name[len(prefix):]
name_trimmed = name_no_prefix[:name_no_prefix.index(suffix)]
Expand Down Expand Up @@ -547,7 +548,7 @@ def check_only_starting_npcs_items(self):
def check_only_starting_npcs_locations(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if location_name.startswith(prefix):
name_no_prefix = location_name[len(prefix):]
name_trimmed = name_no_prefix[:name_no_prefix.index(suffix)]
Expand Down Expand Up @@ -600,7 +601,7 @@ def check_correct_number_of_items(self):
def check_locations_are_valid(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if not location_name.startswith(prefix):
continue
name_no_prefix = location_name[len(prefix):]
Expand Down Expand Up @@ -641,7 +642,7 @@ def check_items(self):
def check_locations(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if location_name.startswith(prefix):
name_no_prefix = location_name[len(prefix):]
name_trimmed = name_no_prefix[:name_no_prefix.index(suffix)]
Expand Down Expand Up @@ -694,7 +695,7 @@ def check_correct_number_of_items(self):
def check_locations_are_valid(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if not location_name.startswith(prefix):
continue
name_no_prefix = location_name[len(prefix):]
Expand Down Expand Up @@ -747,7 +748,7 @@ def check_correct_number_of_items(self):
def check_locations_are_valid(self):
prefix = "Friendsanity: "
suffix = " <3"
for location_name in get_real_location_names(self, self.multiworld):
for location_name in self.get_real_location_names():
if not location_name.startswith(prefix):
continue
name_no_prefix = location_name[len(prefix):]
Expand Down
Loading

0 comments on commit bd5c589

Please sign in to comment.