File: test_crunch.py

package info (click to toggle)
python-graphene 2.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,024 kB
  • sloc: python: 7,295; makefile: 196; sh: 4
file content (58 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
import pytest
from collections import OrderedDict

from ..crunch import crunch


@pytest.mark.parametrize(
    "description,uncrunched,crunched",
    [
        ["number primitive", 0, [0]],
        ["boolean primitive", True, [True]],
        ["string primitive", "string", ["string"]],
        ["empty array", [], [[]]],
        ["single-item array", [None], [None, [0]]],
        [
            "multi-primitive all distinct array",
            [None, 0, True, "string"],
            [None, 0, True, "string", [0, 1, 2, 3]],
        ],
        [
            "multi-primitive repeated array",
            [True, True, True, True],
            [True, [0, 0, 0, 0]],
        ],
        ["one-level nested array", [[1, 2, 3]], [1, 2, 3, [0, 1, 2], [3]]],
        ["two-level nested array", [[[1, 2, 3]]], [1, 2, 3, [0, 1, 2], [3], [4]]],
        ["empty object", {}, [{}]],
        ["single-item object", {"a": None}, [None, {"a": 0}]],
        [
            "multi-item all distinct object",
            OrderedDict([("a", None), ("b", 0), ("c", True), ("d", "string")]),
            [None, 0, True, "string", {"a": 0, "b": 1, "c": 2, "d": 3}],
        ],
        [
            "multi-item repeated object",
            OrderedDict([("a", True), ("b", True), ("c", True), ("d", True)]),
            [True, {"a": 0, "b": 0, "c": 0, "d": 0}],
        ],
        [
            "complex array",
            [OrderedDict([("a", True), ("b", [1, 2, 3])]), [1, 2, 3]],
            [True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, [5, 4]],
        ],
        [
            "complex object",
            OrderedDict(
                [
                    ("a", True),
                    ("b", [1, 2, 3]),
                    ("c", OrderedDict([("a", True), ("b", [1, 2, 3])])),
                ]
            ),
            [True, 1, 2, 3, [1, 2, 3], {"a": 0, "b": 4}, {"a": 0, "b": 4, "c": 5}],
        ],
    ],
)
def test_crunch(description, uncrunched, crunched):
    assert crunch(uncrunched) == crunched