Skip to content

Commit 4623d0d

Browse files
committed
Comments by @altendky
1 parent f3e8530 commit 4623d0d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

chia/_tests/core/util/test_streamable.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,22 @@ class PostInitTestClassDict(Streamable):
446446

447447

448448
@streamable_enum(uint32)
449-
class IntEnum(Enum):
449+
class IntegerEnum(Enum):
450450
A = 1
451451
B = 2
452452

453453

454454
@streamable_enum(str)
455-
class StrEnum(Enum):
455+
class StringEnum(Enum):
456456
A = "foo"
457457
B = "bar"
458458

459459

460460
@streamable
461461
@dataclass(frozen=True)
462462
class PostInitTestClassEnum(Streamable):
463-
a: IntEnum
464-
b: StrEnum
463+
a: IntegerEnum
464+
b: StringEnum
465465

466466

467467
@pytest.mark.parametrize(
@@ -474,7 +474,7 @@ class PostInitTestClassEnum(Streamable):
474474
(PostInitTestClassTuple, ((1, "test"), ((200, "test_2"), b"\xba" * 32))),
475475
(PostInitTestClassDict, ({1: "bar"}, {bytes32.zeros: {1: "bar"}})),
476476
(PostInitTestClassOptional, (12, None, 13, None)),
477-
(PostInitTestClassEnum, (IntEnum.A, StrEnum.B)),
477+
(PostInitTestClassEnum, (IntegerEnum.A, StringEnum.B)),
478478
],
479479
)
480480
def test_post_init_valid(test_class: type[Any], args: tuple[Any, ...]) -> None:
@@ -541,8 +541,8 @@ class TestClass(Streamable):
541541
f: Optional[uint32]
542542
g: tuple[uint32, str, bytes]
543543
h: dict[uint32, str]
544-
i: IntEnum
545-
j: StrEnum
544+
i: IntegerEnum
545+
j: StringEnum
546546

547547
# we want to test invalid here, hence the ignore.
548548
a = TestClass(
@@ -554,8 +554,8 @@ class TestClass(Streamable):
554554
None,
555555
(uint32(383), "hello", b"goodbye"),
556556
{uint32(1): "foo"},
557-
IntEnum.A,
558-
StrEnum.B,
557+
IntegerEnum.A,
558+
StringEnum.B,
559559
)
560560

561561
b: bytes = bytes(a)
@@ -667,19 +667,19 @@ class TestClassUint(Streamable):
667667
a: uint32
668668

669669
# Does not have the required uint size
670-
with pytest.raises(ValueError):
670+
with pytest.raises(ValueError, match=re.escape("uint32.from_bytes() requires 4 bytes but got: 2")):
671671
TestClassUint.from_bytes(b"\x00\x00")
672672

673673

674674
def test_ambiguous_deserialization_int_enum() -> None:
675675
@streamable
676676
@dataclass(frozen=True)
677-
class TestClassIntEnum(Streamable):
678-
a: IntEnum
677+
class TestClassIntegerEnum(Streamable):
678+
a: IntegerEnum
679679

680-
# Does not have the required uint size
681-
with pytest.raises(ValueError):
682-
TestClassIntEnum.from_bytes(b"\x00\x00")
680+
# passed bytes are incorrect size for serialization proxy
681+
with pytest.raises(ValueError, match=re.escape("uint32.from_bytes() requires 4 bytes but got: 2")):
682+
TestClassIntegerEnum.from_bytes(b"\x00\x00")
683683

684684

685685
def test_ambiguous_deserialization_list() -> None:
@@ -719,9 +719,9 @@ def test_ambiguous_deserialization_str_enum() -> None:
719719
@streamable
720720
@dataclass(frozen=True)
721721
class TestClassStr(Streamable):
722-
a: StrEnum
722+
a: StringEnum
723723

724-
# Does not have the required str size
724+
# passed bytes are incorrect size for serialization proxy
725725
with pytest.raises(AssertionError):
726726
TestClassStr.from_bytes(bytes([0, 0, 100, 24, 52]))
727727

chia/util/streamable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ class UInt64Range(Streamable):
719719
_T_Enum = TypeVar("_T_Enum", bound=EnumMeta)
720720

721721

722-
def streamable_enum(proxy: type[Any]) -> Callable[[_T_Enum], _T_Enum]:
722+
def streamable_enum(proxy: type[object]) -> Callable[[_T_Enum], _T_Enum]:
723723
def streamable_enum_wrapper(cls: _T_Enum) -> _T_Enum:
724724
setattr(cls, "_streamable_proxy", proxy)
725725
setattr(cls, "_ignore_", ["_streamable_proxy"])

0 commit comments

Comments
 (0)