Skip to content

Commit c381803

Browse files
Added better image comparison test
1 parent db63805 commit c381803

File tree

8 files changed

+63
-10
lines changed

8 files changed

+63
-10
lines changed
14.2 KB
Binary file not shown.
78.6 KB
Binary file not shown.
Binary file not shown.
14.2 KB
Binary file not shown.
13.8 KB
Binary file not shown.
42.8 KB
Binary file not shown.
14.2 KB
Binary file not shown.

fgivenx/test/test_plot.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,90 @@
33
from fgivenx.plot import plot, plot_lines
44
import matplotlib.pyplot as plt
55
import matplotlib
6+
from matplotlib.testing.decorators import image_comparison
67

78

8-
def test_plot():
9+
def gen_plot_data():
10+
numpy.random.seed(0)
911
nx = 100
1012
ny = 101
1113
x = numpy.linspace(0, 1, nx)
1214
y = numpy.linspace(0, 1, ny)
13-
z = numpy.random.rand(ny, nx)
15+
X, Y = numpy.meshgrid(x, y)
16+
z = numpy.exp(-((X-0.5)**2+(Y-0.5)**2)/0.01)
17+
return x, y, z
18+
19+
20+
@image_comparison(baseline_images=['plot'], extensions=['pdf'])
21+
def test_plot():
22+
x, y, z = gen_plot_data()
1423

1524
fig, ax = plt.subplots()
1625
cbar = plot(x, y, z, ax)
1726
assert type(cbar) is matplotlib.contour.QuadContourSet
1827

28+
29+
def test_plot_wrong_argument():
30+
x, y, z = gen_plot_data()
1931
with pytest.raises(TypeError):
2032
plot(x, y, z, wrong_argument=None)
2133

22-
cbar = plot(x, y, z)
23-
cbar = plot(x, y, z, smooth=1)
24-
cbar = plot(x, y, z, rasterize_contours=True)
25-
cbar = plot(x, y, z, lines=False)
2634

35+
@image_comparison(baseline_images=['plot_no_ax'], extensions=['pdf'])
36+
def test_plot_no_ax():
37+
plt.subplots()
38+
x, y, z = gen_plot_data()
39+
plot(x, y, z)
2740

28-
def test_plot_lines():
41+
42+
@image_comparison(baseline_images=['plot_smooth'], extensions=['pdf'])
43+
def test_plot_smooth():
44+
plt.subplots()
45+
x, y, z = gen_plot_data()
46+
plot(x, y, z, smooth=1)
47+
48+
49+
@image_comparison(baseline_images=['plot_rasterize'], extensions=['pdf'])
50+
def test_plot_rasterize():
51+
plt.subplots()
52+
x, y, z = gen_plot_data()
53+
plot(x, y, z, rasterize_contours=True)
54+
55+
56+
@image_comparison(baseline_images=['plot_nolines'], extensions=['pdf'])
57+
def test_plot_nolines():
58+
plt.subplots()
59+
x, y, z = gen_plot_data()
60+
plot(x, y, z, lines=False)
61+
62+
63+
def gen_line_data():
64+
numpy.random.seed(0)
2965
nx = 100
3066
nsamps = 150
3167
x = numpy.linspace(0, 1, nx)
32-
m = numpy.random.normal(nsamps)
33-
c = numpy.random.normal(nsamps)
68+
m = numpy.random.normal(size=nsamps)
69+
c = numpy.random.normal(size=nsamps)
3470
fsamps = numpy.outer(x, m) + c
71+
return x, fsamps
72+
73+
74+
@image_comparison(baseline_images=['plot_lines'], extensions=['pdf'])
75+
def test_plot_lines():
76+
x, fsamps = gen_line_data()
3577
fig, ax = plt.subplots()
3678
plot_lines(x, fsamps, ax)
3779

80+
81+
@image_comparison(baseline_images=['plot_lines_no_ax'], extensions=['pdf'])
82+
def test_plot_lines_no_ax():
83+
x, fsamps = gen_line_data()
84+
plt.subplots()
3885
plot_lines(x, fsamps)
39-
plot_lines(x, fsamps, downsample=200)
86+
87+
88+
@image_comparison(baseline_images=['plot_lines_downsample'], extensions=['pdf'])
89+
def test_plot_lines_no_ax():
90+
x, fsamps = gen_line_data()
91+
plt.subplots()
92+
plot_lines(x, fsamps, downsample=50)

0 commit comments

Comments
 (0)