Repository: eigenein/protobuf

Issue:
Improve serializers.py test coverage

Discussion:

Patch:
diff --git a/pure_protobuf/serializers.py b/pure_protobuf/serializers.py
index bd643d3..2a467f3 100644
--- a/pure_protobuf/serializers.py
+++ b/pure_protobuf/serializers.py
@@ -139,7 +139,7 @@ class UnsignedInt32Serializer(Serializer):
     def validate(self, value: Any):
         unsigned_varint_serializer.validate(value)
         if not 0 <= value <= 0xFFFFFFFF:
-            raise OverflowError(f'value is out of 32-bit unsigned integer range')
+            raise ValueError(f'value is out of 32-bit unsigned integer range')
 
     def dump(self, value: Any, io: IO):
         unsigned_varint_serializer.dump(value, io)
@@ -158,7 +158,7 @@ class UnsignedInt64Serializer(Serializer):
     def validate(self, value: Any):
         unsigned_varint_serializer.validate(value)
         if not 0 <= value <= 0xFFFFFFFF_FFFFFFFF:
-            raise OverflowError(f'value is out of 64-bit unsigned integer range')
+            raise ValueError(f'value is out of 64-bit unsigned integer range')
 
     def dump(self, value: Any, io: IO):
         unsigned_varint_serializer.dump(value, io)
@@ -177,7 +177,7 @@ class SignedInt32Serializer(Serializer):
     def validate(self, value: Any):
         signed_varint_serializer.validate(value)
         if not -0x7FFFFFFF <= value <= 0x7FFFFFFF:
-            raise OverflowError(f'value is out of 32-bit signed integer range')
+            raise ValueError(f'value is out of 32-bit signed integer range')
 
     def dump(self, value: Any, io: IO):
         signed_varint_serializer.dump(value, io)
@@ -196,7 +196,7 @@ class SignedInt64Serializer(Serializer):
     def validate(self, value: Any):
         signed_varint_serializer.validate(value)
         if not -0x7FFFFFFF_FFFFFFFF <= value <= 0x7FFFFFFF_FFFFFFFF:
-            raise OverflowError(f'value is out of 64-bit signed integer range')
+            raise ValueError(f'value is out of 64-bit signed integer range')
 
     def dump(self, value: Any, io: IO):
         signed_varint_serializer.dump(value, io)


Test patch:
diff --git a/tests/test_serializers.py b/tests/test_serializers.py
index 1cd26df..3e7dec3 100644
--- a/tests/test_serializers.py
+++ b/tests/test_serializers.py
@@ -14,10 +14,21 @@ from pure_protobuf.enums import WireType
 from pure_protobuf.serializers import (
     BooleanSerializer,
     BytesSerializer,
+    DoubleSerializer,
+    FloatSerializer,
     IntEnumSerializer,
     PackingSerializer,
+    Serializer,
+    SignedFixed32Serializer,
+    SignedFixed64Serializer,
+    SignedInt32Serializer,
+    SignedInt64Serializer,
     SignedVarintSerializer,
     StringSerializer,
+    UnsignedFixed32Serializer,
+    UnsignedFixed64Serializer,
+    UnsignedInt32Serializer,
+    UnsignedInt64Serializer,
     UnsignedVarintSerializer,
 )
 from pure_protobuf.types import int32, uint
@@ -50,6 +61,27 @@ def class_3(class_1: Type) -> Type:
     return Test3
 
 
+@mark.parametrize('serializer_class, value', [
+    (SignedVarintSerializer, 'hello'),
+    (BytesSerializer, 42),
+    (StringSerializer, 42),
+    (UnsignedInt32Serializer, 0x1_00000000),
+    (UnsignedInt64Serializer, -1),
+    (SignedInt32Serializer, 0x80000000),
+    (SignedInt64Serializer, 0x80000000_00000000),
+    (BooleanSerializer, 42),
+    (SignedFixed32Serializer, 'hello'),
+    (UnsignedFixed32Serializer, 'hello'),
+    (SignedFixed64Serializer, 'hello'),
+    (UnsignedFixed64Serializer, 'hello'),
+    (FloatSerializer, 'hello'),
+    (DoubleSerializer, 'hello'),
+])
+def test_serializer_value_error(serializer_class: Type[Serializer], value: Any):
+    with raises(ValueError):
+        serializer_class().validate(value)
+
+
 @mark.parametrize('value, bytes_', [
     (0, b'\x00'),
     (3, b'\x03'),
@@ -212,6 +244,3 @@ def test_enum():
 
     assert value.dumps() == bytes_
     assert Test.loads(bytes_) == value
-
-
-# TODO: test individual skip functions.