| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  | from argparse import Namespace | 
					
						
							|  |  |  | from typing import Dict, FrozenSet, Tuple, Any, ClassVar | 
					
						
							| 
									
										
										
										
											2023-02-26 19:19:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  | from BaseClasses import MultiWorld | 
					
						
							| 
									
										
										
										
											2023-02-26 19:19:15 -05:00
										 |  |  | from test.TestBase import WorldTestBase | 
					
						
							| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  | from test.general import gen_steps | 
					
						
							| 
									
										
										
										
											2023-02-26 19:19:15 -05:00
										 |  |  | from .. import StardewValleyWorld | 
					
						
							| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  | from ...AutoWorld import call_all | 
					
						
							| 
									
										
										
										
											2023-02-26 19:19:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SVTestBase(WorldTestBase): | 
					
						
							|  |  |  |     game = "Stardew Valley" | 
					
						
							|  |  |  |     world: StardewValleyWorld | 
					
						
							|  |  |  |     player: ClassVar[int] = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def world_setup(self, *args, **kwargs): | 
					
						
							|  |  |  |         super().world_setup(*args, **kwargs) | 
					
						
							| 
									
										
										
										
											2023-03-04 12:34:51 -05:00
										 |  |  |         if self.constructed: | 
					
						
							| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  |             self.world = self.multiworld.worlds[self.player]  # noqa | 
					
						
							| 
									
										
										
										
											2023-03-04 12:34:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     def run_default_tests(self) -> bool: | 
					
						
							|  |  |  |         # world_setup is overridden, so it'd always run default tests when importing SVTestBase | 
					
						
							|  |  |  |         return type(self) is not SVTestBase and super().run_default_tests | 
					
						
							| 
									
										
										
										
											2023-04-10 19:44:59 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pre_generated_worlds = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Mostly a copy of test.general.setup_solo_multiworld, I just don't want to change the core. | 
					
						
							|  |  |  | def setup_solo_multiworld(test_options=None, | 
					
						
							|  |  |  |                           _cache: Dict[FrozenSet[Tuple[str, Any]], MultiWorld] = {}) -> MultiWorld:  # noqa | 
					
						
							|  |  |  |     if test_options is None: | 
					
						
							|  |  |  |         test_options = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Yes I reuse the worlds generated between tests, its speeds the execution by a couple seconds | 
					
						
							|  |  |  |     frozen_options = frozenset(test_options.items()) | 
					
						
							|  |  |  |     if frozen_options in _cache: | 
					
						
							|  |  |  |         return _cache[frozen_options] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     multiworld = MultiWorld(1) | 
					
						
							|  |  |  |     multiworld.game[1] = StardewValleyWorld.game | 
					
						
							|  |  |  |     multiworld.player_name = {1: "Tester"} | 
					
						
							|  |  |  |     multiworld.set_seed() | 
					
						
							|  |  |  |     args = Namespace() | 
					
						
							|  |  |  |     for name, option in StardewValleyWorld.option_definitions.items(): | 
					
						
							|  |  |  |         value = option(test_options[name]) if name in test_options else option.from_any(option.default) | 
					
						
							|  |  |  |         setattr(args, name, {1: value}) | 
					
						
							|  |  |  |     multiworld.set_options(args) | 
					
						
							|  |  |  |     multiworld.set_default_common_options() | 
					
						
							|  |  |  |     for step in gen_steps: | 
					
						
							|  |  |  |         call_all(multiworld, step) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _cache[frozen_options] = multiworld | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return multiworld |