From be8714d384335c9db0bd61f2e3d0dbe8d2c282a3 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 31 Jul 2023 00:39:02 +0200 Subject: [PATCH 1/5] Tests: test that collect and remove have expected behaviour. --- test/general/TestItems.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/general/TestItems.py b/test/general/TestItems.py index 95eb8d28d9af..a221ede53b55 100644 --- a/test/general/TestItems.py +++ b/test/general/TestItems.py @@ -4,14 +4,36 @@ class TestBase(unittest.TestCase): - def testCreateItem(self): + def testItem(self): for game_name, world_type in AutoWorldRegister.world_types.items(): - proxy_world = world_type(None, 0) # this is identical to MultiServer.py creating worlds + multiworld = setup_solo_multiworld(world_type) + proxy_world = multiworld.worlds[1] + empty_prog_items = multiworld.state.prog_items.copy() for item_name in world_type.item_name_to_id: with self.subTest("Create Item", item_name=item_name, game_name=game_name): item = proxy_world.create_item(item_name) + + with self.subTest("Item Name", item_name=item_name, game_name=game_name): self.assertEqual(item.name, item_name) + if item.advancement: + with self.subTest("Item State Collect", item_name=item_name, game_name=game_name): + multiworld.state.collect(item, True) + + with self.subTest("Item State Remove", item_name=item_name, game_name=game_name): + multiworld.state.remove(item) + + self.assertEqual(multiworld.state.prog_items, empty_prog_items, + "Item Collect -> Remove should restore empty state.") + else: + with self.subTest("Item State Collect No Change", item_name=item_name, game_name=game_name): + # Non-Advancement should not modify state. + base_state = multiworld.state.prog_items.copy() + multiworld.state.collect(item) + self.assertEqual(base_state, multiworld.state.prog_items) + + multiworld.state.prog_items = empty_prog_items + def testItemNameGroupHasValidItem(self): """Test that all item name groups contain valid items. """ # This cannot test for Event names that you may have declared for logic, only sendable Items. From 3fa27f97b22f14057d5bb14262321b5df1aa6589 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 31 Jul 2023 00:53:50 +0200 Subject: [PATCH 2/5] skip some not needed steps --- test/general/TestItems.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/general/TestItems.py b/test/general/TestItems.py index a221ede53b55..11caa4faec01 100644 --- a/test/general/TestItems.py +++ b/test/general/TestItems.py @@ -6,7 +6,7 @@ class TestBase(unittest.TestCase): def testItem(self): for game_name, world_type in AutoWorldRegister.world_types.items(): - multiworld = setup_solo_multiworld(world_type) + multiworld = setup_solo_multiworld(world_type, steps=("generate_early", "create_regions", "create_items")) proxy_world = multiworld.worlds[1] empty_prog_items = multiworld.state.prog_items.copy() for item_name in world_type.item_name_to_id: From db2cf275ed63de84eeb7965da5bf00df4cdb646d Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 31 Jul 2024 17:50:10 +0200 Subject: [PATCH 3/5] fix merge --- test/general/test_items.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/general/test_items.py b/test/general/test_items.py index 0c132b74b2f7..1fe60843ad9a 100644 --- a/test/general/test_items.py +++ b/test/general/test_items.py @@ -8,8 +8,7 @@ class TestBase(unittest.TestCase): def test_create_item(self): """Test that a world can successfully create all items in its datapackage""" for game_name, world_type in AutoWorldRegister.world_types.items(): - proxy_world = setup_solo_multiworld(world_type, ()).worlds[1] - multiworld = setup_solo_multiworld(world_type, steps=("generate_early", "create_regions", "create_items")) + multiworld = setup_solo_multiworld(world_type, ()) proxy_world = multiworld.worlds[1] empty_prog_items = multiworld.state.prog_items.copy() for item_name in world_type.item_name_to_id: From 495c64544395dcf418ec6d04d495a382b6c82fab Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 31 Jul 2024 17:52:04 +0200 Subject: [PATCH 4/5] re-add steps --- test/general/test_items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/general/test_items.py b/test/general/test_items.py index 1fe60843ad9a..7214b3d56307 100644 --- a/test/general/test_items.py +++ b/test/general/test_items.py @@ -8,7 +8,7 @@ class TestBase(unittest.TestCase): def test_create_item(self): """Test that a world can successfully create all items in its datapackage""" for game_name, world_type in AutoWorldRegister.world_types.items(): - multiworld = setup_solo_multiworld(world_type, ()) + multiworld = setup_solo_multiworld(world_type, steps=("generate_early", "create_regions", "create_items")) proxy_world = multiworld.worlds[1] empty_prog_items = multiworld.state.prog_items.copy() for item_name in world_type.item_name_to_id: From ba7428d2c01e38999021ae10c88655b2ef427b30 Mon Sep 17 00:00:00 2001 From: qwint Date: Sun, 12 Jan 2025 22:21:20 -0500 Subject: [PATCH 5/5] reorganizes collect/remove tests to just make a new CollectionState instead of copying it every iteration (#4468) --- test/general/test_items.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/general/test_items.py b/test/general/test_items.py index 7214b3d56307..e69e1f6c461d 100644 --- a/test/general/test_items.py +++ b/test/general/test_items.py @@ -1,5 +1,6 @@ import unittest +from BaseClasses import CollectionState from worlds.AutoWorld import AutoWorldRegister, call_all from . import setup_solo_multiworld @@ -10,8 +11,8 @@ def test_create_item(self): for game_name, world_type in AutoWorldRegister.world_types.items(): multiworld = setup_solo_multiworld(world_type, steps=("generate_early", "create_regions", "create_items")) proxy_world = multiworld.worlds[1] - empty_prog_items = multiworld.state.prog_items.copy() for item_name in world_type.item_name_to_id: + test_state = CollectionState(multiworld) with self.subTest("Create Item", item_name=item_name, game_name=game_name): item = proxy_world.create_item(item_name) @@ -20,21 +21,18 @@ def test_create_item(self): if item.advancement: with self.subTest("Item State Collect", item_name=item_name, game_name=game_name): - multiworld.state.collect(item, True) + test_state.collect(item, True) with self.subTest("Item State Remove", item_name=item_name, game_name=game_name): - multiworld.state.remove(item) + test_state.remove(item) - self.assertEqual(multiworld.state.prog_items, empty_prog_items, + self.assertEqual(test_state.prog_items, multiworld.state.prog_items, "Item Collect -> Remove should restore empty state.") else: with self.subTest("Item State Collect No Change", item_name=item_name, game_name=game_name): # Non-Advancement should not modify state. - base_state = multiworld.state.prog_items.copy() - multiworld.state.collect(item) - self.assertEqual(base_state, multiworld.state.prog_items) - - multiworld.state.prog_items = empty_prog_items + test_state.collect(item) + self.assertEqual(test_state.prog_items, multiworld.state.prog_items) def test_item_name_group_has_valid_item(self): """Test that all item name groups contain valid items. """