Tests: test that worlds don't create regions or locations after `create_items` (#1465)
* Tests: test that worlds don't create regions or locations after `create_items` * recache during the location counts just to be extra safe * adjust typing and use a Tuple instead of a list * remove unused import
This commit is contained in:
		
							parent
							
								
									7cad53c31a
								
							
						
					
					
						commit
						9cb9cbe47d
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
import unittest
 | 
			
		||||
from collections import Counter
 | 
			
		||||
from worlds.AutoWorld import AutoWorldRegister
 | 
			
		||||
from worlds.AutoWorld import AutoWorldRegister, call_all
 | 
			
		||||
from . import setup_solo_multiworld
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,3 +23,33 @@ class TestBase(unittest.TestCase):
 | 
			
		|||
                for location in locations:
 | 
			
		||||
                    self.assertIn(location.name, world_type.location_name_to_id)
 | 
			
		||||
                    self.assertEqual(location.address, world_type.location_name_to_id[location.name])
 | 
			
		||||
 | 
			
		||||
    def testLocationCreationSteps(self):
 | 
			
		||||
        """Tests that Regions and Locations aren't created after `create_items`."""
 | 
			
		||||
        gen_steps = ("generate_early", "create_regions", "create_items")
 | 
			
		||||
        for game_name, world_type in AutoWorldRegister.world_types.items():
 | 
			
		||||
            with self.subTest("Game", game_name=game_name):
 | 
			
		||||
                multiworld = setup_solo_multiworld(world_type, gen_steps)
 | 
			
		||||
                multiworld._recache()
 | 
			
		||||
                region_count = len(multiworld.get_regions())
 | 
			
		||||
                location_count = len(multiworld.get_locations())
 | 
			
		||||
 | 
			
		||||
                call_all(multiworld, "set_rules")
 | 
			
		||||
                self.assertEqual(region_count, len(multiworld.get_regions()),
 | 
			
		||||
                                 f"{game_name} modified region count during rule creation")
 | 
			
		||||
                self.assertEqual(location_count, len(multiworld.get_locations()),
 | 
			
		||||
                                 f"{game_name} modified locations count during rule creation")
 | 
			
		||||
 | 
			
		||||
                multiworld._recache()
 | 
			
		||||
                call_all(multiworld, "generate_basic")
 | 
			
		||||
                self.assertEqual(region_count, len(multiworld.get_regions()),
 | 
			
		||||
                                 f"{game_name} modified region count during generate_basic")
 | 
			
		||||
                self.assertGreaterEqual(location_count, len(multiworld.get_locations()),
 | 
			
		||||
                                        f"{game_name} modified locations count during generate_basic")
 | 
			
		||||
 | 
			
		||||
                multiworld._recache()
 | 
			
		||||
                call_all(multiworld, "pre_fill")
 | 
			
		||||
                self.assertEqual(region_count, len(multiworld.get_regions()),
 | 
			
		||||
                                 f"{game_name} modified region count during pre_fill")
 | 
			
		||||
                self.assertGreaterEqual(location_count, len(multiworld.get_locations()),
 | 
			
		||||
                                        f"{game_name} modified locations count during pre_fill")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,13 @@
 | 
			
		|||
from argparse import Namespace
 | 
			
		||||
from typing import Type, Tuple
 | 
			
		||||
 | 
			
		||||
from BaseClasses import MultiWorld
 | 
			
		||||
from worlds.AutoWorld import call_all
 | 
			
		||||
from worlds.AutoWorld import call_all, World
 | 
			
		||||
 | 
			
		||||
gen_steps = ["generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill"]
 | 
			
		||||
gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_solo_multiworld(world_type) -> MultiWorld:
 | 
			
		||||
def setup_solo_multiworld(world_type: Type[World], steps: Tuple[str, ...] = gen_steps) -> MultiWorld:
 | 
			
		||||
    multiworld = MultiWorld(1)
 | 
			
		||||
    multiworld.game[1] = world_type.game
 | 
			
		||||
    multiworld.player_name = {1: "Tester"}
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +17,6 @@ def setup_solo_multiworld(world_type) -> MultiWorld:
 | 
			
		|||
        setattr(args, name, {1: option.from_any(option.default)})
 | 
			
		||||
    multiworld.set_options(args)
 | 
			
		||||
    multiworld.set_default_common_options()
 | 
			
		||||
    for step in gen_steps:
 | 
			
		||||
    for step in steps:
 | 
			
		||||
        call_all(multiworld, step)
 | 
			
		||||
    return multiworld
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue