From d1d654ebac2d51e3841675faeb56480e440f622f Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 5 Mar 2024 18:08:09 +0100 Subject: Initial commit --- tests/scrapers/test_scraper_utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/scrapers/test_scraper_utils.py (limited to 'tests/scrapers/test_scraper_utils.py') diff --git a/tests/scrapers/test_scraper_utils.py b/tests/scrapers/test_scraper_utils.py new file mode 100644 index 0000000..193cf2a --- /dev/null +++ b/tests/scrapers/test_scraper_utils.py @@ -0,0 +1,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", + ] -- cgit v1.2.3-2-gb3c3