From 9281011315ed8d5f36fa5b61b7969c82b25c1552 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Fri, 27 Oct 2023 05:33:59 -0500 Subject: [PATCH] Tests: Add a unit test for slot_data (#2333) * Tests: Add a unit test for slot_data * use NetUtils.encode * modern PEP8 --- test/general/test_implemented.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/general/test_implemented.py b/test/general/test_implemented.py index 67d0e5ff..b60bcee4 100644 --- a/test/general/test_implemented.py +++ b/test/general/test_implemented.py @@ -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.")