Skip to content

Commit

Permalink
tests: testing codspeed
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Nov 1, 2023
1 parent 385cc9c commit 1eb139c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 29 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: codspeed-benchmarks

on:
push:
branches:
- "main"
# Run on pull requests
pull_request:
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
hatch env create
- name: Run benchmarks
uses: CodSpeedHQ/action@v1
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: "pytest benchmarks/ --codspeed"
Empty file added benchmarks/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions benchmarks/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

import pytest

import mknodes as mk


@pytest.mark.benchmark()
def test_build_duration(benchmark):
theme = mk.MaterialTheme()
from mknodes.manual import root

proj = mk.Project(theme=theme)
root.build(proj)
for node in proj.root.descendants:
if not isinstance(node, mk.MkPage):
continue
node.to_markdown()
12 changes: 6 additions & 6 deletions mknodes/templatenodes/mkpydeps/metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ group = "documentation"
# {{ "mknodes/data/tools.py" | MkPyDeps(max_bacon=1, max_module_depth=1) }}
# """

[output.markdown]
template = """
<body>
# [output.markdown]
# template = """
# <body>

{{ node.svg }}
# {{ node.svg }}

</body>
# </body>

"""
# """
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = [
# Testing
"pytest",
"pytest-cov",

"pytest-codspeed",
# Docs
"mkdocs >=1.5",
"mkdocs-material >= 9.4",
Expand Down
12 changes: 0 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

import pytest

import mknodes as mk

from mknodes.manual import root


@pytest.fixture(scope="session")
def test_data_dir():
Expand All @@ -17,11 +13,3 @@ def test_data_dir():
@pytest.fixture(scope="session")
def resources_dir():
return pathlib.Path(__file__).parent.parent / "mknodes/resources/"


@pytest.fixture(scope="session")
def mknodes_project():
theme = mk.MaterialTheme()
proj = mk.Project(theme=theme)
root.build(proj)
return proj
8 changes: 8 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def build(project):
project.root += sub_nav


def test_build():
theme = mk.MaterialTheme()
from mknodes.manual import root

proj = mk.Project(theme=theme)
root.build(proj)


# def test_templates():
# theme = mk.MaterialTheme()
# project = mk.Project(theme=theme, repo=".", build_fn=build)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import mknodes as mk


def test_if_mknodes_parent_is_set(mknodes_project):
def test_if_mknodes_parent_is_set():
page = mk.MkPage()
mknodes_project._root += page
page.env.render_string(r"{{ 'test' | MkHeader }}")
assert page.env.rendered_nodes[-1].parent == page


def test_correct_child_count_after_multiple_renders(mknodes_project):
def test_correct_child_count_after_multiple_renders():
page = mk.MkPage()
mknodes_project._root += page
page.env.render_string(r"{{ 'test' | MkHeader }}")
assert len(page.env.rendered_nodes) == 1
page.env.render_string(r"{{ 'test' | MkHeader }}")
Expand Down
14 changes: 8 additions & 6 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

import mknodes as mk

from mknodes.treelib import noderesolver


def test_resolver(mknodes_project):
def test_resolver():
resolver = noderesolver.MkNodeResolver()
result = resolver.glob("*/*/MkAdm*", mknodes_project._root)
root = mk.MkNav()
sub = root.add_nav("SubNav")
page = sub.add_page("Test")
page += mk.MkAdmonition("Test")
result = resolver.glob("*/*/MkAdm*", root)
assert result


def resolving_files(mknodes_project):
mknodes_project.all_files()

0 comments on commit 1eb139c

Please sign in to comment.