diff --git a/sphinxcontrib/test_reports/directives/test_common.py b/sphinxcontrib/test_reports/directives/test_common.py index 9f5e9c9..de0f046 100644 --- a/sphinxcontrib/test_reports/directives/test_common.py +++ b/sphinxcontrib/test_reports/directives/test_common.py @@ -3,6 +3,7 @@ """ # fmt: off import os +import pathlib from docutils.parsers.rst import Directive from sphinx.util import logging @@ -52,10 +53,12 @@ def load_test_file(self): if self.test_file is None: raise TestReportFileNotSetException("Option test_file must be set.") - root_path = self.app.config.tr_rootdir - if not os.path.isabs(self.test_file): - self.test_file = os.path.join(root_path, self.test_file) - if not os.path.exists(self.test_file): + test_path = pathlib.Path(self.test_file) + if not test_path.is_absolute(): + root_path = pathlib.Path(self.app.config.tr_rootdir) + test_path = root_path / test_path + self.test_file = str(test_path) + if not test_path.exists(): # raise TestReportFileInvalidException('Given test_file path invalid: {}'.format(self.test_file)) self.log.warning( "Given test_file path invalid: {} in {} (Line: {})".format( diff --git a/sphinxcontrib/test_reports/directives/test_report.py b/sphinxcontrib/test_reports/directives/test_report.py index e2622ec..a1eb856 100644 --- a/sphinxcontrib/test_reports/directives/test_report.py +++ b/sphinxcontrib/test_reports/directives/test_report.py @@ -1,5 +1,6 @@ # fmt: off import os +import pathlib from docutils import nodes from docutils.parsers.rst import directives @@ -41,24 +42,21 @@ def run(self): self.load_test_file() # if user provides a custom template, use it - tr_template = self.app.config.tr_report_template + tr_template = pathlib.Path(self.app.config.tr_report_template) - template_path = "" - - if os.path.isabs(tr_template): + if tr_template.is_absolute(): template_path = tr_template - else: - template_path = os.path.join(self.app.confdir, os.path.relpath(tr_template)) + template_path = pathlib.Path(self.app.confdir) / tr_template - if not os.path.isfile(template_path): + if not template_path.is_file(): raise InvalidConfigurationError( "could not find a template file with name {} in conf.py directory".format( template_path ) ) - with open(template_path) as template_file: + with template_path.open() as template_file: template = "".join(template_file.readlines()) if self.test_links is not None and len(self.test_links) > 0: @@ -78,7 +76,7 @@ def run(self): "links_string": links_string, "title": self.test_name, "content": self.content, - "template_path": template_path, + "template_path": str(template_path), } template_ready = template.format(**template_data) diff --git a/sphinxcontrib/test_reports/directives/test_report_template.txt b/sphinxcontrib/test_reports/directives/test_report_template.txt index ec19c3c..a5228aa 100644 --- a/sphinxcontrib/test_reports/directives/test_report_template.txt +++ b/sphinxcontrib/test_reports/directives/test_report_template.txt @@ -1,6 +1,6 @@ -**Test file**: {file} +**Test file**: ``{file}`` -**Template used**: {template_path} +**Template used**: ``{template_path}`` **Statistics**