Skip to content

Commit 4803c22

Browse files
committed
Fix some insane pathify
1 parent 9e7c62e commit 4803c22

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pytest_mpl/plugin.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ def pathify(path):
108108
Remove non-path safe characters.
109109
"""
110110
path = Path(path)
111-
ext = path.suffix
112-
path = str(path).split(ext)[0]
111+
ext = ''
112+
if path.suffixes[-1] == '.png':
113+
ext = '.png'
114+
path = str(path).split(ext)[0]
115+
path = str(path)
113116
path = path.replace('[', '_').replace(']', '_')
114117
path = path.replace('/', '_')
115118
if path.endswith('_'):
116-
path = path[:-2]
119+
path = path[:-1]
117120
return Path(path + ext)
118121

119122

@@ -296,7 +299,8 @@ def generate_filename(self, item):
296299
if filename is None:
297300
filename = item.name + '.png'
298301

299-
return str(pathify(filename))
302+
filename = str(pathify(filename))
303+
return filename
300304

301305
def generate_test_name(self, item):
302306
"""
@@ -308,7 +312,7 @@ def make_test_results_dir(self, item):
308312
"""
309313
Generate the directory to put the results in.
310314
"""
311-
test_name = self.generate_test_name(item)
315+
test_name = pathify(self.generate_test_name(item))
312316
results_dir = self.results_dir / test_name
313317
results_dir.mkdir(exist_ok=True, parents=True)
314318
return results_dir

tests/test_pytest_mpl.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_parametrized(s):
240240
return fig
241241

242242

243-
class TestClassWithSetup(object):
243+
class TestClassWithSetup:
244244

245245
# Regression test for a bug that occurred when using setup_method
246246

@@ -291,6 +291,15 @@ def test_hash_fails(tmpdir):
291291
# We didn't specify a baseline dir so we shouldn't attempt to find one
292292
assert "Unable to find baseline image" not in output, output
293293

294+
# Check that the summary path is printed and that it exists.
295+
output = assert_pytest_fails_with(['--mpl', test_file, '--mpl-generate-summary'],
296+
"doesn't match hash FAIL in library")
297+
# We didn't specify a baseline dir so we shouldn't attempt to find one
298+
print_message = "A summary of the failed tests can be found at:"
299+
assert print_message in output, output
300+
printed_path = Path(output.split(print_message)[1].strip())
301+
assert printed_path.exists()
302+
294303
# If we don't use --mpl option, the test should succeed
295304
code = call_pytest([test_file])
296305
assert code == 0
@@ -299,7 +308,8 @@ def test_hash_fails(tmpdir):
299308
TEST_FAILING_HYBRID = f"""
300309
import pytest
301310
import matplotlib.pyplot as plt
302-
@pytest.mark.mpl_image_compare(hash_library="{fail_hash_library}")
311+
@pytest.mark.mpl_image_compare(hash_library="{fail_hash_library}",
312+
tolerance=2)
303313
def test_hash_fail_hybrid():
304314
fig = plt.figure()
305315
ax = fig.add_subplot(1,1,1)

0 commit comments

Comments
 (0)