Skip to content

Commit

Permalink
Upgraded
Browse files Browse the repository at this point in the history
- Upgraded to allow for compaitiblity with Sphinx-needs 4.0+
- Changed paths  to allow for better integration with other tools (like bazel).
- Added setuptools as dependency as it wasn't there already but is used.
- Added possibility for mutliple values in 'tr_link' targeted option
- Enabled TestFileDirective, TestSuiteDirective, TestCaseDirective to
  have additional options from extra_links & extra_options
- Edited tests to only test newer versions of Sphinx & Python
- Fixed tests to account for new paths
  • Loading branch information
MaximilianSoerenPollak committed Nov 28, 2024
1 parent a8da8e8 commit 21a9a56
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 117 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
author = "team useblocks"

# The short X.Y version
version = "1.0"
version = "1.1"
# The full version, including alpha/beta/rc tags
release = "1.0.2"
release = "1.1.0a"


# -- General configuration ---------------------------------------------------
Expand Down
34 changes: 17 additions & 17 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import nox
from nox import session

PYTHON_VERSIONS = ["3.8", "3.9", "3.10"]
SPHINX_VERSIONS = ["5.0", "6.2.1", "7.1.2", "7.2.5"]
PYTHON_VERSIONS = ["3.11", "3.12"]
SPHINX_VERSIONS = ["7.4.1", "8.1"]
TEST_DEPENDENCIES = [
"pytest",
"pytest-xdist",
Expand Down Expand Up @@ -36,18 +36,18 @@ def tests(session, sphinx):
session.skip("unsupported combination")


@session(python="3.9")
def lint(session):
session.install(*LINT_DEPENDENCIES)
session.run("make", "lint", external=True)


@session(python="3.9")
def linkcheck(session):
session.install(".")
# LinkCheck cn handle rate limits since Sphinx 3.4, which is needed as
# our doc has to many links to GitHub.
session.run("pip", "install", "sphinx==3.5.4", silent=True)

session.run("pip", "install", "-r", "doc-requirements.txt", silent=True)
session.run("make", "docs-linkcheck", external=True)
# @session(python="3.9")
# def lint(session):
# session.install(*LINT_DEPENDENCIES)
# session.run("make", "lint", external=True)
#
#
# @session(python="3.11")
# def linkcheck(session):
# session.install(".")
# # LinkCheck cn handle rate limits since Sphinx 3.4, which is needed as
# # our doc has to many links to GitHub.
# session.run("pip", "install", "sphinx==3.5.4", silent=True)
#
# session.run("pip", "install", "-r", "doc-requirements.txt", silent=True)
# session.run("make", "docs-linkcheck", external=True)
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import os

from setuptools import find_packages, setup
from setuptools import find_namespace_packages, setup

requires = ["sphinx>=4.0", "lxml", "sphinx-needs>=1.0.1"]
requires = ["sphinx>=7.4.1", "lxml", "sphinx-needs>=4.0.0", "setuptools"]

with open(os.path.join(os.path.dirname(__file__), "README.rst")) as file:
setup(
name="sphinx-test-reports",
# Update also test_reports.py, conf.py and changelog!
version="1.0.2",
version="1.1.0a",
url="http://github.com/useblocks/sphinx-test-reports",
download_url="http://pypi.python.org/pypi/sphinx-test-reports",
license="MIT",
Expand All @@ -33,10 +33,12 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Documentation",
],
platforms="any",
packages=find_packages(),
packages=find_namespace_packages(include=['sphinxcontrib.*']),
include_package_data=True,
install_requires=requires,
namespace_packages=["sphinxcontrib"],
Expand Down
1 change: 0 additions & 1 deletion sphinxcontrib/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion sphinxcontrib/test_reports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# from sphinxcontrib.test_reports.needs.dyn_functions import Results4Needs
from sphinxcontrib.test_reports.test_reports import setup
from .test_reports import setup
46 changes: 40 additions & 6 deletions sphinxcontrib/test_reports/directives/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from docutils.parsers.rst import directives
from sphinx_needs.api import add_need
from sphinx_needs.utils import add_doc
from sphinx_needs.config import NeedsSphinxConfig

from sphinxcontrib.test_reports.directives.test_common import TestCommonDirective
from sphinxcontrib.test_reports.exceptions import TestReportInvalidOption
from .test_common import TestCommonDirective
from ..exceptions import TestReportInvalidOption


class TestCase(nodes.General, nodes.Element):
Expand Down Expand Up @@ -33,9 +34,6 @@ class TestCaseDirective(TestCommonDirective):

final_argument_whitespace = True

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def run(self, nested=False, suite_count=-1, case_count=-1):
self.prepare_basic_options()
self.load_test_file()
Expand Down Expand Up @@ -163,6 +161,41 @@ def run(self, nested=False, suite_count=-1, case_count=-1):

main_section = []
docname = self.state.document.settings.env.docname
needs_config = NeedsSphinxConfig(self.env.config)
extra_links = needs_config.extra_links
extra_options = needs_config.extra_options
specified_opts = (
"docname",
"lineno",
"type",
"title",
"id",
"content",
"links",
"tags",
"status",
"collapse",
"file",
"suite",
"case",
"case_name",
"case_parameter",
"classname",
"result",
"time",
"style",
"passed",
"skipped",
"failed",
"errors",
)
need_extra_options = {}
extra_links_options = [x["option"] for x in extra_links]
all_options = extra_links_options + list(extra_options.keys())
for extra_option in all_options:
if extra_option not in specified_opts:
need_extra_options[extra_option] = self.options.get(extra_option, "")

main_section += add_need(
self.app,
self.state,
Expand All @@ -185,7 +218,8 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
result=result,
time=time,
style=style,
**need_extra_options
)

add_doc(self.env, docname)
return main_section
47 changes: 39 additions & 8 deletions sphinxcontrib/test_reports/directives/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
# fmt: off
import os

from docutils.parsers.rst import Directive
from docutils.parsers.rst import Directive, directives
from sphinx.util import logging
from sphinx_needs.api import make_hashed_id
from sphinx_needs.api.need import _make_hashed_id
from sphinx_needs.config import NeedsSphinxConfig
from sphinx_needs.data import SphinxNeedsData, NeedsInfoType
from typing import Any, Dict, List, Iterable

from sphinxcontrib.test_reports.exceptions import (
from ..exceptions import (
SphinxError, TestReportFileNotSetException)
from sphinxcontrib.test_reports.jsonparser import JsonParser
from sphinxcontrib.test_reports.junitparser import JUnitParser
from ..jsonparser import JsonParser
from ..junitparser import JUnitParser

# fmt: on

Expand All @@ -21,6 +24,36 @@ class TestCommonDirective(Directive):
Common directive, which provides some shared functions to "real" directives.
"""

@classmethod
def update_option_spec(cls, app):
"""
Adding extra_options & extra_links defined via sphinx_needs to 'allowed' options
"""
needs_config = NeedsSphinxConfig(app.config)

if not hasattr(cls, 'option_spec'):
cls.option_spec = {}
elif cls.option_spec is None:
cls.option_spec = {}
new_options = dict(getattr(cls, 'option_spec', {}) or {})

extra_options = getattr(needs_config, 'extra_options', None)
if extra_options is None:
extra_options = {}
extra_links = getattr(needs_config, 'extra_links', None)
if extra_links is None:
extra_links = {}

extra_links_options = [x["option"] for x in extra_links]
all_options = extra_links_options + list(extra_options.keys())

for option in all_options:
if option not in new_options:
new_options[option] = directives.unchanged

cls.option_spec = new_options


def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.env = self.state.document.settings.env
Expand Down Expand Up @@ -90,9 +123,7 @@ def prepare_basic_options(self):
self.need_type = self.app.tr_types[self.name][0]
self.test_id = self.options.get(
"id",
make_hashed_id(
self.app, self.need_type, self.test_name, self.test_content
),
_make_hashed_id(self.need_type, self.test_name, self.test_content, NeedsSphinxConfig(self.app.config))
)
else:
self.test_id = self.options.get("id")
Expand Down
48 changes: 39 additions & 9 deletions sphinxcontrib/test_reports/directives/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from docutils.parsers.rst import directives
from sphinx_needs.api import add_need
from sphinx_needs.utils import add_doc
from sphinx_needs.config import NeedsSphinxConfig

import sphinxcontrib.test_reports.directives.test_suite
from sphinxcontrib.test_reports.directives.test_common import TestCommonDirective
from sphinxcontrib.test_reports.exceptions import TestReportIncompleteConfiguration
from sphinx_needs.data import NeedsInfoType
from .test_suite import TestSuiteDirective
from .test_common import TestCommonDirective
from ..exceptions import TestReportIncompleteConfiguration


class TestFile(nodes.General, nodes.Element):
Expand Down Expand Up @@ -35,13 +37,38 @@ class TestFileDirective(TestCommonDirective):

final_argument_whitespace = True

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.suite_ids = {}

def run(self):
self.suite_ids = {}
self.prepare_basic_options()
results = self.load_test_file()
needs_config = NeedsSphinxConfig(self.env.config)
extra_links = needs_config.extra_links
extra_options = needs_config.extra_options
specified_opts = (
"docname",
"lineno",
"type",
"title",
"id",
"content",
"links",
"tags",
"status",
"collapse",
"file",
"suites",
"cases",
"passed",
"skipped",
"failed",
"errors",
)
need_extra_options = {}
extra_links_options = [x["option"] for x in extra_links]
all_options = extra_links_options + list(extra_options.keys())
for extra_option in all_options:
if extra_option not in specified_opts:
need_extra_options[extra_option] = self.options.get(extra_option, "")

# Error handling, if file not found
if results is None:
Expand All @@ -65,6 +92,8 @@ def run(self):

main_section = []
docname = self.state.document.settings.env.docname
needs_config = NeedsSphinxConfig(self.env.config)
need_extra_options = {}
main_section += add_need(
self.app,
self.state,
Expand All @@ -84,7 +113,8 @@ def run(self):
passed=passed,
skipped=skipped,
failed=failed,
errors=errors,
errors=errors,
**need_extra_options
)

if (
Expand Down Expand Up @@ -124,7 +154,7 @@ def run(self):

arguments = [suite["name"]]
suite_directive = (
sphinxcontrib.test_reports.directives.test_suite.TestSuiteDirective(
TestSuiteDirective(
self.app.config.tr_suite[0],
arguments,
options,
Expand Down
4 changes: 2 additions & 2 deletions sphinxcontrib/test_reports/directives/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from docutils import nodes
from docutils.parsers.rst import directives

from sphinxcontrib.test_reports.directives.test_common import \
from .test_common import \
TestCommonDirective
from sphinxcontrib.test_reports.exceptions import InvalidConfigurationError
from ..exceptions import InvalidConfigurationError

# fmt: on

Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/test_reports/directives/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from docutils import nodes
from docutils.parsers.rst import Directive

from sphinxcontrib.test_reports.junitparser import JUnitParser
from ..junitparser import JUnitParser


class TestResults(nodes.General, nodes.Element):
Expand Down
Loading

0 comments on commit 21a9a56

Please sign in to comment.