File: __init__.py

package info (click to toggle)
extruct 0.18.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,048 kB
  • sloc: python: 2,106; makefile: 10
file content (30 lines) | stat: -rw-r--r-- 781 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
# mypy: disallow_untyped_defs=False
import json
import os

tests_datadir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "samples")


def get_testdata(*paths):
    """Return test data"""
    path = os.path.join(tests_datadir, *paths)
    with open(path, "rb") as f_in:
        return f_in.read()


def jsonize_dict(d):
    return json.loads(json.dumps(d))


def replace_node_ref_with_node_id(item):
    if isinstance(item, list):
        for i in item:
            replace_node_ref_with_node_id(i)
    if isinstance(item, dict):
        for key in list(item):
            val = item[key]
            if key == "htmlNode":
                item["_nodeId_"] = val.get("id")
                del item[key]
            else:
                replace_node_ref_with_node_id(val)