1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""
import itertools
from collections import OrderedDict
import pytest
from typepy import Dictionary, StrictLevel, Typecode
nan = float("nan")
inf = float("inf")
class Test_Dictionary_is_type:
@pytest.mark.parametrize(
["value", "strict_level", "expected"],
[
[[["a", 1]], StrictLevel.MIN, True],
[[["a", 1]], StrictLevel.MAX, False],
[(("a", 1),), StrictLevel.MIN, True],
[(("a", 1),), StrictLevel.MAX, False],
]
+ list(
itertools.product(
[{}, {"a": 1, "b": 2}, OrderedDict(a=1, b=1)],
[StrictLevel.MIN, StrictLevel.MAX],
[True],
)
)
+ [
['{"foo": 10}', StrictLevel.MIN, True],
['{"foo": 10}', StrictLevel.MAX, False],
]
+ list(
itertools.product(
[1, "a", "あ".encode(), nan, True, None],
[StrictLevel.MIN, StrictLevel.MAX],
[False],
)
),
)
def test_normal(self, value, strict_level, expected):
type_object = Dictionary(value, strict_level)
assert type_object.is_type() == expected
assert type_object.typecode == Typecode.DICTIONARY
|