Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
os: [ubuntu-latest]
python-version: ["3.10", "3.12"] # No "3.10", as nose seem to have problems with it
sphinx-version: ["5.0", "8.1.3"]
sphinx_needs-version: ["2.1", "4.2", "5.1", "6.3.0"]
sphinx_needs-version: ["2.1", "4.2", "5.1", "6.3.0", "8.0.0"]
steps:
- uses: actions/checkout@v2
- name: Set Up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ introduces several maintenance improvements.
-----
:Released: 26.09.2022

* Improvement: Supporting `Sphinx-Needs <https://www.sphinx-needs.com/>`__ ``>= 1.01`` only.
* Improvement: Supporting `Sphinx-Needs <https://sphinx-needs.readthedocs.io/en/latest/>`__ ``>= 1.01`` only.
Comment thread
patdhlk marked this conversation as resolved.
* Improvement: Migrated nosetests to pytest.

0.3.7
Expand Down
11 changes: 10 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# import os
import sys

import sphinx_needs
from packaging.version import Version
Comment thread
patdhlk marked this conversation as resolved.

sys.path.append(os.path.abspath("."))

from ub_theme.conf import html_theme_options
Expand Down Expand Up @@ -67,7 +70,13 @@

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates", "ub_theme/templates"]
needs_extra_options = ["more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {
"more_info": {"nullable": True},
}
else:
needs_extra_options = ["more_info"]

tr_extra_options = ["more_info"]
# Add a custom test report template. Please add a relative path from this conf.py
# tr_report_template = "./custom_test_report_template.txt"
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ In the last years, we have created additional information and extensions, which

.. grid-item-card::
:columns: 12 6 6 6
:link: https://sphinx-needs.com
:link: https://sphinx-needs.readthedocs.io/en/latest/
:img-top: /_static/sphinx-needs-card.png
:class-card: border

Expand All @@ -103,7 +103,7 @@ In the last years, we have created additional information and extensions, which
Also, it is a good entry point to understand the benefits and get an idea about the complete ecosystem of Sphinx-Needs.
+++

.. button-link:: https://sphinx-needs.com
.. button-link:: https://sphinx-needs.readthedocs.io/en/latest/
:color: primary
:outline:
:align: center
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PYTHON_VERSIONS = ["3.10", "3.12"]
SPHINX_VERSIONS = ["5.0", "7.2.5", "8.1.3"]
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1", "6.0.0", "6.3.0"]
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1", "6.0.0", "6.3.0", "8.0.0"]


def run_tests(session, sphinx, sphinx_needs):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ classifiers = [
]
keywords = ["sphinx", "documentation", "test-reports"]
requires-python = ">=3.10"
dependencies = ["sphinx>4.0", "lxml", "sphinx-needs>=1.0.1"]
dependencies = ["sphinx>4.0", "lxml", "sphinx-needs>=1.0.1", "packaging>=20.0"]

[project.optional-dependencies]
test = [
"beautifulsoup4",
"nox>=2025.2.9",
"pytest-xdist",
"pytest>=7.0",
Expand Down
112 changes: 75 additions & 37 deletions sphinxcontrib/test_reports/test_reports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# fmt: off
import inspect
import os

import sphinx
Expand All @@ -9,7 +10,7 @@
from sphinx.config import Config

# from docutils import nodes
from sphinx_needs.api import add_dynamic_function, add_extra_option, add_need_type
from sphinx_needs.api import add_dynamic_function, add_need_type

from sphinxcontrib.test_reports.directives.test_case import TestCase, TestCaseDirective
from sphinxcontrib.test_reports.directives.test_env import EnvReport, EnvReportDirective
Expand Down Expand Up @@ -39,6 +40,46 @@

VERSION = "1.3.2"

# Field descriptions for better semantics
FIELD_DESCRIPTIONS = {
"file": "Test file name",
"suite": "Test suite name",
"case": "Test case name",
"case_name": "Test case display name",
"case_parameter": "Test case parameter",
"classname": "Test class name",
"time": "Test execution time",
"suites": "Number of test suites",
"cases": "Number of test cases",
"passed": "Number of passed tests",
"skipped": "Number of skipped tests",
"failed": "Number of failed tests",
"errors": "Number of test errors",
"result": "Test result status",
}

try:
from sphinx_needs.api import add_field as _add_field

def _register_field(app, name, schema=None):
description = FIELD_DESCRIPTIONS.get(name, name)
_add_field(name, description, schema=schema)

except ImportError:
from sphinx_needs.api import add_extra_option as _add_extra_option

_add_extra_option_supports_description = (
"description" in inspect.signature(_add_extra_option).parameters
)

def _register_field(app, name, schema=None):
kwargs = {}
if _add_extra_option_supports_description:
kwargs["description"] = FIELD_DESCRIPTIONS.get(name, name)
if schema is not None:
kwargs["schema"] = schema
_add_extra_option(app, name, **kwargs)


def setup(app: Sphinx):
"""
Expand Down Expand Up @@ -177,44 +218,41 @@ def sphinx_needs_update(app: Sphinx, config: Config) -> None:
sphinx-needs configuration
"""

# Check sphinx-needs version to determine if schema is needed
try:
needs_version = Version(sphinx_needs.__version__)
use_schema = needs_version >= Version("6.0.0")
except ImportError:
# If we can't determine version, assume older version
use_schema = False

# Extra options
# For details read
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_extra_option

add_extra_option(app, getattr(config, "tr_file_option", "file"))

add_extra_option(app, "suite")
add_extra_option(app, "case")
add_extra_option(app, "case_name")
add_extra_option(app, "case_parameter")
add_extra_option(app, "classname")
# Add schema parameter conditionally based on sphinx-needs version
needs_version = Version(sphinx_needs.__version__)
use_schema = needs_version >= Version("6.0.0")

if use_schema:
add_extra_option(app, "time", schema={"type": "string"})
add_extra_option(app, "suites", schema={"type": "integer"})
add_extra_option(app, "cases", schema={"type": "integer"})
add_extra_option(app, "passed", schema={"type": "integer"})
add_extra_option(app, "skipped", schema={"type": "integer"})
add_extra_option(app, "failed", schema={"type": "integer"})
add_extra_option(app, "errors", schema={"type": "integer"})
add_extra_option(app, "result", schema={"type": "string"})
_register_field(
app, getattr(config, "tr_file_option", "file"), schema={"type": "string"}
)
_register_field(app, "suite", schema={"type": "string"})
_register_field(app, "case", schema={"type": "string"})
_register_field(app, "case_name", schema={"type": "string"})
_register_field(app, "case_parameter", schema={"type": "string"})
_register_field(app, "classname", schema={"type": "string"})
_register_field(app, "time", schema={"type": "string"})
_register_field(app, "suites", schema={"type": "integer"})
_register_field(app, "cases", schema={"type": "integer"})
_register_field(app, "passed", schema={"type": "integer"})
_register_field(app, "skipped", schema={"type": "integer"})
_register_field(app, "failed", schema={"type": "integer"})
_register_field(app, "errors", schema={"type": "integer"})
_register_field(app, "result", schema={"type": "string"})
else:
add_extra_option(app, "time")
add_extra_option(app, "suites")
add_extra_option(app, "cases")
add_extra_option(app, "passed")
add_extra_option(app, "skipped")
add_extra_option(app, "failed")
add_extra_option(app, "errors")
add_extra_option(app, "result")
_register_field(app, getattr(config, "tr_file_option", "file"))
_register_field(app, "suite")
_register_field(app, "case")
_register_field(app, "case_name")
_register_field(app, "case_parameter")
_register_field(app, "classname")
_register_field(app, "time")
_register_field(app, "suites")
_register_field(app, "cases")
_register_field(app, "passed")
_register_field(app, "skipped")
_register_field(app, "failed")
_register_field(app, "errors")
_register_field(app, "result")
# Extra dynamic functions
# For details about usage read
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_dynamic_function
Expand Down
8 changes: 7 additions & 1 deletion tests/doc_test/basic_doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -69,7 +72,10 @@
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
needs_extra_options = ["more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {"more_info": {"nullable": True}}
else:
needs_extra_options = ["more_info"]
tr_extra_options = ["more_info"]

# The name of the Pygments (syntax highlighting) style to use.
Expand Down
12 changes: 11 additions & 1 deletion tests/doc_test/doc_test_ctest_file/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -75,7 +78,14 @@
# The master toctree document.
master_doc = "index"

needs_extra_options = ["asil", "uses_secure", "more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {
"asil": {"nullable": True},
"uses_secure": {"nullable": True},
"more_info": {"nullable": True},
}
else:
needs_extra_options = ["asil", "uses_secure", "more_info"]
tr_extra_options = ["more_info"]

# General information about the project.
Expand Down
12 changes: 11 additions & 1 deletion tests/doc_test/doc_test_file/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -75,7 +78,14 @@
# The master toctree document.
master_doc = "index"

needs_extra_options = ["asil", "uses_secure", "more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {
"asil": {"nullable": True},
"uses_secure": {"nullable": True},
"more_info": {"nullable": True},
}
else:
needs_extra_options = ["asil", "uses_secure", "more_info"]
tr_extra_options = ["more_info"]

# General information about the project.
Expand Down
8 changes: 7 additions & 1 deletion tests/doc_test/json_parser_custom/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand All @@ -32,7 +35,10 @@

extensions = ["sphinx_needs", "sphinxcontrib.test_reports"]

needs_extra_options = ["priority"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {"priority": {"nullable": True}}
else:
needs_extra_options = ["priority"]
tr_extra_options = ["priority"]

tr_json_mapping = {
Expand Down
8 changes: 7 additions & 1 deletion tests/doc_test/many_testsuites_doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand All @@ -37,7 +40,10 @@

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
needs_extra_options = ["more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {"more_info": {"nullable": True}}
else:
needs_extra_options = ["more_info"]
tr_extra_options = ["more_info"]

# The suffix(es) of source filenames.
Expand Down
12 changes: 11 additions & 1 deletion tests/doc_test/needs_linking/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -75,7 +78,14 @@
# The master toctree document.
master_doc = "index"

needs_extra_options = ["asil", "uses_secure", "references"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {
"asil": {"nullable": True},
"uses_secure": {"nullable": True},
"references": {"nullable": True},
}
else:
needs_extra_options = ["asil", "uses_secure", "references"]

# General information about the project.
project = "test-report test docs"
Expand Down
8 changes: 7 additions & 1 deletion tests/doc_test/testsuites_doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import os
import sys

import sphinx_needs
from packaging.version import Version

sys.path.insert(0, os.path.abspath("../../sphinxcontrib"))

# -- General configuration ------------------------------------------------
Expand All @@ -34,7 +37,10 @@

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
needs_extra_options = ["more_info"]
if Version(sphinx_needs.__version__) >= Version("8.0.0"):
needs_fields = {"more_info": {"nullable": True}}
else:
needs_extra_options = ["more_info"]
tr_extra_options = ["more_info"]

# The suffix(es) of source filenames.
Expand Down
Loading
Loading