Skip to content

Add tests for new features in the template that evaluates markdown syntax and finds issues- a test_markdown.py module #98

@lwasser

Description

@lwasser

we should test this! just writing this in the gh comment box, haven't run it, but ya since this is a template repo it makes sense for us to actually be able to test the markdown it renders, and this seems like a good opportunity to get some basic patterns in a test_markdown.py module or something

# add to test deps
import mistune

def _recursive_extract(parsed: list[dict], typ: str) -> list[dict]:
    res = []
    for block in parsed:
        if block.get('type') == typ:
            res.append(block)
        if 'children' in block:
            res.extend(_recursive_extract(block, typ))
    return res

@pytest.mark.parameterize("username", ["juno", None])
@pytest.mark.parameterize("use_git", [True, False])
def test_contributing_links(username, use_git):
    project = generated(username=username, use_git=use_git)
    contributing = (project / "CONTRIBUTING.md").read_text()
    parsed = mistune.Markdown()(contributing)
    links = _recursive_extract(parsed, "link")
    urls = [link['attrs']['url'] for link in links]
    
    if username and use_git:
        # we would also want to test for no broken links, as well as include all the links we expect to exist,
        # but just writing a quick 5 minute example
        assert f"https://github.com/{username}/alien-clones" in urls
    else:
        assert not any(["https://github.com" in url for url in urls])

Originally posted by @sneakers-the-rat in #95 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions