From 07a1ec0a1d1e958a24e9aeeb32cd5c1e8c8e4e5e Mon Sep 17 00:00:00 2001 From: josephwhite <22449090+josephwhite@users.noreply.github.com> Date: Tue, 10 Mar 2026 00:23:26 -0400 Subject: [PATCH] Test: Defaults for Options test (#5428) --- test/general/test_options.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/general/test_options.py b/test/general/test_options.py index e610e36794..6b08c8e9b0 100644 --- a/test/general/test_options.py +++ b/test/general/test_options.py @@ -1,7 +1,7 @@ import unittest from BaseClasses import PlandoOptions -from Options import Choice, ItemLinks, OptionSet, PlandoConnections, PlandoItems, PlandoTexts +from Options import Choice, TextChoice, ItemLinks, OptionSet, PlandoConnections, PlandoItems, PlandoTexts from Utils import restricted_dumps from worlds.AutoWorld import AutoWorldRegister @@ -16,6 +16,29 @@ class TestOptions(unittest.TestCase): with self.subTest(game=gamename, option=option_key): self.assertTrue(option.__doc__) + def test_option_defaults(self): + """Test that defaults for submitted options are valid.""" + for gamename, world_type in AutoWorldRegister.world_types.items(): + if not world_type.hidden: + for option_key, option in world_type.options_dataclass.type_hints.items(): + with self.subTest(game=gamename, option=option_key): + if issubclass(option, TextChoice): + self.assertTrue(option.default in option.name_lookup, + f"Default value {option.default} for TextChoice option {option.__name__} in" + f" {gamename} does not resolve to a listed value!" + ) + # Standard "can default generate" test + err_raised = None + try: + option.from_any(option.default) + except Exception as ex: + err_raised = ex + self.assertIsNone(err_raised, + f"Default value {option.default} for option {option.__name__} in {gamename}" + f" is not valid! Exception: {err_raised}" + ) + + def test_options_are_not_set_by_world(self): """Test that options attribute is not already set""" for gamename, world_type in AutoWorldRegister.world_types.items():