Skip to content

Commit e107724

Browse files
committed
Fix code style issues
1 parent 5c4b759 commit e107724

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

pytest_mpl/plugin.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _download_file(baseline, filename):
6363
try:
6464
u = urlopen(base_url + filename)
6565
content = u.read()
66-
except Exception as exc:
66+
except Exception:
6767
warnings.warn('Downloading {0} failed'.format(base_url + filename))
6868
else:
6969
break
@@ -104,7 +104,9 @@ def pytest_addoption(parser):
104104

105105
def pytest_configure(config):
106106

107-
config.addinivalue_line('markers', "mpl_image_compare: Compares matplotlib figures against a baseline image")
107+
config.addinivalue_line('markers',
108+
"mpl_image_compare: Compares matplotlib figures "
109+
"against a baseline image")
108110

109111
if config.getoption("--mpl") or config.getoption("--mpl-generate-path") is not None:
110112

@@ -269,21 +271,26 @@ def item_function_wrapper(*args, **kwargs):
269271
if baseline_remote:
270272
baseline_image_ref = _download_file(baseline_dir, filename)
271273
else:
272-
baseline_image_ref = os.path.abspath(os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir, filename))
274+
baseline_image_ref = os.path.abspath(os.path.join(
275+
os.path.dirname(item.fspath.strpath), baseline_dir, filename))
273276

274277
if not os.path.exists(baseline_image_ref):
275278
pytest.fail("Image file not found for comparison test in: "
276279
"\n\t{baseline_dir}"
277280
"\n(This is expected for new tests.)\nGenerated Image: "
278-
"\n\t{test}".format(baseline_dir=baseline_dir, test=test_image), pytrace=False)
281+
"\n\t{test}".format(baseline_dir=baseline_dir,
282+
test=test_image),
283+
pytrace=False)
279284

280285
# distutils may put the baseline images in non-accessible places,
281286
# copy to our tmpdir to be sure to keep them in case of failure
282-
baseline_image = os.path.abspath(os.path.join(result_dir, 'baseline-' + filename))
287+
baseline_image = os.path.abspath(os.path.join(result_dir,
288+
'baseline-' + filename))
283289
shutil.copyfile(baseline_image_ref, baseline_image)
284290

285-
# Compare image size ourselves since the Matplotlib exception is a bit cryptic in this case
286-
# and doesn't show the filenames
291+
# Compare image size ourselves since the Matplotlib
292+
# exception is a bit cryptic in this case and doesn't show
293+
# the filenames
287294
expected_shape = Image.open(baseline_image).size
288295
actual_shape = Image.open(test_image).size
289296
if expected_shape != actual_shape:
@@ -305,7 +312,8 @@ def item_function_wrapper(*args, **kwargs):
305312
if not os.path.exists(self.generate_dir):
306313
os.makedirs(self.generate_dir)
307314

308-
fig.savefig(os.path.abspath(os.path.join(self.generate_dir, filename)), **savefig_kwargs)
315+
fig.savefig(os.path.abspath(os.path.join(self.generate_dir, filename)),
316+
**savefig_kwargs)
309317
close_mpl_figure(fig)
310318
pytest.skip("Skipping test, since generating data")
311319

@@ -331,8 +339,6 @@ def pytest_runtest_setup(self, item):
331339
if compare is None:
332340
return
333341

334-
import matplotlib.pyplot as plt
335-
336342
original = item.function
337343

338344
@wraps(item.function)

tests/test_pytest_mpl.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_dpi():
6767
ax.plot([1, 2, 3])
6868
return fig
6969

70+
7071
TEST_FAILING = """
7172
import pytest
7273
import matplotlib.pyplot as plt
@@ -113,14 +114,16 @@ def test_output_dir(tmpdir):
113114

114115
# When we run the test, we should get output images where we specify
115116
output_dir = tmpdir.join('test_output_dir').strpath
116-
code = subprocess.call('{0} -m pytest --mpl-results-path={1} --mpl {2}'.format(sys.executable, output_dir, test_file),
117+
code = subprocess.call('{0} -m pytest --mpl-results-path={1} --mpl {2}'
118+
.format(sys.executable, output_dir, test_file),
117119
shell=True)
118120

119121
assert code != 0
120122
assert os.path.exists(output_dir)
121123

122124
# Listdir() is to get the random name that the output for the one test is written into
123-
assert os.path.exists(os.path.join(output_dir, os.listdir(output_dir)[0], 'test_output_dir.png'))
125+
assert os.path.exists(os.path.join(output_dir, os.listdir(output_dir)[0],
126+
'test_output_dir.png'))
124127

125128

126129
TEST_GENERATE = """
@@ -156,7 +159,8 @@ def test_generate(tmpdir):
156159
assert b'Image file not found for comparison test' in p.stdout.read()
157160

158161
# If we do generate, the test should succeed and a new file will appear
159-
code = subprocess.call('{0} -m pytest --mpl-generate-path={1} {2}'.format(sys.executable, gen_dir, test_file), shell=True)
162+
code = subprocess.call('{0} -m pytest --mpl-generate-path={1} {2}'
163+
.format(sys.executable, gen_dir, test_file), shell=True)
160164
assert code == 0
161165
assert os.path.exists(os.path.join(gen_dir, 'test_gen.png'))
162166

@@ -173,7 +177,8 @@ def test_nofigure():
173177
pass
174178

175179

176-
@pytest.mark.skipif(MPL_LT_2, reason="the fivethirtyeight style is only available in Matplotlib 2.0 and later")
180+
@pytest.mark.skipif(MPL_LT_2, reason="the fivethirtyeight style is only available "
181+
"in Matplotlib 2.0 and later")
177182
@pytest.mark.mpl_image_compare(baseline_dir=baseline_dir_local,
178183
style='fivethirtyeight')
179184
def test_base_style():
@@ -198,7 +203,7 @@ def test_remove_text():
198203
def test_parametrized(s):
199204
fig = plt.figure()
200205
ax = fig.add_subplot(1, 1, 1)
201-
ax.scatter([1,3,4,3,2],[1,4,3,3,1], s=s)
206+
ax.scatter([1, 3, 4, 3, 2], [1, 4, 3, 3, 1], s=s)
202207
return fig
203208

204209

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ requires =
77
pip >= 19.3.1
88

99
[testenv]
10-
passenv =
11-
DISPLAY
10+
passenv = DISPLAY
1211
changedir = .tmp/{envname}
1312
description = run tests
1413
deps =
@@ -31,8 +30,9 @@ commands =
3130

3231
[testenv:codestyle]
3332
skip_install = true
33+
changedir = .
3434
description = check code style, e.g. with flake8
3535
deps = flake8
3636
commands =
37-
flake8 pytest_mpl tests --count
37+
flake8 pytest_mpl tests --count --max-line-length=100
3838
python setup.py check --restructuredtext

0 commit comments

Comments
 (0)