Skip to content

Commit 0db258d

Browse files
authored
🧪 Add simple pytest build test (#10)
1 parent 917ddc7 commit 0db258d

File tree

7 files changed

+71
-9
lines changed

7 files changed

+71
-9
lines changed

‎.github/workflows/build.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
# set -e
5757
# pip install --upgrade pip
5858
# pip install sphinx_rust --find-links dist --force-reinstall
59-
# pip install pytest pytest-param-files
59+
# pip install pytest
6060
# pytest
6161
# - name: pytest
6262
# if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }}
@@ -68,7 +68,7 @@ jobs:
6868
# install: |
6969
# apt-get update
7070
# apt-get install -y --no-install-recommends python3-dev python3-pip build-essential
71-
# pip3 install -U pip pytest pytest-param-files
71+
# pip3 install -U pip pytest
7272
# run: |
7373
# set -e
7474
# pip3 install sphinx_rust --find-links dist --force-reinstall
@@ -104,7 +104,7 @@ jobs:
104104
# set -e
105105
# pip install --upgrade pip
106106
# pip install sphinx_rust --find-links dist --force-reinstall
107-
# pip install pytest pytest-param-files
107+
# pip install pytest
108108
# pytest
109109

110110
macos:
@@ -136,7 +136,7 @@ jobs:
136136
# set -e
137137
# pip install --upgrade pip
138138
# pip install sphinx_rust --find-links dist --force-reinstall
139-
# pip install pytest pytest-param-files
139+
# pip install pytest
140140
# pytest
141141

142142
sdist:

‎.github/workflows/tests.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ jobs:
7474
uses: actions/setup-python@v5
7575
with:
7676
python-version: ${{ matrix.python-version }}
77-
- run: pip install -e .[testing]
77+
- run: pip install -e .[test]
7878
env:
7979
RUST_BACKTRACE: 1
8080
- run: pip freeze
81-
# - run: pytest
81+
- run: pytest
8282

8383
check:
8484
if: always()

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ To run the analysis CLI tool:
3838
tox -e dev -- python -m sphinx_rust.cli crates/py_binding --overwrite
3939
```
4040

41+
To run the pytest tests:
42+
43+
```bash
44+
tox -e test-py39
45+
```
46+
4147
To build the documentation:
4248

4349
```bash

‎pyproject.toml‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dynamic = ["version"]
1313
description = "Sphinx plugin for documentation of Rust projects."
1414
authors = [{ name = "Chris Sewell", email = "chrisj_sewell@hotmail.com" }]
1515
readme = "README.md"
16-
requires-python = ">=3.8"
16+
requires-python = ">=3.9"
1717
license = { file = "LICENSE" }
1818
keywords = [
1919
"sphinx",
@@ -26,7 +26,6 @@ classifiers = [
2626
"License :: OSI Approved :: MIT License",
2727
"Operating System :: OS Independent",
2828
"Programming Language :: Python",
29-
"Programming Language :: Python :: 3.8",
3029
"Programming Language :: Python :: 3.9",
3130
"Programming Language :: Python :: 3.10",
3231
"Programming Language :: Python :: 3.11",
@@ -47,9 +46,12 @@ Documentation = "http://sphinx-rust.readthedocs.io"
4746

4847
[project.optional-dependencies]
4948
dev = [
50-
"pytest",
5149
"ipython"
5250
]
51+
test = [
52+
"pytest",
53+
"defusedxml",
54+
]
5355
docs = [
5456
"furo",
5557
"myst-parser",
@@ -111,6 +113,16 @@ allowlist_externals = bash
111113
commands_pre = bash -c "unset CONDA_PREFIX; maturin develop"
112114
commands = {posargs:ipython}
113115
116+
[testenv:test-{py39,py310,py311,py312}]
117+
extras = test
118+
passenv = TERM
119+
; ensure that the compilation is up-to-date
120+
; There is an issue with mixing maturin with tox-conda, raising:
121+
; Both VIRTUAL_ENV and CONDA_PREFIX are set. Please unset one of them
122+
allowlist_externals = bash
123+
commands_pre = bash -c "unset CONDA_PREFIX; maturin develop"
124+
commands = pytest {posargs}
125+
114126
[testenv:docs]
115127
extras = docs
116128
passenv = TERM

‎python/sphinx_rust/domain.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def on_builder_inited(app: Sphinx) -> None:
104104
LOGGER.warning(
105105
f"Error analyzing crate: {e!s}", type="rust", subtype="analyze"
106106
)
107+
return
107108
create_pages(srcdir, result)
108109

109110
@property

‎tests/conftest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest_plugins = ["sphinx.testing.fixtures"]

‎tests/test_sphinx_build.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Simple test to build sphinx documentation."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
from textwrap import dedent
7+
8+
from sphinx.testing.util import SphinxTestApp
9+
from sphinx.util.console import strip_colors
10+
11+
12+
def test_basic(make_app: type[SphinxTestApp], tmp_path: Path) -> None:
13+
"""Basic sphinx build test."""
14+
tmp_path.joinpath("Cargo.toml").write_text(
15+
dedent("""\
16+
[package]
17+
name = "test"
18+
version = "0.1.0"
19+
[lib]
20+
""")
21+
)
22+
tmp_path.joinpath("conf.py").write_text(
23+
dedent("""\
24+
extensions = ['sphinx_rust']
25+
rust_crates = ['.']
26+
""")
27+
)
28+
tmp_path.joinpath("index.rst").write_text(
29+
dedent("""\
30+
Test
31+
====
32+
.. toctree:: api/crates/test/index
33+
""")
34+
)
35+
36+
app = make_app("html", srcdir=tmp_path)
37+
app.build()
38+
assert strip_colors(app.warning.getvalue()) == "" # noqa: PLC1901
39+
40+
assert (
41+
Path(str(app.outdir)).joinpath("api", "crates", "test", "index.html").exists()
42+
)

0 commit comments

Comments
 (0)