Skip to content

Commit 54fa458

Browse files
patdhlkubmarco
andauthored
👌 Handle SN >= 6 schema validation (#122)
* Handle SN >= 6 schema validation * Add SN 6 to test-matrix * Update noxfile.py Co-authored-by: Marco Heinemann <marco.heinemann@useblocks.com>
1 parent c487ea0 commit 54fa458

4 files changed

Lines changed: 47 additions & 14 deletions

File tree

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Sphinx-Test-Reports
22
===================
33

4-
.. image:: docs/_static/sphinx-test-reports-logo.png
4+
.. image:: https://raw.githubusercontent.com/useblocks/sphinx-test-reports/master/docs/_static/sphinx-test-reports-logo.png
55

66
Sphinx-Test-Reports shows test results of your unit tests inside your sphinx documentation.
77

‎noxfile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
PYTHON_VERSIONS = ["3.10", "3.12"]
55
SPHINX_VERSIONS = ["5.0", "7.2.5", "8.1.3"]
6-
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1"]
6+
SPHINX_NEEDS_VERSIONS = ["2.1", "4.2", "5.1", "6.0.1"]
77

88

99
def run_tests(session, sphinx, sphinx_needs):

‎sphinxcontrib/test_reports/directives/test_case.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
129129
""".format("\n ".join([x.lstrip() for x in case["system-out"].split("\n")]))
130130

131131
time = case["time"]
132+
# Ensure time is a string, SN 6.0.0 requires to be in one specific type
133+
# and it is set to string for backwards compatibility
134+
if isinstance(time, (int, float)):
135+
# Keep as numeric seconds (decimal format)
136+
time = float(time) if time >= 0 else 0.0
137+
elif time is None:
138+
time = 0.0
139+
else:
140+
# Try to parse string to float, fallback to 0.0
141+
try:
142+
time = float(time)
143+
except (ValueError, TypeError):
144+
time = 0.0
145+
time_str = str(time)
146+
147+
# If time is already a string or None, keep it as is
132148
style = "tr_" + case["result"]
133149

134150
import re
@@ -180,7 +196,7 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
180196
case_parameter=case_parameter,
181197
classname=class_name,
182198
result=result,
183-
time=time,
199+
time=time_str,
184200
style=style,
185201
**self.extra_options,
186202
)

‎sphinxcontrib/test_reports/test_reports.py‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
import sphinx
5+
import sphinx_needs
56
from docutils.parsers.rst import directives
67
from packaging.version import Version
78
from sphinx.application import Sphinx
@@ -176,6 +177,14 @@ def sphinx_needs_update(app: Sphinx, config: Config) -> None:
176177
sphinx-needs configuration
177178
"""
178179

180+
# Check sphinx-needs version to determine if schema is needed
181+
try:
182+
needs_version = Version(sphinx_needs.__version__)
183+
use_schema = needs_version >= Version("6.0.0")
184+
except ImportError:
185+
# If we can't determine version, assume older version
186+
use_schema = False
187+
179188
# Extra options
180189
# For details read
181190
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_extra_option
@@ -187,17 +196,25 @@ def sphinx_needs_update(app: Sphinx, config: Config) -> None:
187196
add_extra_option(app, "case_name")
188197
add_extra_option(app, "case_parameter")
189198
add_extra_option(app, "classname")
190-
add_extra_option(app, "time")
191-
192-
add_extra_option(app, "suites")
193-
add_extra_option(app, "cases")
194-
195-
add_extra_option(app, "passed")
196-
add_extra_option(app, "skipped")
197-
add_extra_option(app, "failed")
198-
add_extra_option(app, "errors")
199-
add_extra_option(app, "result") # used by test cases only
200-
199+
# Add schema parameter conditionally based on sphinx-needs version
200+
if use_schema:
201+
add_extra_option(app, "time", schema={"type": "string"})
202+
add_extra_option(app, "suites", schema={"type": "integer"})
203+
add_extra_option(app, "cases", schema={"type": "integer"})
204+
add_extra_option(app, "passed", schema={"type": "integer"})
205+
add_extra_option(app, "skipped", schema={"type": "integer"})
206+
add_extra_option(app, "failed", schema={"type": "integer"})
207+
add_extra_option(app, "errors", schema={"type": "integer"})
208+
add_extra_option(app, "result", schema={"type": "string"})
209+
else:
210+
add_extra_option(app, "time")
211+
add_extra_option(app, "suites")
212+
add_extra_option(app, "cases")
213+
add_extra_option(app, "passed")
214+
add_extra_option(app, "skipped")
215+
add_extra_option(app, "failed")
216+
add_extra_option(app, "errors")
217+
add_extra_option(app, "result")
201218
# Extra dynamic functions
202219
# For details about usage read
203220
# https://sphinx-needs.readthedocs.io/en/latest/api.html#sphinx_needs.api.configuration.add_dynamic_function

0 commit comments

Comments
 (0)