Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed import to enable sphinx-needs 4.1 compatibility #83

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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: 23.1.0
hooks:
- id: black
args: [--line-length=120]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# The full version, including alpha/beta/rc tags
release = "1.0.2"

needs_id_regex = ".*"
needs_css = "dark.css"

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -111,6 +113,7 @@
other_options = {
"repo_url": "https://github.com/useblocks/sphinx-test-reports",
"repo_name": "sphinx-test-reports",
"font": False,
}
html_theme_options.update(other_options)
html_theme_options["features"].extend(["navigation.tabs", "navigation.tabs.sticky"])
Expand Down Expand Up @@ -195,6 +198,7 @@
linkcheck_ignore = [
r"http://localhost:\d+",
r"http://127.0.0.1:\d+",
r"https://fonts.googleapis.com",
]

linkcheck_request_headers = {
Expand Down
21 changes: 0 additions & 21 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,6 @@ In the last years, we have created additional information and extensions, which

:octicon:`book;1em;sd-text-primary` Technical Docs

.. grid-item-card::
:columns: 12 6 6 6
:link: https://useblocks.com/sphinx-needs-enterprise/
:img-top: /_static/sphinx-needs-enterprise-card.png
:class-card: border

Sphinx-Needs Enterprise
^^^^^^^^^^^^^^^^^^^^^^^
Synchronize Sphinx-Needs data with external, company internal systems like CodeBeamer, Jira or Azure Boards.

Provides scripts to baseline data and makes CI usage easier.
+++

.. button-link:: http://useblocks.com/sphinx-needs-enterprise/
:color: primary
:outline:
:align: center
:expand:

:octicon:`book;1em;sd-text-primary` Technical Docs

.. grid-item-card::
:columns: 12 6 6 6
:link: https://sphinx-test-reports.readthedocs.io/en/latest/
Expand Down
23 changes: 5 additions & 18 deletions sphinxcontrib/test_reports/directives/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,20 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
break

if suite is None:
raise TestReportInvalidOption(
f"Suite {suite_name} not found in test file {self.test_file}"
)
raise TestReportInvalidOption(f"Suite {suite_name} not found in test file {self.test_file}")

case = None

for case_obj in suite["testcases"]:
if (
case_obj["name"] == case_full_name # noqa: SIM114
and class_name is None # noqa: W503
):
if case_obj["name"] == case_full_name and class_name is None: # noqa: SIM114 # noqa: W503
case = case_obj
break

elif (
case_obj["classname"] == class_name # noqa: SIM114
and case_full_name is None # noqa: W503
):
elif case_obj["classname"] == class_name and case_full_name is None: # noqa: SIM114 # noqa: W503
case = case_obj
break

elif (
case_obj["name"] == case_full_name
and case_obj["classname"] == class_name # noqa: W503
):
elif case_obj["name"] == case_full_name and case_obj["classname"] == class_name: # noqa: W503
case = case_obj
break

Expand All @@ -105,9 +94,7 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
if case is None:
raise TestReportInvalidOption(
"Case {} with classname {} not found in test file {} "
"and testsuite {}".format(
case_full_name, class_name, self.test_file, suite_name
)
"and testsuite {}".format(case_full_name, class_name, self.test_file, suite_name)
)

result = case["result"]
Expand Down
32 changes: 23 additions & 9 deletions sphinxcontrib/test_reports/directives/test_common.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
"""
A Common directive, from which all other test directives inherit the shared functions.
"""

# fmt: off
import os
from importlib.metadata import version

from docutils.parsers.rst import Directive
from sphinx.util import logging
from sphinx_needs.api import make_hashed_id
from sphinx_needs.config import NeedsSphinxConfig

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

sn_major_version = int(version("sphinx-needs").split('.')[0])

if sn_major_version >= 4:
from sphinx_needs.api.need import _make_hashed_id
else:
from sphinx_needs.api import make_hashed_id


# fmt: on


Expand Down Expand Up @@ -59,11 +69,7 @@ def load_test_file(self):
self.test_file = os.path.join(root_path, self.test_file)
if not os.path.exists(self.test_file):
# raise TestReportFileInvalidException('Given test_file path invalid: {}'.format(self.test_file))
self.log.warning(
"Given test_file path invalid: {} in {} (Line: {})".format(
self.test_file, self.docname, self.lineno
)
)
self.log.warning(f"Given test_file path invalid: {self.test_file} in {self.docname} (Line: {self.lineno})")
return None

if self.test_file not in self.app.testreport_data.keys():
Expand All @@ -88,11 +94,19 @@ def prepare_basic_options(self):
self.test_content = "\n".join(self.content)
if self.name != "test-report":
self.need_type = self.app.tr_types[self.name][0]
if sn_major_version >= 4:
hashed_id = _make_hashed_id(
self.need_type,
self.test_name,
self.test_content,
NeedsSphinxConfig(self.app.config),
)
else: # Sphinx-Needs < 4
hashed_id = make_hashed_id(self.app, self.need_type, self.test_name, self.test_content)

self.test_id = self.options.get(
"id",
make_hashed_id(
self.app, self.need_type, self.test_name, self.test_content
),
hashed_id,
)
else:
self.test_id = self.options.get("id")
Expand Down
16 changes: 3 additions & 13 deletions sphinxcontrib/test_reports/directives/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ def run(self):
try:
results = json.load(fp_json)
except ValueError:
raise InvalidJsonFile(
"The given file {} is not a valid JSON".format(
json_path.split("/")[-1]
)
)
raise InvalidJsonFile("The given file {} is not a valid JSON".format(json_path.split("/")[-1]))

# check to see if environment is present in JSON or not
if self.req_env_list is not None:
Expand Down Expand Up @@ -118,9 +114,7 @@ def run(self):
# option check
for opt in self.data_option_list:
if opt not in temp_dict2[enviro]:
logger.warning(
f"option '{opt}' is not present in JSON file"
)
logger.warning(f"option '{opt}' is not present in JSON file")

del temp_dict

Expand All @@ -146,11 +140,7 @@ def run(self):
# option check
for opt in self.data_option_list:
if opt not in temp_dict2[enviro]:
logger.warning(
"option '{}' is not present in '{}' environment file".format(
opt, enviro
)
)
logger.warning(f"option '{opt}' is not present in '{enviro}' environment file")

del temp_dict

Expand Down
30 changes: 12 additions & 18 deletions sphinxcontrib/test_reports/directives/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ def run(self):
errors=errors,
)

if (
"auto_cases" in self.options.keys()
and "auto_suites" not in self.options.keys() # noqa W 503
):
if "auto_cases" in self.options.keys() and "auto_suites" not in self.options.keys(): # noqa W 503
raise TestReportIncompleteConfiguration(
"option auto_cases must be used together with "
"auto_suites for test-file directives."
"option auto_cases must be used together with " "auto_suites for test-file directives."
)

if "auto_suites" in self.options.keys():
Expand Down Expand Up @@ -123,18 +119,16 @@ def run(self):
options["links"] = options["links"] + ";" + self.test_id

arguments = [suite["name"]]
suite_directive = (
sphinxcontrib.test_reports.directives.test_suite.TestSuiteDirective(
self.app.config.tr_suite[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)
suite_directive = sphinxcontrib.test_reports.directives.test_suite.TestSuiteDirective(
self.app.config.tr_suite[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)

main_section += suite_directive.run()
Expand Down
16 changes: 4 additions & 12 deletions sphinxcontrib/test_reports/directives/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ def run(self):

if not os.path.isfile(template_path):
raise InvalidConfigurationError(
"could not find a template file with name {} in conf.py directory".format(
template_path
)
f"could not find a template file with name {template_path} in conf.py directory"
)

with open(
template_path, encoding=self.app.config.tr_import_encoding
) as template_file:
with open(template_path, encoding=self.app.config.tr_import_encoding) as template_file:
template = "".join(template_file.readlines())

if self.test_links is not None and len(self.test_links) > 0:
Expand All @@ -75,18 +71,14 @@ def run(self):
"file_type": self.app.config.tr_file[0],
"suite_need": self.app.config.tr_suite[1],
"case_need": self.app.config.tr_case[1],
"tags": ";".join([self.test_tags, self.test_id])
if len(self.test_tags) > 0
else self.test_id,
"tags": (";".join([self.test_tags, self.test_id]) if len(self.test_tags) > 0 else self.test_id),
"links_string": links_string,
"title": self.test_name,
"content": self.content,
"template_path": template_path,
}

template_ready = template.format(**template_data)
self.state_machine.insert_input(
template_ready.split("\n"), self.state_machine.document.attributes["source"]
)
self.state_machine.insert_input(template_ready.split("\n"), self.state_machine.document.attributes["source"])

return []
8 changes: 2 additions & 6 deletions sphinxcontrib/test_reports/directives/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def run(self):
skips=testsuite["skips"],
)
)
section += nodes.paragraph(
text="Time: {time}".format(time=testsuite["time"])
)
section += nodes.paragraph(text="Time: {time}".format(time=testsuite["time"]))

table = nodes.table()
section += table
Expand Down Expand Up @@ -92,9 +90,7 @@ def _create_testcase_row(self, testcase):

row = nodes.row(classes=["tr_" + testcase["result"]])
for index, cell in enumerate(row_cells):
entry = nodes.entry(
classes=["tr_" + testcase["result"], self.header[index]]
)
entry = nodes.entry(classes=["tr_" + testcase["result"], self.header[index]])
row += entry
entry += nodes.paragraph(text=cell, classes=["tr_" + testcase["result"]])
return row
Expand Down
52 changes: 22 additions & 30 deletions sphinxcontrib/test_reports/directives/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def run(self, nested=False, count=-1):
break

if suite is None:
raise TestReportInvalidOption(
f"Suite {suite_name} not found in test file {self.test_file}"
)
raise TestReportInvalidOption(f"Suite {suite_name} not found in test file {self.test_file}")

cases = suite["tests"]

Expand Down Expand Up @@ -120,18 +118,16 @@ def run(self, nested=False, count=-1):
options["links"] = options["links"] + ";" + self.test_id

arguments = [suite["name"]]
suite_directive = (
sphinxcontrib.test_reports.directives.test_suite.TestSuiteDirective(
self.app.config.tr_suite[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)
suite_directive = sphinxcontrib.test_reports.directives.test_suite.TestSuiteDirective(
self.app.config.tr_suite[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)

is_nested = len(suite_obj["testsuites"]) > 0
Expand All @@ -149,9 +145,7 @@ def run(self, nested=False, count=-1):
case_id = self.test_id
case_id += (
"_"
+ hashlib.sha1( # noqa: W503
case["classname"].encode("UTF-8") + case["name"].encode("UTF-8")
)
+ hashlib.sha1(case["classname"].encode("UTF-8") + case["name"].encode("UTF-8")) # noqa: W503
.hexdigest()
.upper()[: self.app.config.tr_case_id_length]
)
Expand All @@ -175,18 +169,16 @@ def run(self, nested=False, count=-1):
options["links"] = options["links"] + ";" + self.test_id

arguments = [case["name"]]
case_directive = (
sphinxcontrib.test_reports.directives.test_case.TestCaseDirective(
self.app.config.tr_case[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)
case_directive = sphinxcontrib.test_reports.directives.test_case.TestCaseDirective(
self.app.config.tr_case[0],
arguments,
options,
"",
self.lineno, # no content
self.content_offset,
self.block_text,
self.state,
self.state_machine,
)

is_nested = len(suite_obj["testsuite_nested"]) > 0 or nested
Expand Down
Loading