|
| 1 | +# Copyright 2021 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import pytest |
| 16 | + |
| 17 | +from proto.marshal.marshal import BaseMarshal |
| 18 | +from proto.primitives import ProtoType |
| 19 | + |
| 20 | +INT_32BIT_PLUS_ONE = 0xFFFFFFFF + 1 |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.parametrize( |
| 24 | + "pb_type,value,expected", |
| 25 | + [ |
| 26 | + (ProtoType.INT64, 0, 0), |
| 27 | + (ProtoType.INT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE), |
| 28 | + (ProtoType.SINT64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE), |
| 29 | + (ProtoType.INT64, None, None), |
| 30 | + (ProtoType.UINT64, 0, 0), |
| 31 | + (ProtoType.UINT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE), |
| 32 | + (ProtoType.UINT64, None, None), |
| 33 | + (ProtoType.SINT64, 0, 0), |
| 34 | + (ProtoType.SINT64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE), |
| 35 | + (ProtoType.SINT64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE), |
| 36 | + (ProtoType.SINT64, None, None), |
| 37 | + (ProtoType.FIXED64, 0, 0), |
| 38 | + (ProtoType.FIXED64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE), |
| 39 | + (ProtoType.FIXED64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE), |
| 40 | + (ProtoType.FIXED64, None, None), |
| 41 | + (ProtoType.SFIXED64, 0, 0), |
| 42 | + (ProtoType.SFIXED64, INT_32BIT_PLUS_ONE, INT_32BIT_PLUS_ONE), |
| 43 | + (ProtoType.SFIXED64, -INT_32BIT_PLUS_ONE, -INT_32BIT_PLUS_ONE), |
| 44 | + (ProtoType.SFIXED64, None, None), |
| 45 | + ], |
| 46 | +) |
| 47 | +def test_marshal_to_proto_stringy_numbers(pb_type, value, expected): |
| 48 | + |
| 49 | + marshal = BaseMarshal() |
| 50 | + assert marshal.to_proto(pb_type, value) == expected |
0 commit comments