From c4d8dc659dc739a23aab5f9065c411eede6076b5 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 8 Nov 2023 14:46:12 +0100 Subject: [PATCH] add more testing --- .github/workflows/ci.yaml | 11 +++++---- noxfile.py | 10 ++++++++ tests/doc_test/doc_needbar/conf.py | 8 +++++++ tests/doc_test/doc_needbar/index.rst | 35 ++++++++++++++++++++++++++++ tests/no_mpl_tests.py | 18 ++++++++++++++ tests/test_needbar.py | 12 ++++++++++ 6 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 tests/doc_test/doc_needbar/conf.py create mode 100644 tests/doc_test/doc_needbar/index.rst create mode 100644 tests/no_mpl_tests.py create mode 100644 tests/test_needbar.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b40552cd9..a5a8f4ab3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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 @@ -110,7 +113,7 @@ jobs: - lint - tests-core - tests-js - - docs-no-mpl + - tests-no-mpl runs-on: ubuntu-latest diff --git a/noxfile.py b/noxfile.py index e01b47e39..94999fdbb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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]") diff --git a/tests/doc_test/doc_needbar/conf.py b/tests/doc_test/doc_needbar/conf.py new file mode 100644 index 000000000..0d9b66fe3 --- /dev/null +++ b/tests/doc_test/doc_needbar/conf.py @@ -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"}, +] diff --git a/tests/doc_test/doc_needbar/index.rst b/tests/doc_test/doc_needbar/index.rst new file mode 100644 index 000000000..cf32eab7a --- /dev/null +++ b/tests/doc_test/doc_needbar/index.rst @@ -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 diff --git a/tests/no_mpl_tests.py b/tests/no_mpl_tests.py new file mode 100644 index 000000000..17cd6aece --- /dev/null +++ b/tests/no_mpl_tests.py @@ -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() diff --git a/tests/test_needbar.py b/tests/test_needbar.py new file mode 100644 index 000000000..776b7a758 --- /dev/null +++ b/tests/test_needbar.py @@ -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 '