1313from plotpy .builder import make
1414
1515
16- def plot_qtbot_curve (qtbot , curve ):
17- """Plot * curve* in a dialog managed by *qtbot* """
18- win = make .dialog (type = "curve" )
16+ def show_item (qtbot , item , type = " curve" ):
17+ """Plot curve in a dialog"""
18+ win = make .dialog (type = type )
1919 plot = win .manager .get_plot ()
20- plot .add_item (curve )
21- qtbot .addWidget (win )
20+ plot .add_item (item )
2221 win .show ()
2322 qtbot .keyClick (win , Qt .Key_Enter )
2423
2524
2625_COLOR_TO_HEX = {"red" : "#ff0000" , "blue" : "#0000ff" }
2726
2827
29- @pytest .mark .parametrize ("shade" , [0 , 0.4 , 1.0 ])
30- @pytest .mark .parametrize ("curvestyle" , ["Lines" , "Sticks" , "Steps" , "Dots" , "NoCurve" ])
31- @pytest .mark .parametrize ("baseline" , [0.0 , 1.0 ])
32- def test_builder_curve_curve_params (qtbot , shade , curvestyle , baseline ):
33- """Test curve parameters of curve() method"""
34-
28+ def _make_curve_style (shade , curvestyle , baseline ):
29+ """Make curve with curve style parameters"""
3530 x = np .linspace (- 10 , 10 , 200 )
3631 y = np .sin (x )
3732 curve = make .curve (x , y , shade = shade , curvestyle = curvestyle , baseline = baseline )
38-
3933 assert curve .baseline () == baseline
4034 brush = curve .brush ()
4135 assert brush .color ().alphaF () == pytest .approx (shade )
4236 assert curve .style () == getattr (QwtPlotCurve , curvestyle )
43- plot_qtbot_curve ( qtbot , curve )
37+ return curve
4438
4539
46- @pytest .mark .parametrize ("color" , ["red" , "blue" ])
40+ @pytest .mark .parametrize ("shade" , [0 ])
41+ @pytest .mark .parametrize ("curvestyle" , ["Lines" , "Sticks" , "Steps" , "Dots" , "NoCurve" ])
42+ @pytest .mark .parametrize ("baseline" , [0.0 ])
43+ def test_builder_curve_curve_style (qtbot , shade , curvestyle , baseline ):
44+ """Test curve parameters of curve() method"""
45+ curve = _make_curve_style (shade , curvestyle , baseline )
46+ show_item (qtbot , curve , "curve" )
47+
48+
49+ @pytest .mark .parametrize ("shade" , [0 , 0.4 , 1.0 ])
50+ @pytest .mark .parametrize ("curvestyle" , ["Lines" ])
51+ @pytest .mark .parametrize ("baseline" , [0.0 , 1.0 ])
52+ def test_builder_curve_curve_shade_baseline (qtbot , shade , curvestyle , baseline ):
53+ """Test curve parameters of curve() method"""
54+ curve = _make_curve_style (shade , curvestyle , baseline )
55+ show_item (qtbot , curve , "curve" )
56+
57+
58+ def _make_curve_linestyle (color , linestyle , linewidth ):
59+ """Make curve with line parameters"""
60+ x = np .linspace (- 10 , 10 , 200 )
61+ y = np .sin (x )
62+ curve = make .curve (x , y , color = color , linestyle = linestyle , linewidth = linewidth )
63+ pen = curve .pen ()
64+ assert pen .color ().name () == _COLOR_TO_HEX [color ]
65+ assert pen .style () == getattr (Qt , linestyle )
66+ assert pen .width () == linewidth
67+ return curve
68+
69+
70+ @pytest .mark .parametrize ("color" , ["red" ])
4771@pytest .mark .parametrize (
4872 "linestyle" ,
4973 ["SolidLine" , "DashLine" , "DotLine" , "DashDotLine" , "DashDotDotLine" , "NoPen" ],
5074)
5175@pytest .mark .parametrize ("linewidth" , [1 , 2 ])
52- def test_builder_curve_line_params (qtbot , color , linestyle , linewidth ):
76+ def test_builder_curve_line_style (qtbot , color , linestyle , linewidth ):
77+ """Test line parameters of curve() method"""
78+ curve = _make_curve_linestyle (color , linestyle , linewidth )
79+ show_item (qtbot , curve , "curve" )
80+
81+
82+ @pytest .mark .parametrize ("color" , ["red" , "blue" ])
83+ @pytest .mark .parametrize ("linestyle" , ["SolidLine" ])
84+ @pytest .mark .parametrize ("linewidth" , [1 , 2 ])
85+ def test_builder_curve_line_color (qtbot , color , linestyle , linewidth ):
5386 """Test line parameters of curve() method"""
87+ curve = _make_curve_linestyle (color , linestyle , linewidth )
88+ show_item (qtbot , curve , "curve" )
89+
5490
91+ def _make_curve_marker (marker , markersize , markerfacecolor , markeredgecolor ):
92+ """Make curve with marker parameters"""
5593 x = np .linspace (- 10 , 10 , 200 )
5694 y = np .sin (x )
57- curve = make .curve (x , y , color = color , linestyle = linestyle , linewidth = linewidth )
58-
59- pen = curve .pen ()
60- assert pen .color ().name () == _COLOR_TO_HEX [color ]
61- assert pen .style () == getattr (Qt , linestyle )
62- assert pen .width () == linewidth
63- plot_qtbot_curve (qtbot , curve )
95+ curve = make .curve (
96+ x ,
97+ y ,
98+ marker = marker ,
99+ markersize = markersize ,
100+ markerfacecolor = markerfacecolor ,
101+ markeredgecolor = markeredgecolor ,
102+ )
103+ symbol = curve .symbol ()
104+ assert symbol .style () == getattr (type (symbol ), marker )
105+ assert symbol .size ().width () == markersize
106+ assert symbol .size ().height () == markersize
107+ assert symbol .brush ().color ().name () == _COLOR_TO_HEX [markerfacecolor ]
108+ assert symbol .pen ().color ().name () == _COLOR_TO_HEX [markeredgecolor ]
109+ return curve
64110
65111
66112@pytest .mark .parametrize (
@@ -80,29 +126,24 @@ def test_builder_curve_line_params(qtbot, color, linestyle, linewidth):
80126 "NoSymbol" ,
81127 ],
82128)
129+ @pytest .mark .parametrize ("markersize" , [5 ])
130+ @pytest .mark .parametrize ("markerfacecolor" , ["red" ])
131+ @pytest .mark .parametrize ("markeredgecolor" , ["blue" ])
132+ def test_builder_curve_marker_params_symbol (
133+ qtbot , marker , markersize , markerfacecolor , markeredgecolor
134+ ):
135+ """Test marker parameters of curve() methodg"""
136+ curve = _make_curve_marker (marker , markersize , markerfacecolor , markeredgecolor )
137+ show_item (qtbot , curve , "curve" )
138+
139+
140+ @pytest .mark .parametrize ("marker" , ["Cross" ])
83141@pytest .mark .parametrize ("markersize" , [1 , 5 , 10 ])
84142@pytest .mark .parametrize ("markerfacecolor" , ["red" , "blue" ])
85143@pytest .mark .parametrize ("markeredgecolor" , ["red" , "blue" ])
86- def test_builder_curve_marker_params (
144+ def test_builder_curve_marker_size_color (
87145 qtbot , marker , markersize , markerfacecolor , markeredgecolor
88146):
89147 """Test marker parameters of curve() methodg"""
90-
91- x = np .linspace (- 10 , 10 , 200 )
92- y = np .sin (x )
93- curve = make .curve (
94- x ,
95- y ,
96- marker = marker ,
97- markersize = markersize ,
98- markerfacecolor = markerfacecolor ,
99- markeredgecolor = markeredgecolor ,
100- )
101-
102- symbol = curve .symbol ()
103- assert symbol .style () == getattr (type (symbol ), marker )
104- assert symbol .size ().width () == markersize
105- assert symbol .size ().height () == markersize
106- assert symbol .brush ().color ().name () == _COLOR_TO_HEX [markerfacecolor ]
107- assert symbol .pen ().color ().name () == _COLOR_TO_HEX [markeredgecolor ]
108- plot_qtbot_curve (qtbot , curve )
148+ curve = _make_curve_marker (marker , markersize , markerfacecolor , markeredgecolor )
149+ show_item (qtbot , curve , "curve" )
0 commit comments