Skip to content

Commit

Permalink
Tr encoding (useblocks#62)
Browse files Browse the repository at this point in the history
* [useblocks#60] test report encoding from config

* Updates pre-commit deps to be working with newest poetry version

* [useblocks#60] add missing changelog entry

* Updating linting

---------

Co-authored-by: Joerg Kreuzberger <[email protected]>
  • Loading branch information
danwos and kreuzberger authored Mar 10, 2023
1 parent 0316d13 commit ebe4680
Show file tree
Hide file tree
Showing 27 changed files with 722 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 120
extend-ignore = I # ignore all isort errors
extend-ignore = I
per-file-ignores =
sphinxcontrib/test_reports/__init__.py: F401
sphinxcontrib/test_reports/directives/__init__.py: F401
Expand Down
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
- flake8-isort
- pep8-naming

# ignore sim118 ("do not use dict.keys()") for clarity
args: [--max-line-length=120, --ignore=SIM118]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [-l 120,]
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
rev: v3.3.1
hooks:
- id: pyupgrade
args:
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changelog
:Released: under development

* Updated project documentation to use the Useblocks theme customization.
* Improvement: Template file encoding coud be configured. See :ref:`tr_import_encoding`.
`#60 <https://github.com/useblocks/sphinx-test-reports/issues/60>`_

1.0.2
-----
Expand Down
18 changes: 8 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@

# -- Path setup --------------------------------------------------------------

import datetime
import os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
import sys
import datetime
import os

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

from ub_theme.conf import html_theme_options
from ub_theme.conf import html_theme_options # noqa

# -- Project information -----------------------------------------------------

project = "sphinx-test-reports"
now = datetime.datetime.now()
copyright = 'team useblocks, 2017-{year}'.format(
year=now.year
)
copyright = f"team useblocks, 2017-{now.year}"
author = "team useblocks"

# The short X.Y version
Expand All @@ -49,7 +48,7 @@
"sphinxcontrib.test_reports",
"sphinxcontrib.plantuml",
"sphinx_design",
"sphinx_immaterial"
"sphinx_immaterial",
]

cwd = os.getcwd()
Expand All @@ -65,7 +64,7 @@


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates', 'ub_theme/templates']
templates_path = ["_templates", "ub_theme/templates"]
# 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 Expand Up @@ -108,7 +107,6 @@
html_logo = "_static/sphinx-test-reports-logo.svg"
html_favicon = "_static/sphinx-test-reports-logo.svg"
html_title = "Sphinx-Test-Reports"
html_theme_options = html_theme_options

other_options = {
"repo_url": "https://github.com/useblocks/sphinx-test-reports",
Expand Down
12 changes: 11 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,14 @@ Defines the length of the calculated ID for test cases.

This may be needed, if a junit-xml files contains many test cases.

Default: **5**
Default: **5**

.. _tr_import_encoding:

tr_import_encoding
__________________
.. versionadded:: 1.0.3

Defines the encoding for imported files, e.g. in custom templates.

Default: **utf8**
7 changes: 2 additions & 5 deletions docs/ub_theme/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
"icon": {
"repo": "fontawesome/brands/github",
},
"font": {
"code": "JetBrains Mono",
"text": "Urbanist"
},
"font": {"code": "JetBrains Mono", "text": "Urbanist"},
"globaltoc_collapse": True,
"features": [
"navigation.top",
"search.share",
"navigation.tracking",
"toc.follow",
"content.tabs.link"
"content.tabs.link",
],
"palette": {
"scheme": "slate",
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
requires = ["sphinx>=4.0", "lxml", "sphinx-needs>=1.0.1"]

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!
Expand Down
2 changes: 0 additions & 2 deletions sphinxcontrib/test_reports/directives/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def run(self, nested=False, suite_count=-1, case_count=-1):

suite = None
for suite_obj in self.results:

if nested: # nested testsuites
suite = self.results
break
Expand All @@ -73,7 +72,6 @@ def run(self, nested=False, suite_count=-1, case_count=-1):
case = None

for case_obj in suite["testcases"]:

if (
case_obj["name"] == case_full_name # noqa: SIM114
and class_name is None # noqa: W503
Expand Down
1 change: 0 additions & 1 deletion sphinxcontrib/test_reports/directives/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def run(self):
"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."
Expand Down
4 changes: 3 additions & 1 deletion sphinxcontrib/test_reports/directives/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def run(self):
)
)

with open(template_path) 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 Down
3 changes: 0 additions & 3 deletions sphinxcontrib/test_reports/directives/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def run(self, nested=False, count=-1):
# nested testsuite present, if testcases are present -> reached most inner testsuite
access_count = 0
if len(suite_obj["testcases"]) == 0:

for suite in suite_obj["testsuite_nested"]:

suite_id = self.test_id
suite_id += (
"_"
Expand Down Expand Up @@ -145,7 +143,6 @@ def run(self, nested=False, count=-1):

# suite has testcases
if "auto_cases" in self.options.keys() and len(suite_obj["testcases"]) > 0:

case_count = 0

for case in suite["testcases"]:
Expand Down
2 changes: 0 additions & 2 deletions sphinxcontrib/test_reports/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def safe_remove_file(filename, app):
hasattr(app.builder, "css_files")
and static_data_file in app.builder.css_files # noqa: W503
):

app.builder.css_files.remove(static_data_file)


Expand All @@ -91,7 +90,6 @@ def install_styles_static_files(app, env):
brown,
len(files_to_copy),
):

if not os.path.isabs(source_file_path):
source_file_path = os.path.join(
os.path.dirname(__file__), "css", source_file_path
Expand Down
4 changes: 0 additions & 4 deletions sphinxcontrib/test_reports/junitparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def parse(self):
"""

def parse_testcase(xml_object):

testcase = xml_object

tc_dict = {
Expand Down Expand Up @@ -83,7 +82,6 @@ def parse_testcase(xml_object):
return tc_dict

def parse_testsuite(xml_object):

testsuite = xml_object

tests = int(testsuite.attrib.get("tests", -1))
Expand Down Expand Up @@ -112,14 +110,12 @@ def parse_testsuite(xml_object):

# add nested testsuite objects to
if hasattr(testsuite, "testsuite"):

for ts in testsuite.testsuite:
# dict from inner parse
inner_testsuite = parse_testsuite(ts)
ts_dict["testsuite_nested"].append(inner_testsuite)

elif hasattr(testsuite, "testcase"):

for tc in testsuite.testcase:
new_testcase = parse_testcase(tc)
ts_dict["testcases"].append(new_testcase)
Expand Down
1 change: 1 addition & 0 deletions sphinxcontrib/test_reports/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def setup(app):

app.add_config_value("tr_suite_id_length", 3, "html")
app.add_config_value("tr_case_id_length", 5, "html")
app.add_config_value("tr_import_encoding", "utf8", "html")

# nodes
app.add_node(TestResults)
Expand Down
20 changes: 20 additions & 0 deletions tests/doc_test/custom_tr_koi8_template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = needstestdocs
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading

0 comments on commit ebe4680

Please sign in to comment.