mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-04-18 07:53:32 -07:00
* Test: add test for unpickling NetUtils enums This verifies that Utils.ByValue either works or is not required, and once we drop ByValue, this validates that future Python versions do not break our Enums again. * Test: NetUtils enum switch to more direct pickle.dumps It's probably better to use the direct interface in case restricted_dumps does some funky stuff in the future. Co-authored-by: Duck <31627079+duckboycool@users.noreply.github.com> * Test: NetUtils enum fix import for change --------- Co-authored-by: Duck <31627079+duckboycool@users.noreply.github.com>
38 lines
993 B
Python
38 lines
993 B
Python
"""Verify that NetUtils' enums work correctly with all supported Python versions."""
|
|
|
|
import pickle
|
|
import unittest
|
|
from enum import Enum
|
|
from typing import Type
|
|
|
|
from NetUtils import ClientStatus, HintStatus, SlotType
|
|
from Utils import restricted_loads
|
|
|
|
|
|
class Base:
|
|
class DataEnumTest(unittest.TestCase):
|
|
type: Type[Enum]
|
|
value: Enum
|
|
|
|
def test_unpickle(self) -> None:
|
|
"""Tests that enums used in multidata or multisave can be pickled and unpickled."""
|
|
pickled = pickle.dumps(self.value)
|
|
unpickled = restricted_loads(pickled)
|
|
self.assertEqual(unpickled, self.value)
|
|
self.assertIsInstance(unpickled, self.type)
|
|
|
|
|
|
class HintStatusTest(Base.DataEnumTest):
|
|
type = HintStatus
|
|
value = HintStatus.HINT_AVOID
|
|
|
|
|
|
class ClientStatusTest(Base.DataEnumTest):
|
|
type = ClientStatus
|
|
value = ClientStatus.CLIENT_GOAL
|
|
|
|
|
|
class SlotTypeTest(Base.DataEnumTest):
|
|
type = SlotType
|
|
value = SlotType.player
|