From 8ece833e72d594d9ff5d84e5511ef43e954c0d3c Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Thu, 23 May 2024 23:28:30 -0500 Subject: [PATCH 1/3] Tests: Add a test that weights file generates different results per player correctly --- test/programs/data/weights/weights.yaml | 11 +++++++ test/programs/test_generate.py | 44 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/programs/data/weights/weights.yaml diff --git a/test/programs/data/weights/weights.yaml b/test/programs/data/weights/weights.yaml new file mode 100644 index 000000000000..4ccd62a0044c --- /dev/null +++ b/test/programs/data/weights/weights.yaml @@ -0,0 +1,11 @@ +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 + 1: 50 + 2: 50 diff --git a/test/programs/test_generate.py b/test/programs/test_generate.py index 887a417ec9f9..67667b61c3de 100644 --- a/test/programs/test_generate.py +++ b/test/programs/test_generate.py @@ -91,3 +91,47 @@ def test_generate_yaml(self): 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.""" + + 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", "--outputpath", self.output_tempdir.name] + multiworld = 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": [1, 1, 0, 2, 2], + "progression_balancing": [0, 50, 99, 0, 50], + } + + for option_name, results in expected_results.items(): + for player, result in enumerate(results, 1): + self.assertEqual( + result, getattr(multiworld.worlds[player].options, option_name).value, + "Generated results from weights file did not match expected value." + ) + + self.assertOutput(self.output_tempdir.name) From 32a63a139bf8ce8899164f5076a1aaec449b1986 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Tue, 29 Oct 2024 09:15:21 -0500 Subject: [PATCH 2/3] Update test/programs/test_generate.py --- test/programs/test_generate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/programs/test_generate.py b/test/programs/test_generate.py index 67667b61c3de..b744afdb1c2c 100644 --- a/test/programs/test_generate.py +++ b/test/programs/test_generate.py @@ -96,6 +96,8 @@ def test_generate_yaml(self): 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" From 772495ce2e121f119688dfcc1f131bf950345404 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 29 Oct 2024 12:15:04 -0500 Subject: [PATCH 3/3] Generate.main() return and accessibility options were changed --- test/programs/data/weights/weights.yaml | 1 - test/programs/test_generate.py | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/programs/data/weights/weights.yaml b/test/programs/data/weights/weights.yaml index 4ccd62a0044c..1e3c65d8f9c1 100644 --- a/test/programs/data/weights/weights.yaml +++ b/test/programs/data/weights/weights.yaml @@ -7,5 +7,4 @@ Archipelago: 99: 50 accessibility: 0: 50 - 1: 50 2: 50 diff --git a/test/programs/test_generate.py b/test/programs/test_generate.py index b371963b6f5b..51800a0ec5c2 100644 --- a/test/programs/test_generate.py +++ b/test/programs/test_generate.py @@ -119,22 +119,21 @@ def test_generate_yaml(self): user_path_backup = user_path.cached_path user_path.cached_path = local_path() try: - sys.argv = [sys.argv[0], "--seed", "1", "--outputpath", self.output_tempdir.name] - multiworld = Generate.main() + 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": [1, 1, 0, 2, 2], + "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(multiworld.worlds[player].options, option_name).value, + result, getattr(namespace, option_name)[player].value, "Generated results from weights file did not match expected value." ) - - self.assertOutput(self.output_tempdir.name)