mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-26 17:13:22 -07:00
Test: Defaults for Options test (#5428)
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user