Пример #1
0
def info(input, verbose, pyformat, **kwargs):
    """
    Provides info about the input. Requires valid input.
    """
    if not input:
        input = '-'
    with click.open_file(input, mode='rb') as f:
        # root = xml_utils.load(f)
        tree = ET.parse(f)
        root = tree.getroot()
        d = {}
        d.update({'xml': xml_utils.element_info(root)})

        rf_metrics = {
            'suites': xml_utils.count_elements(tree, xpath='//suite'),
            'tests': xml_utils.count_elements(tree, xpath='//test'),
            'messages': xml_utils.count_elements(tree, xpath='//msg')
        }
        d.update({'robot': rf_metrics})

        if verbose:
            d['_object'] = {
                'type': type(root),
                # 'repr': repr(root),
                # 'vars': sorted(vars(root)),
                # 'dir': sorted(dir(root)),
                'members': sorted(varsdict(root).keys())
            }
        # click.echo(d)
        # click.echo(sorted(d.items()))
        if pyformat:
            s = pformat(d)
        else:
            s = json.dumps(d, indent=2, sort_keys=True)
        click.echo(s)
Пример #2
0
def info(input, verbose, pyformat, **kwargs):
    """
    Provides info about the input. Requires valid input.
    """
    if not input:
        input = "-"
    with click.open_file(input, mode="rb") as f:
        parser = Parser()
        feature_text = f.read()
        feature = parser.parse(feature_text)

        metrics = {}
        steps = [a[-1] for d, k, v, a in walk_items(feature) if k == "type" and v == "Step"]
        scenarios = [a[-1] for d, k, v, a in walk_items(feature) if k == "type" and v == "Scenario"]
        # tables = [a[-1] for d, k, v, a in walk_items(feature) if k == 'type' and v == 'DataTable']
        ctr_type = Counter((v for d, k, v in walk_items(feature, ancestors=False) if k == "type"))
        ctr_kw = Counter((v for d, k, v in walk_items(feature, ancestors=False) if k == "keyword"))
        metrics.update({"count": {"Keywords": ctr_kw, "Types": ctr_type}})
        metrics.update({"content": {"Scenarios": [d["name"] for d in scenarios], "Steps": [d["text"] for d in steps]}})
        data = metrics

        if verbose:
            data["_object"] = {"type": type(feature), "members": sorted(varsdict(feature).keys())}
        if pyformat:
            s = pformat(data)
        else:
            s = json.dumps(data, indent=2, sort_keys=True)
        click.echo(s)
Пример #3
0
def info(input, verbose, pyformat, **kwargs):
    """
    Provides info about the input. Requires valid input.
    """
    if not input:
        input = "-"
    with click.open_file(input, mode="rb") as f:
        data = json_utils.load_ordered(f)
        d = {"length": len(data), "keys": sorted(data.keys())}
        if verbose:
            d["_object"] = {
                "type": type(data),
                # 'repr': repr(data),
                # 'vars': sorted(vars(data)),
                # 'dir': sorted(dir(data)),
                "members": sorted(varsdict(data).keys()),
            }
        # click.echo(d)
        # click.echo(sorted(d.items()))
        if pyformat:
            s = pformat(d)
        else:
            s = json.dumps(d, indent=2, sort_keys=True)
        click.echo(s)