Tests: Add a unit test for slot_data (#2333)
* Tests: Add a unit test for slot_data * use NetUtils.encode * modern PEP8
This commit is contained in:
parent
d595b1a67f
commit
9281011315
|
@ -1,6 +1,8 @@
|
||||||
import unittest
|
import unittest
|
||||||
from worlds.AutoWorld import AutoWorldRegister
|
|
||||||
|
|
||||||
|
from Fill import distribute_items_restrictive
|
||||||
|
from NetUtils import encode
|
||||||
|
from worlds.AutoWorld import AutoWorldRegister, call_all
|
||||||
from . import setup_solo_multiworld
|
from . import setup_solo_multiworld
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,3 +33,17 @@ class TestImplemented(unittest.TestCase):
|
||||||
for method in ("assert_generate",):
|
for method in ("assert_generate",):
|
||||||
self.assertFalse(hasattr(world_type, method),
|
self.assertFalse(hasattr(world_type, method),
|
||||||
f"{method} must be implemented as a @classmethod named stage_{method}.")
|
f"{method} must be implemented as a @classmethod named stage_{method}.")
|
||||||
|
|
||||||
|
def test_slot_data(self):
|
||||||
|
"""Tests that if a world creates slot data, it's json serializable."""
|
||||||
|
for game_name, world_type in AutoWorldRegister.world_types.items():
|
||||||
|
# has an await for generate_output which isn't being called
|
||||||
|
if game_name in {"Ocarina of Time", "Zillion"}:
|
||||||
|
continue
|
||||||
|
with self.subTest(game_name):
|
||||||
|
multiworld = setup_solo_multiworld(world_type)
|
||||||
|
distribute_items_restrictive(multiworld)
|
||||||
|
call_all(multiworld, "post_fill")
|
||||||
|
for key, data in multiworld.worlds[1].fill_slot_data().items():
|
||||||
|
self.assertIsInstance(key, str, "keys in slot data must be a string")
|
||||||
|
self.assertIsInstance(encode(data), str, f"object {type(data).__name__} not serializable.")
|
||||||
|
|
Loading…
Reference in New Issue