def test_number(m): repack(m, -10) repack(m, 0) repack(m, 10) repack_as(m, int, -10) repack_as(m, int, 0) repack_as(m, int, 10)
def test_nested_classes(m, t1, t2, t3, v1, v2, v3): @dataclass class Child: a: t1 b: t2 @dataclass class Test1: x: t3 y: Child repack_as(m, Test1, Test1(v3, Child(v1, v2))) @dataclass class Test2: x: Child y: t3 repack_as(m, Test2, Test2(Child(v1, v2), v3)) @dataclass class Test3: p: t1 q: Child r: t3 repack_as(m, Test3, Test3(v1, Child(v1, v2), v3))
def test_bytes(m): repack_as(m, bytes, b"1234") repack_as(m, bytes, b"")
def test_bool(m): repack(m, True) repack(m, False) repack_as(m, bool, True) repack_as(m, bool, False)
def test_uuid(m): repack_as(m, uuid.UUID, uuid.uuid1())
def test_decimal(m): repack_as(m, decimal.Decimal, decimal.Decimal("3.1314134"))
def test_datetime(m): now = datetime.datetime.now() repack_as(m, datetime.datetime, now) repack_as(m, datetime.date, now.date()) repack_as(m, datetime.time, now.time())
def test_primitives(m, t1, v1): repack_as(m, t1, v1)
def test_list(m): repack(m, [1, 2, 3]) repack(m, [1]) repack(m, []) repack_as(m, list, [1, 2, 3]) repack_as(m, list, [1]) repack_as(m, list, []) repack_as(m, typing.List, [1, 2, 3]) repack_as(m, typing.List[int], [1, 2, 3]) repack_as(m, typing.List[int], [1]) repack_as(m, typing.List[int], []) repack_as(m, typing.List[typing.Any], ["a", "b", "c"]) repack_as(m, typing.List[typing.Any], ["a", "b"]) repack_as(m, typing.List[typing.Any], ["a"]) repack_as(m, typing.List[typing.Any], [])
def test_optional(m): repack_as(m, typing.Optional, 3.3) repack_as(m, typing.Optional[int], 3) repack_as(m, typing.Optional[str], "lel")
def test_flag(m): class E(enum.Flag): X = enum.auto() Y = enum.auto() Z = X | Y repack_as(m, E, E.X) repack_as(m, E, E.Y) repack_as(m, E, E.Z) @perde.attr(as_value=True) class EV(enum.Flag): X = enum.auto() Y = enum.auto() Z = X | Y repack_as(m, EV, EV.X) repack_as(m, EV, EV.Y) repack_as(m, EV, EV.Z) class IE(enum.IntFlag): X = enum.auto() Y = enum.auto() Z = X | Y repack_as(m, IE, IE.X) repack_as(m, IE, IE.Y) repack_as(m, IE, IE.Z) @perde.attr(as_value=True) class IEV(enum.IntFlag): X = enum.auto() Y = enum.auto() Z = X | Y repack_as(m, IEV, IEV.X) repack_as(m, IEV, IEV.Y) repack_as(m, IEV, IEV.Z)
def test_enum(m): class E(enum.Enum): X = 1 Y = "hage" Z = 3.3 repack_as(m, E, E.X) repack_as(m, E, E.Y) repack_as(m, E, E.Z) @perde.attr(as_value=True) class EV(enum.Enum): X = 1 Y = "hage" Z = 3.3 repack_as(m, EV, EV.X) repack_as(m, EV, EV.Y) repack_as(m, EV, EV.Z) class IE(enum.IntEnum): X = 1 Y = 4 Z = 5 repack_as(m, IE, IE.X) repack_as(m, IE, IE.Y) repack_as(m, IE, IE.Z) @perde.attr(as_value=True) class IEV(enum.IntEnum): X = 1 Y = 4 Z = 5 repack_as(m, IEV, IEV.X) repack_as(m, IEV, IEV.Y) repack_as(m, IEV, IEV.Z)
def test_tuple39(m): repack_as(m, tuple[int, str, bytes], (3, "abc", b"def")) repack_as(m, tuple[str, dict], ("hage", {"a": -10})) repack_as(m, tuple[str], ("foo",)) repack_as(m, tuple[int], ()) repack_as(m, tuple[int, str, typing.Any], (3, "abc", "def")) repack_as(m, tuple[int, typing.Any, bytes], (3, "abc", b"def")) repack_as(m, tuple[typing.Any, str, bytes], (3, "abc", b"def"))
def test_frozenset39(m): repack_as(m, frozenset[int], {1, 2, 3}) repack_as(m, frozenset[str], {"a", "b", "c"}) repack_as(m, frozenset[str], frozenset()) repack_as(m, frozenset[typing.Any], {"a", "b"}) repack_as(m, frozenset[typing.Any], {"a"}) repack_as(m, frozenset[typing.Any], frozenset())
def test_set(m): repack_as(m, set, {1, 2, 3}) repack_as(m, set, {"a", "b", "c"}) repack_as(m, set, set()) repack_as(m, typing.Set, {1, 2, 3}) repack_as(m, typing.Set[int], {1, 2, 3}) repack_as(m, typing.Set[str], {"a", "b", "c"}) repack_as(m, typing.Set[str], set()) repack_as(m, typing.Set[typing.Any], {"a", "b", "c"}) repack_as(m, typing.Set[typing.Any], set())
def test_bytearray(m): repack_as(m, bytearray, bytearray(b"1234")) repack_as(m, bytearray, bytearray(b""))
def test_dict39(m): repack_as(m, dict[str, int], {"a": 10}) repack_as(m, dict[str, int], {}) repack_as(m, dict[str, dict[str, int]], {"a": {"b": 10}}) repack_as(m, dict[str, typing.Any], {"xxx": 3.3}) repack_as(m, dict[str], {"xxx": 3.3})
def test_union(m): repack_as(m, typing.Union, 3) repack_as(m, typing.Union[int, str, bytes], 3) repack_as(m, typing.Union[int, str, bytes], b"abyte") repack_as(m, typing.Union[int, str, bytes], "hage")
def test_empty_tuple(m): @dataclass class Fruit: horoscope: typing.Union[float, typing.Set[int], typing.Tuple[()], int] repack_as(m, Fruit, Fruit(2))
def test_any(m): repack_as(m, typing.Any, 3) repack_as(m, typing.Any, "abc") repack_as(m, typing.Any, [1, 2, 3])