Skip to content

Commit 560de01

Browse files
committed
put two noise tests in one file
1 parent 261a876 commit 560de01

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

test/helpers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from matplotlib import pyplot as plt
1111

1212

13-
def assert_phash(fig, reference_phash):
13+
def compute_phash(fig):
1414
# convert to tikz file
1515
_, tmp_base = tempfile.mkstemp()
1616
tikz_file = tmp_base + '_tikz.tex'
@@ -82,7 +82,15 @@ def assert_phash(fig, reference_phash):
8282
png_file = tmp_base + '-1.png'
8383

8484
# compute the phash of the PNG
85-
phash = imagehash.phash(Image.open(png_file)).__str__()
85+
return (
86+
imagehash.phash(Image.open(png_file)).__str__(), png_file, pdf_file,
87+
tex_out, ptp_out, mpl_reference, tikz_file
88+
)
89+
90+
91+
def assert_phash(fig, reference_phash):
92+
phash, png_file, pdf_file, tex_out, ptp_out, mpl_reference, tikz_file =\
93+
compute_phash(fig)
8694

8795
if reference_phash != phash:
8896
# Compute the Hamming distance between the two 64-bit numbers

test/test_noise.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#
33
import helpers
44

5+
from numpy.random import randn
6+
from matplotlib import pyplot as plt
7+
import numpy as np
8+
import pytest
59

6-
def plot():
7-
from numpy.random import randn
8-
from matplotlib import pyplot as plt
9-
import numpy as np
1010

11+
def plot1():
1112
# Make plot with vertical (default) colorbar
1213
fig = plt.figure()
1314
ax = fig.add_subplot(111)
@@ -23,9 +24,39 @@ def plot():
2324
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
2425
# vertically oriented colorbar
2526
cbar.ax.set_yticklabels(['< -1', '0', '> 1'])
27+
return fig
28+
29+
30+
def plot2():
31+
# Make plot with horizontal colorbar
32+
fig = plt.figure()
33+
ax = fig.add_subplot(111)
2634

35+
np.random.seed(123)
36+
data = np.clip(np.random.randn(250, 250), -1, 1)
37+
38+
cax = ax.imshow(data, interpolation='nearest')
39+
ax.set_title('Gaussian noise with horizontal colorbar')
40+
41+
cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')
42+
# horizontal colorbar
43+
cbar.ax.set_xticklabels(['Low', 'Medium', 'High'])
2744
return fig
2845

2946

30-
def test():
31-
helpers.assert_phash(plot(), 'f55a0bb503fd0354')
47+
@pytest.mark.parametrize(
48+
'plot, phash', [
49+
(plot1, 'fda50b5a0b5a835a'),
50+
(plot2, '7f56a913a9816ba1'),
51+
]
52+
)
53+
def test(plot, phash):
54+
helpers.assert_phash(plot(), phash)
55+
return
56+
57+
58+
if __name__ == '__main__':
59+
# plot1()
60+
# plt.show()
61+
phash, _, _, _, _, _, _ = helpers.compute_phash(plot2())
62+
print(phash)

test/test_noise2.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)