Tests: Add a test that weights file generates different results per player correctly (#3392)
* Tests: Add a test that weights file generates different results per player correctly * Update test/programs/test_generate.py * Generate.main() return and accessibility options were changed
This commit is contained in:
		
							parent
							
								
									ad40acd392
								
							
						
					
					
						commit
						f00975c73d
					
				|  | @ -0,0 +1,10 @@ | |||
| name: Player{number} | ||||
| game: Archipelago # we only need to test options work and this "supports" all the base options | ||||
| Archipelago: | ||||
|   progression_balancing: | ||||
|     0: 50 | ||||
|     50: 50 | ||||
|     99: 50 | ||||
|   accessibility: | ||||
|     0: 50 | ||||
|     2: 50 | ||||
|  | @ -92,3 +92,48 @@ class TestGenerateMain(unittest.TestCase): | |||
|             user_path.cached_path = user_path_backup | ||||
| 
 | ||||
|         self.assertOutput(self.output_tempdir.name) | ||||
| 
 | ||||
| 
 | ||||
| class TestGenerateWeights(TestGenerateMain): | ||||
|     """Tests Generate.py using a weighted file to generate for multiple players.""" | ||||
| 
 | ||||
|     # this test will probably break if something in generation is changed that affects the seed before the weights get processed | ||||
|     # can be fixed by changing the expected_results dict | ||||
|     generate_dir = TestGenerateMain.generate_dir | ||||
|     run_dir = TestGenerateMain.run_dir | ||||
|     abs_input_dir = Path(__file__).parent / "data" / "weights" | ||||
|     rel_input_dir = abs_input_dir.relative_to(run_dir)  # directly supplied relative paths are relative to cwd | ||||
|     yaml_input_dir = abs_input_dir.relative_to(generate_dir)  # yaml paths are relative to user_path | ||||
| 
 | ||||
|     # don't need to run these tests | ||||
|     test_generate_absolute = None | ||||
|     test_generate_relative = None | ||||
| 
 | ||||
|     def test_generate_yaml(self): | ||||
|         from settings import get_settings | ||||
|         from Utils import user_path, local_path | ||||
|         settings = get_settings() | ||||
|         settings.generator.player_files_path = settings.generator.PlayerFilesPath(self.yaml_input_dir) | ||||
|         settings.generator.players = 5  # arbitrary number, should be enough | ||||
|         settings._filename = None | ||||
|         user_path_backup = user_path.cached_path | ||||
|         user_path.cached_path = local_path() | ||||
|         try: | ||||
|             sys.argv = [sys.argv[0], "--seed", "1"] | ||||
|             namespace, seed = Generate.main() | ||||
|         finally: | ||||
|             user_path.cached_path = user_path_backup | ||||
| 
 | ||||
|         # there's likely a better way to do this, but hardcode the results from seed 1 to ensure they're always this | ||||
|         expected_results = { | ||||
|             "accessibility": [0, 2, 0, 2, 2], | ||||
|             "progression_balancing": [0, 50, 99, 0, 50], | ||||
|         } | ||||
| 
 | ||||
|         self.assertEqual(seed, 1) | ||||
|         for option_name, results in expected_results.items(): | ||||
|             for player, result in enumerate(results, 1): | ||||
|                 self.assertEqual( | ||||
|                     result, getattr(namespace, option_name)[player].value, | ||||
|                     "Generated results from weights file did not match expected value." | ||||
|                 ) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue