Skip to content

Commit

Permalink
Replace colon with hyphen in plot filenames
Browse files Browse the repository at this point in the history
Windows does not allow colons in filenames. Rather than have
different behavior on different platforms, we unconditionally
replace colons with hyphens when generating the plot filename.
This is the only place that we modify the nodeid.

Fixes #17.
  • Loading branch information
tbekolay committed Oct 14, 2019
1 parent 4b67080 commit 1c9a348
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pytest_plt/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ def dirname(self, _dirname):

def get_filename(self, ext=""):
# Flatten filestructure (replace folders with dots in filename).
# The nodeid should only contain /, but to be safe we also replace \\
filename = self.nodeid.replace("/", ".").replace("\\", ".")
# The nodeid should only contain /, but to be safe we also replace \\.
# We also replace : with - because Windows does not allow colons in filenames.
filename = self.nodeid.replace("/", ".").replace("\\", ".").replace(":", "-")

# Drop parts of filename matching the given regexs
for pattern in self.filename_drop:
Expand Down
10 changes: 5 additions & 5 deletions pytest_plt/tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def assert_all_passed(result):
"""
outcomes = result.parseoutcomes()
for outcome in outcomes:
if outcome not in ("passed", "seconds"):
if outcome not in ("passed", "seconds", "warnings"):
assert outcomes[outcome] == 0
return outcomes.get("passed", 0)

Expand Down Expand Up @@ -138,7 +138,7 @@ def test_filename_drop_prefix(testdir, prefix):
for prefix_part, test_part in zip(prefix_parts, test_parts):
assert prefix_part == test_part

plot_name = ".".join(test_parts[len(prefix_parts) :])
plot_name = ".".join(test_parts[len(prefix_parts) :]).replace(":", "-")
assert plot in ["plots/%s.%s" % (plot_name, ext) for ext in ("pdf", "png")]
assert os.path.exists(plot)

Expand All @@ -156,7 +156,7 @@ def test_filename_drop_within(testdir):
"plt_filename_drop =",
r" package\.",
# Matches the `test_` of the function name only
r" (?<=::)test_",
r" (?<=--)test_",
]
)
)
Expand All @@ -170,8 +170,8 @@ def test_filename_drop_within(testdir):
assert 0 < len(saved) <= n_passed
for _, plot in saved:
assert plot.startswith("plots/tests.test_")
colon_ix = plot.index("::")
assert not plot[colon_ix:].startswith("::test_")
colon_ix = plot.index("--")
assert not plot[colon_ix:].startswith("--test_")


def test_plots_dir(testdir):
Expand Down

0 comments on commit 1c9a348

Please sign in to comment.