diff --git a/.cruft.json b/.cruft.json index 81bf4bd..6e9b169 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/sphinx-notes/cookiecutter", - "commit": "634c4022e575bd086ea47f3b42feafe24e14a939", + "commit": "62cd96195962da3392cdc34125c95e9144a5f5ca", "checkout": null, "context": { "cookiecutter": { @@ -20,7 +20,7 @@ "sphinx_version": "7.0", "development_status": "3 - Alpha", "_template": "https://github.com/sphinx-notes/cookiecutter", - "_commit": "634c4022e575bd086ea47f3b42feafe24e14a939" + "_commit": "62cd96195962da3392cdc34125c95e9144a5f5ca" } }, "directory": null diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 638156d..7f56f2c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,5 +12,14 @@ jobs: - uses: actions/setup-python@v5 with: python-version-file: 'pyproject.toml' - - run: python3 -m pip install .[dev] + - run: python3 -m pip install .[test] - run: make test + doctest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v5 + with: + python-version-file: 'pyproject.toml' + - run: python3 -m pip install .[docs] + - run: make doctest diff --git a/Makefile b/Makefile index 06a9e9d..6e7539a 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,11 @@ fmt: .PHONY: test test: - $(PY) -m unittest discover -s tests -v + $(PY) -m pytest tests/ -v + +.PHONY: doctest +doctest: + $(MAKE) doctest -C docs/ ################################################################################ # Distribution Package diff --git a/docs/conf.py b/docs/conf.py index 3f6f141..2052dd2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,6 +23,7 @@ # ones. extensions = [ 'sphinx.ext.githubpages', + 'sphinx.ext.doctest', 'sphinx_design', 'sphinx_copybutton', 'sphinx_last_updated_by_git', diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..b1ec9f9 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,8 @@ +from pathlib import Path +import pytest + +pytest_plugins = 'sphinx.testing.fixtures' + +@pytest.fixture(scope='session') +def rootdir() -> Path: + return Path(__file__).parent / 'roots' diff --git a/tests/roots/test-smoke/conf.py b/tests/roots/test-smoke/conf.py new file mode 100644 index 0000000..319b202 --- /dev/null +++ b/tests/roots/test-smoke/conf.py @@ -0,0 +1 @@ +extensions = ['sphinxnotes.data'] diff --git a/tests/roots/test-smoke/index.rst b/tests/roots/test-smoke/index.rst new file mode 100644 index 0000000..52d3541 --- /dev/null +++ b/tests/roots/test-smoke/index.rst @@ -0,0 +1,15 @@ +Smoke Test +========== + +.. data:template:: + + Name: **{{ name }}** + {% for k, v in attrs.items() %} + {{ k }}: {{ v }} + {% endfor %} + +.. data:define:: Test User + :homepage: https://example.com/ + :email: test@example.com + + This is a test user. diff --git a/tests/test_always_pass.py b/tests/test_always_pass.py new file mode 100644 index 0000000..9a05eb7 --- /dev/null +++ b/tests/test_always_pass.py @@ -0,0 +1,9 @@ +# This file is generated from sphinx-notes/cookiecutter. +# DO NOT EDIT. + +import unittest + + +class TestAlwaysPass(unittest.TestCase): + def test_dummy(self): + self.assertTrue(True) diff --git a/tests/test_smoke.py b/tests/test_smoke.py new file mode 100644 index 0000000..6652f10 --- /dev/null +++ b/tests/test_smoke.py @@ -0,0 +1,27 @@ +"""Smoke tests for sphinxnotes.data extension.""" + +import pytest + +PHASES = ['parsing', 'parsed', 'resolving'] + + +@pytest.mark.sphinx('html', testroot='smoke') +@pytest.mark.parametrize('phase', PHASES) +def test_data_template_and_define(app, status, warning, phase): + """Test that data:template and data:define directives work correctly.""" + index_path = app.srcdir / 'index.rst' + content = index_path.read_text(encoding='utf-8') + modified_content = content.replace( + '.. data:template::', + f'.. data:template::\n :on: {phase}', + 1, + ) + index_path.write_text(modified_content, encoding='utf-8') + + app.build() + + html = (app.outdir / 'index.html').read_text(encoding='utf-8') + + assert 'Test User' in html + assert 'https://example.com/' in html + assert 'test%40example.com' in html