File: test_coercion.py

package info (click to toggle)
python-apischema 0.18.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,636 kB
  • sloc: python: 15,281; makefile: 3; sh: 2
file content (24 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest

from apischema.deserialization.coercion import coerce
from apischema.types import NoneType


@pytest.mark.parametrize(
    "cls, data, result",
    [
        (int, 0, 0),
        (str, 0, "0"),
        (bool, 0, False),
        (bool, "true", True),
        (NoneType, "", None),
    ],
)
def test_coerce(cls, data, result):
    assert coerce(cls, data) == result


@pytest.mark.parametrize("cls, data", [(int, None), (bool, "I SAY NO"), (NoneType, 42)])
def test_coerce_error(cls, data):
    with pytest.raises(Exception):
        coerce(cls, data)