summaryrefslogblamecommitdiffstatshomepage
path: root/tests/scrapers/test_scraper_utils.py
blob: 193cf2ab9562eb66edc961e8c7a6e240a1adf4c0 (plain) (tree)



























                                                                            
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",
    ]