Skip to content

Commit 7eeb838

Browse files
committed
Better error handling for messages
1 parent 7e74186 commit 7eeb838

12 files changed

+1131
-115
lines changed

test/builtin/drawing/test_plot_detail.py

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,51 +53,65 @@
5353

5454
import os
5555
import subprocess
56+
57+
# couple tests depend on ths
58+
try:
59+
import skimage
60+
except:
61+
skimage = None
62+
5663
from test.helper import session
5764

5865
import mathics.builtin.drawing.plot as plot
5966
from mathics.core.util import print_expression_tree
6067

68+
# common plotting options for 2d plots to test with and without
69+
opt2 = """
70+
AspectRatio -> 2,
71+
Axes -> False,
72+
Frame -> False,
73+
Mesh -> Full,
74+
PlotPoints -> 10
75+
"""
76+
77+
# 3d plots add these options
78+
opt3 = (
79+
opt2
80+
+ """,
81+
BoxRatios -> {1, 2, 3}
82+
"""
83+
)
84+
6185
# non-vectorized available, vectorized not available,
6286
classic = [
63-
("barchart", "BarChart[{3,5,2,7}]"),
64-
("discreteplot", "DiscretePlot[n^2,{n,1,10}]"),
65-
("histogram", "Histogram[{1,1,1,5,5,7,8,8,8}]"),
66-
("listlineplot", "ListLinePlot[{1,4,2,5,3}]"),
67-
("listplot", "ListPlot[{1,4,2,5,3}]"),
68-
("liststepplot", "ListStepPlot[{1,4,2,5,3}]"),
69-
# ("manipulate", "Manipulate[Plot[a x,{x,0,1}],{a,0,5}]"),
70-
("numberlineplot", "NumberLinePlot[{1,3,4}]"),
71-
("parametricplot", "ParametricPlot[{t,2 t},{t,0,2}]"),
72-
("piechart", "PieChart[{3,2,5}]"),
73-
("plot", "Plot[x, {x, 0, 1}]"),
74-
("polarplot", "PolarPlot[3 θ,{θ,0,2}]"),
87+
("barchart", "BarChart[{3,5,2,7}]", opt2, True),
88+
("discreteplot", "DiscretePlot[n^2,{n,1,10}]", opt2, True),
89+
("histogram", "Histogram[{1,1,1,5,5,7,8,8,8}]", opt2, True),
90+
("listlineplot", "ListLinePlot[{1,4,2,5,3}]", opt2, True),
91+
("listplot", "ListPlot[{1,4,2,5,3}]", opt2, True),
92+
("liststepplot", "ListStepPlot[{1,4,2,5,3}]", opt2, True),
93+
# ("manipulate", "Manipulate[Plot[a x,{x,0,1}],{a,0,5}]", opt2, True),
94+
("numberlineplot", "NumberLinePlot[{1,3,4}]", opt2, True),
95+
("parametricplot", "ParametricPlot[{t,2 t},{t,0,2}]", opt2, True),
96+
("piechart", "PieChart[{3,2,5}]", opt2, True),
97+
("plot", "Plot[x, {x, 0, 1}]", opt2, True),
98+
("polarplot", "PolarPlot[3 θ,{θ,0,2}]", opt2, True),
7599
]
76100

77101
# vectorized available, non-vectorized not available
78102
vectorized = [
79-
("complexplot", "ComplexPlot[Exp[I z],{z,-2-2 I,2+2 I}]"),
80-
("complexplot3d", "ComplexPlot3D[Exp[I z],{z,-2-2 I,2+2 I}]"),
81-
("contourplot-1", "ContourPlot[x^2-y^2,{x,-2,2},{y,-2,2}]"),
82-
("contourplot-2", "ContourPlot[x^2+y^2==1,{x,-2,2},{y,-2,2}]"),
103+
("complexplot", "ComplexPlot[Exp[I z],{z,-2-2 I,2+2 I}]", opt2, True),
104+
("complexplot3d", "ComplexPlot3D[Exp[I z],{z,-2-2 I,2+2 I}]", opt3, True),
105+
("contourplot-1", "ContourPlot[x^2-y^2,{x,-2,2},{y,-2,2}]", opt2, True),
106+
("contourplot-2", "ContourPlot[x^2+y^2==1,{x,-2,2},{y,-2,2}]", opt2, True),
83107
]
84108

85109
# both vectorized and non-vectorized available
86110
both = [
87-
("densityplot", "DensityPlot[x y,{x,-2,2},{y,-2,2}]"),
88-
("plot3d", "Plot3D[x y,{x,-2,2},{y,-2,2}]"),
111+
("densityplot", "DensityPlot[x y,{x,-2,2},{y,-2,2}]", opt2, True),
112+
("plot3d", "Plot3D[x y,{x,-2,2},{y,-2,2}]", opt3, True),
89113
]
90114

91-
# common plotting options to test with and without
92-
opts = """
93-
AspectRatio -> 2,
94-
Axes -> False,
95-
BoxRatios -> {1, 2, 3},
96-
Frame -> False,
97-
Mesh -> Full,
98-
PlotPoints -> 10
99-
"""
100-
101115
# compute reference dir, which is this file minus .py plus _ref
102116
path, _ = os.path.splitext(__file__)
103117
ref_dir = path + "_ref"
@@ -117,7 +131,7 @@ def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
117131
# whether default or with-options test
118132
if opt:
119133
name += "-opt"
120-
str_expr = f"{str_expr[:-1]}, {opts}]"
134+
str_expr = f"{str_expr[:-1]}, {opt}]"
121135
else:
122136
name += "-def"
123137

@@ -127,6 +141,11 @@ def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
127141
# evaluate the expression to be tested
128142
expr = session.parse(str_expr)
129143
act_expr = expr.evaluate(session.evaluation)
144+
if len(session.evaluation.out):
145+
print("=== messages:")
146+
for message in session.evaluation.out:
147+
print(message.text)
148+
assert not session.evaluation.out, "no output messages expected"
130149

131150
# write the results to act_fn in act_dir
132151
act_fn = os.path.join(act_dir, f"{name}.txt")
@@ -156,14 +175,18 @@ def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
156175

157176
def test_all(act_dir="/tmp", opt=None):
158177
# run twice, once without and once with options
159-
for opt in [False, True]:
178+
for use_opt in [False, True]:
160179
# run classic tests
161-
for name, str_expr in classic + both:
162-
one_test(name, str_expr, False, opt, act_dir)
180+
for name, str_expr, opt, cond in classic + both:
181+
if cond:
182+
opt = opt if use_opt else None
183+
one_test(name, str_expr, False, opt, act_dir)
163184

164185
# run vectorized tests
165-
for name, str_expr in vectorized + both:
166-
one_test(name, str_expr, True, opt, act_dir)
186+
for name, str_expr, opt, cond in vectorized + both:
187+
if cond:
188+
opt = opt if use_opt else None
189+
one_test(name, str_expr, True, opt, act_dir)
167190

168191

169192
if __name__ == "__main__":

test/builtin/drawing/test_plot_detail_ref/barchart-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ System`Graphics
109109
System`Rule
110110
System`BaselinePosition
111111
System`Automatic
112-
System`Rule
113-
System`BoxRatios
114-
System`List
115-
System`Integer 1
116-
System`Integer 2
117-
System`Integer 3
118112
System`Rule
119113
System`ChartLabels
120114
System`None

test/builtin/drawing/test_plot_detail_ref/discreteplot-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ System`DiscretePlot
1313
System`Rule
1414
System`Axes
1515
System`False
16-
System`Rule
17-
System`BoxRatios
18-
System`List
19-
System`Integer 1
20-
System`Integer 2
21-
System`Integer 3
2216
System`Rule
2317
System`Frame
2418
System`False

test/builtin/drawing/test_plot_detail_ref/histogram-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ System`Graphics
136136
System`Rule
137137
System`BaselinePosition
138138
System`Automatic
139-
System`Rule
140-
System`BoxRatios
141-
System`List
142-
System`Integer 1
143-
System`Integer 2
144-
System`Integer 3
145139
System`Rule
146140
System`ContentSelectable
147141
System`Automatic

test/builtin/drawing/test_plot_detail_ref/listlineplot-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ System`Graphics
4848
System`Rule
4949
System`BaselinePosition
5050
System`Automatic
51-
System`Rule
52-
System`BoxRatios
53-
System`List
54-
System`Integer 1
55-
System`Integer 2
56-
System`Integer 3
5751
System`Rule
5852
System`ContentSelectable
5953
System`Automatic

test/builtin/drawing/test_plot_detail_ref/listplot-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ System`Graphics
4848
System`Rule
4949
System`BaselinePosition
5050
System`Automatic
51-
System`Rule
52-
System`BoxRatios
53-
System`List
54-
System`Integer 1
55-
System`Integer 2
56-
System`Integer 3
5751
System`Rule
5852
System`ContentSelectable
5953
System`Automatic

test/builtin/drawing/test_plot_detail_ref/liststepplot-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ System`Graphics
7575
System`Rule
7676
System`BaselinePosition
7777
System`Automatic
78-
System`Rule
79-
System`BoxRatios
80-
System`List
81-
System`Integer 1
82-
System`Integer 2
83-
System`Integer 3
8478
System`Rule
8579
System`ContentSelectable
8680
System`Automatic

test/builtin/drawing/test_plot_detail_ref/numberlineplot-cls-opt.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ System`Graphics
4242
System`Rule
4343
System`BaselinePosition
4444
System`Automatic
45-
System`Rule
46-
System`BoxRatios
47-
System`List
48-
System`Integer 1
49-
System`Integer 2
50-
System`Integer 3
5145
System`Rule
5246
System`ContentSelectable
5347
System`Automatic

0 commit comments

Comments
 (0)