5353
5454import os
5555import subprocess
56+
57+ # couple tests depend on ths
58+ try :
59+ import skimage
60+ except :
61+ skimage = None
62+
5663from test .helper import session
5764
5865import mathics .builtin .drawing .plot as plot
5966from 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,
6286classic = [
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
78102vectorized = [
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
86110both = [
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
102116path , _ = os .path .splitext (__file__ )
103117ref_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
157176def 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
169192if __name__ == "__main__" :
0 commit comments