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

Use pathlib for file args to support Windows and Linux. #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions sphinxcontrib/test_reports/directives/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
# fmt: off
import os
import pathlib

from docutils.parsers.rst import Directive
from sphinx.util import logging
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 7 additions & 9 deletions sphinxcontrib/test_reports/directives/test_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# fmt: off
import os
import pathlib

from docutils import nodes
from docutils.parsers.rst import directives
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**Test file**: {file}
**Test file**: ``{file}``

**Template used**: {template_path}
**Template used**: ``{template_path}``

**Statistics**

Expand Down