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:
Aaron Wagener 2023-10-27 05:33:59 -05:00 committed by GitHub
parent d595b1a67f
commit 9281011315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,8 @@
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
@ -31,3 +33,17 @@ class TestImplemented(unittest.TestCase):
for method in ("assert_generate",):
self.assertFalse(hasattr(world_type, 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.")