summaryrefslogtreecommitdiffstatshomepage
path: root/tests/scrapers/test_scraper_utils.py
blob: 193cf2ab9562eb66edc961e8c7a6e240a1adf4c0 (plain) (blame)
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
from hircine.scraper.utils import parse_dict


def test_parse_dict():
    dict = {
        "scalar": "foo",
        "list": ["bar", "baz"],
        "dict": {"nested_scalar": "qux", "nested_list": ["plugh", "xyzzy"]},
    }

    def id(type):
        return lambda item: f"{type}_{item}"

    parsers = {
        "scalar": id("scalar"),
        "list": id("list"),
        "dict": {"nested_scalar": id("scalar"), "nested_list": id("list")},
        "missing": id("missing"),
    }

    assert [f() for f in parse_dict(parsers, dict)] == [
        "scalar_foo",
        "list_bar",
        "list_baz",
        "scalar_qux",
        "list_plugh",
        "list_xyzzy",
    ]