示例#1
0
def pytest_collection_modifyitems(items):
    output = {}
    for item in items:
        item_class = item.location[0]
        item_class = item_class[:item_class.rfind('.')].replace('/', '.')
        item_name = item.location[2]
        item_param = re.findall(r'\.*(\[.*\])', item_name)
        if item_param:
            item_name = item_name.replace(item_param[0], '')
        node_name = '{}.{}'.format(item_class, item_name)
        output[node_name] = {}
        docstring = getattr(item.function, '__doc__') or ''
        output[node_name]['docstring'] = docstring.encode('utf-8')
        output[node_name]['name'] = item_name

        # This is necessary to convert AttrDict in metadata, or even metadict(previously)
        # into serializable data as builtin doesn't contain instancemethod and gives us issues.
        doc_meta = {
            k: v
            for k, v in item._metadata.get('from_docs', {}).items()
        }
        output[node_name]['metadata'] = {'from_docs': doc_meta}

    with open('doc_data.yaml', 'w') as f:

        def dice_representer(dumper, data):
            return dumper.represent_scalar("chew", "me")

        import lya
        from yaml.representer import SafeRepresenter
        yaml.add_representer(lya.lya.AttrDict, SafeRepresenter.represent_dict)
        yaml.safe_dump(output, f)
示例#2
0
def pytest_collection_modifyitems(items):
    output = {}
    for item in items:
        item_class = item.location[0]
        item_class = item_class[:item_class.rfind('.')].replace('/', '.')
        item_name = item.location[2]
        item_param = re.findall(r'\.*(\[.*\])', item_name)
        if item_param:
            item_name = item_name.replace(item_param[0], '')
        node_name = '{}.{}'.format(item_class, item_name)
        output[node_name] = {}
        docstring = getattr(item.function, '__doc__') or ''
        output[node_name]['docstring'] = base64.b64encode(
            docstring if six.PY2 else docstring.encode('utf-8'))
        output[node_name]['name'] = item_name

        # This is necessary to convert AttrDict in metadata, or even metadict(previously)
        # into serializable data as builtin doesn't contain instancemethod and gives us issues.
        doc_meta = {k: v for k, v in item._metadata.get('from_docs', {}).items()}
        output[node_name]['metadata'] = {'from_docs': doc_meta}

    with open('doc_data.yaml', 'w') as f:
        def dice_representer(dumper, data):
            return dumper.represent_scalar("chew", "me")
        import lya
        from yaml.representer import SafeRepresenter
        yaml.add_representer(lya.lya.AttrDict, SafeRepresenter.represent_dict)
        yaml.safe_dump(output, f)