Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 910b325

Browse files
committed
Use a regular expression to handle the different output of integers on Unix and Windows.
1 parent 3ac1ab0 commit 910b325

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/matplotlib/tests/test_contour.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from matplotlib.testing.decorators import cleanup, image_comparison
44
from matplotlib import pyplot as plt
55

6+
import re
7+
68

79
@cleanup
810
def test_contour_shape_1d_valid():
@@ -97,14 +99,18 @@ def test_contour_shape_mismatch_4():
9799
ax.contour(b, g, z)
98100
except TypeError as exc:
99101
print exc.args[0]
100-
assert exc.args[0] == 'Shape of x does not match that of z: ' + \
101-
'found (9, 9) instead of (9, 10).'
102+
assert re.match(
103+
r'Shape of x does not match that of z: ' +
104+
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
105+
exc.args[0]) is not None
102106

103107
try:
104108
ax.contour(g, b, z)
105109
except TypeError as exc:
106-
assert exc.args[0] == 'Shape of y does not match that of z: ' + \
107-
'found (9, 9) instead of (9, 10).'
110+
assert re.match(
111+
r'Shape of y does not match that of z: ' +
112+
r'found \(9L?, 9L?\) instead of \(9L?, 10L?\)\.',
113+
exc.args[0]) is not None
108114

109115

110116
@cleanup
@@ -157,23 +163,23 @@ def test_given_colors_levels_and_extends():
157163
_, axes = plt.subplots(2, 4)
158164

159165
data = np.arange(12).reshape(3, 4)
160-
166+
161167
colors = ['red', 'yellow', 'pink', 'blue', 'black']
162168
levels = [2, 4, 8, 10]
163-
169+
164170
for i, ax in enumerate(axes.flatten()):
165171
plt.sca(ax)
166-
172+
167173
filled = i % 2 == 0.
168174
extend = ['neither', 'min', 'max', 'both'][i // 2]
169-
175+
170176
if filled:
171177
last_color = -1 if extend in ['min', 'max'] else None
172178
plt.contourf(data, colors=colors[:last_color], levels=levels, extend=extend)
173179
else:
174180
last_level = -1 if extend == 'both' else None
175181
plt.contour(data, colors=colors, levels=levels[:last_level], extend=extend)
176-
182+
177183
plt.colorbar()
178184

179185

0 commit comments

Comments
 (0)