Skip to content

Commit

Permalink
Unit test for annotated decimal type
Browse files Browse the repository at this point in the history
  • Loading branch information
faph committed Nov 5, 2023
1 parent ac2521b commit 614d8ac
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_logicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# specific language governing permissions and limitations under the License.

import datetime
import decimal
import uuid
from typing import Any, Dict, List
from typing import Annotated, Any, Dict, List

import py_avro_schema as pas
from py_avro_schema._testing import assert_schema
Expand Down Expand Up @@ -76,6 +77,7 @@ def test_timedelta():


def test_decimal():
# Deprecated custom type hint for decimals
py_type = pas.DecimalType[5, 2]
expected = {
"type": "bytes",
Expand All @@ -86,6 +88,17 @@ def test_decimal():
assert_schema(py_type, expected)


def test_annotated_decimal():
py_type = Annotated[decimal.Decimal, (5, 2)]
expected = {
"type": "bytes",
"logicalType": "decimal",
"precision": 5,
"scale": 2,
}
assert_schema(py_type, expected)


def test_multiple_decimals():
# Test the magic with _GenericAlias!
py_type_1 = pas.DecimalType[5, 2]
Expand Down

0 comments on commit 614d8ac

Please sign in to comment.