Skip to content

Commit

Permalink
add more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Nov 8, 2023
1 parent 8573961 commit c4d8dc6
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ jobs:
run: |
python -m pytest -v --ignore=tests/benchmarks -m "jstest" tests
docs-no-mpl:
# the docs should build without matplotlib (just issuing warnings)
tests-no-mpl:
name: Docs no matplotlib
runs-on: ubuntu-latest
steps:
Expand All @@ -92,10 +91,14 @@ jobs:
run: python -m pip install --upgrade pip
- name: Install Dependencies
run: |
python -m pip install -e .[docs]
python -m pip install -e .[test,docs]
python -m pip uninstall -y matplotlib numpy
python -m pip freeze
- name: Run pytest
run: |
python -m pytest -v tests/no_mpl_tests.py
- name: Run HTML build
# the docs should build without matplotlib (just issuing warnings)
run: sphinx-build -b html . _build
working-directory: docs

Expand All @@ -110,7 +113,7 @@ jobs:
- lint
- tests-core
- tests-js
- docs-no-mpl
- tests-no-mpl

runs-on: ubuntu-latest

Expand Down
10 changes: 10 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def tests(session, sphinx):
session.run("pytest", "--ignore", "tests/benchmarks", *posargs, external=True)


@session(python=PYTHON_VERSIONS)
def tests_no_mpl(session):
session.install(".[test]")
session.run("pip", "uninstall", "-y", "matplotlib", "numpy", silent=True)
session.run("echo", "TEST FINAL PACKAGE LIST")
session.run("pip", "freeze")
posargs = session.posargs or ["tests/no_mpl_tests.py"]
session.run("pytest", *posargs, external=True)


@session(python="3.10")
def benchmark_time(session):
session.install(".[test,benchmark,docs]")
Expand Down
8 changes: 8 additions & 0 deletions tests/doc_test/doc_needbar/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extensions = ["sphinx_needs"]

needs_id_regex = "^[A-Za-z0-9_]"

needs_types = [
{"directive": "req", "title": "Requirement", "prefix": "RQ_", "color": "#FEDCD2", "style": "node"},
{"directive": "spec", "title": "Specification", "prefix": "SP_", "color": "#FEDCD2", "style": "node"},
]
35 changes: 35 additions & 0 deletions tests/doc_test/doc_needbar/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
TEST DOCUMENT Needbar
=====================

.. req:: Req 1
:id: REQ_1
:tags: a

.. req:: Req 2
:id: REQ_2
:tags: b

.. req:: Req 3
:id: REQ_3
:tags: b

.. spec:: Spec 1
:id: SPEC_1
:tags: a

.. spec:: Spec 2
:id: SPEC_2
:tags: a

.. spec:: Spec 3
:id: SPEC_3
:tags: b

.. needbar:: Bar Title
:legend:
:xlabels: FROM_DATA
:ylabels: FROM_DATA

, A , B
Req , type=='req' and 'a' in tags , type=='req' and 'a' in tags
Spec , type=='spec' and 'b' in tags, type=='spec' and 'b' in tags
18 changes: 18 additions & 0 deletions tests/no_mpl_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""These tests should only be run in an environment without matplotlib installed."""
import pytest


@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_needbar"}], indirect=True)
def test_needbar(test_app):
"""Test the build fails correctly, if matplotlib is not installed."""
test_app.build()
expected = "WARNING: Matplotlib is not installed and required by needbar. Install with `sphinx-needs[plotting]` to use. [needs.mpl]"
assert expected in test_app._warning.getvalue()


@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_needpie"}], indirect=True)
def test_needpie(test_app):
"""Test the build fails correctly, if matplotlib is not installed."""
test_app.build()
expected = "WARNING: Matplotlib is not installed and required by needpie. Install with `sphinx-needs[plotting]` to use. [needs.mpl]"
assert expected in test_app._warning.getvalue()
12 changes: 12 additions & 0 deletions tests/test_needbar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pathlib import Path

import pytest


@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_needbar"}], indirect=True)
def test_doc_build_html(test_app):
app = test_app
app.build()
html = Path(app.outdir, "index.html").read_text()
assert "SPEC_1" in html
assert '<img alt="Bar Title"' in html

0 comments on commit c4d8dc6

Please sign in to comment.