| 
									
										
										
										
											2021-11-11 00:06:51 +01:00
										 |  |  | import unittest | 
					
						
							|  |  |  | from worlds.AutoWorld import AutoWorldRegister | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  | from . import setup_solo_multiworld | 
					
						
							| 
									
										
										
										
											2021-11-11 00:06:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestBase(unittest.TestCase): | 
					
						
							|  |  |  |     def testCreateItem(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 | 
					
						
							|  |  |  |             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) | 
					
						
							|  |  |  |                     self.assertEqual(item.name, item_name) | 
					
						
							| 
									
										
										
										
											2022-06-01 17:25:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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. | 
					
						
							|  |  |  |         # In such a case, you can add your entries to this Exclusion dict. Game Name -> Group Names | 
					
						
							|  |  |  |         exclusion_dict = { | 
					
						
							|  |  |  |             "A Link to the Past": | 
					
						
							|  |  |  |                 {"Pendants", "Crystals"}, | 
					
						
							| 
									
										
										
										
											2022-11-09 15:07:14 -06:00
										 |  |  |             "Ocarina of Time": | 
					
						
							|  |  |  |                 {"medallions", "stones", "rewards", "logic_bottles"}, | 
					
						
							| 
									
										
										
										
											2022-06-01 17:25:40 +02:00
										 |  |  |             "Starcraft 2 Wings of Liberty": | 
					
						
							|  |  |  |                 {"Missions"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							|  |  |  |             with self.subTest(game_name, game_name=game_name): | 
					
						
							|  |  |  |                 exclusions = exclusion_dict.get(game_name, frozenset()) | 
					
						
							|  |  |  |                 for group_name, items in world_type.item_name_groups.items(): | 
					
						
							|  |  |  |                     if group_name not in exclusions: | 
					
						
							|  |  |  |                         with self.subTest(group_name, group_name=group_name): | 
					
						
							|  |  |  |                             for item in items: | 
					
						
							|  |  |  |                                 self.assertIn(item, world_type.item_name_to_id) | 
					
						
							| 
									
										
										
										
											2022-09-05 01:02:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 15:45:48 +01:00
										 |  |  |     def testItemNameGroupConflict(self): | 
					
						
							|  |  |  |         """Test that all item name groups aren't also item names.""" | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							|  |  |  |             with self.subTest(game_name, game_name=game_name): | 
					
						
							|  |  |  |                 for group_name in world_type.item_name_groups: | 
					
						
							|  |  |  |                     with self.subTest(group_name, group_name=group_name): | 
					
						
							|  |  |  |                         self.assertNotIn(group_name, world_type.item_name_to_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-05 01:02:40 -07:00
										 |  |  |     def testItemCountGreaterEqualLocations(self): | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							|  |  |  |             with self.subTest("Game", game=game_name): | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |                 multiworld = setup_solo_multiworld(world_type) | 
					
						
							| 
									
										
										
										
											2022-09-05 01:02:40 -07:00
										 |  |  |                 self.assertGreaterEqual( | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |                     len(multiworld.itempool), | 
					
						
							|  |  |  |                     len(multiworld.get_unfilled_locations()), | 
					
						
							|  |  |  |                     f"{game_name} Item count MUST meet or exceed the number of locations", | 
					
						
							| 
									
										
										
										
											2022-09-05 01:02:40 -07:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def testItemsInDatapackage(self): | 
					
						
							|  |  |  |         """Test that any created items in the itempool are in the datapackage""" | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							|  |  |  |             with self.subTest("Game", game=game_name): | 
					
						
							|  |  |  |                 multiworld = setup_solo_multiworld(world_type) | 
					
						
							|  |  |  |                 for item in multiworld.itempool: | 
					
						
							|  |  |  |                     self.assertIn(item.name, world_type.item_name_to_id) |