Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add a test that weights file generates different results per player correctly #3392

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/programs/data/weights/weights.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions test/programs/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,48 @@ 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."""

alwaysintreble marked this conversation as resolved.
Show resolved Hide resolved
# 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