2
2
import shutil
3
3
import subprocess
4
4
import sys
5
+ import warnings
5
6
6
7
import pytest
7
8
@@ -71,11 +72,6 @@ def test_webagg_general(page):
71
72
# Check title.
72
73
expect (page .locator ('div.ui-dialog-title' )).to_have_text ('Figure 1' )
73
74
74
- # Check toolbar buttons.
75
- assert page .locator ('button.mpl-widget' ).count () == len ([
76
- name for name , * _ in fig .canvas .manager .ToolbarCls .toolitems
77
- if name is not None ])
78
-
79
75
# Check canvas actually contains something.
80
76
baseline_dir , result_dir = _image_directories (test_webagg_general )
81
77
browser = page .context .browser .browser_type .name
@@ -89,3 +85,65 @@ def test_webagg_general(page):
89
85
err = compare_images (expected , actual , tol = 0 )
90
86
if err :
91
87
raise ImageComparisonFailure (err )
88
+
89
+
90
+ @pytest .mark .backend ('webagg' )
91
+ @pytest .mark .parametrize ('toolbar' , ['toolbar2' , 'toolmanager' ])
92
+ def test_webagg_toolbar (page , toolbar ):
93
+ from playwright .sync_api import expect
94
+
95
+ # Listen for all console logs.
96
+ page .on ('console' , lambda msg : print (f'CONSOLE: { msg .text } ' ))
97
+
98
+ with warnings .catch_warnings ():
99
+ warnings .filterwarnings ('ignore' , message = 'Treat the new Tool classes' ,
100
+ category = UserWarning )
101
+ plt .rcParams ['toolbar' ] = toolbar
102
+
103
+ fig , ax = plt .subplots (facecolor = 'w' )
104
+
105
+ # Don't start the Tornado event loop, but use the existing event loop
106
+ # started by the `page` fixture.
107
+ WebAggApplication .initialize ()
108
+ WebAggApplication .started = True
109
+
110
+ page .goto (f'http://{ WebAggApplication .address } :{ WebAggApplication .port } /' )
111
+
112
+ expect (page .locator ('button.mpl-widget' )).to_have_count (
113
+ len ([
114
+ name for name , * _ in fig .canvas .manager .ToolbarCls .toolitems
115
+ if name is not None ]))
116
+
117
+ home = page .locator ('button.mpl-widget' ).nth (0 )
118
+ expect (home ).to_be_visible ()
119
+
120
+ back = page .locator ('button.mpl-widget' ).nth (1 )
121
+ expect (back ).to_be_visible ()
122
+ forward = page .locator ('button.mpl-widget' ).nth (2 )
123
+ expect (forward ).to_be_visible ()
124
+ if toolbar == 'toolbar2' :
125
+ # ToolManager doesn't implement history button disabling.
126
+ # https://github.com/matplotlib/matplotlib/issues/17979
127
+ expect (back ).to_be_disabled ()
128
+ expect (forward ).to_be_disabled ()
129
+
130
+ pan = page .locator ('button.mpl-widget' ).nth (3 )
131
+ expect (pan ).to_be_visible ()
132
+ zoom = page .locator ('button.mpl-widget' ).nth (4 )
133
+ expect (zoom ).to_be_visible ()
134
+
135
+ save = page .locator ('button.mpl-widget' ).nth (5 )
136
+ expect (save ).to_be_visible ()
137
+ format_dropdown = page .locator ('select.mpl-widget' )
138
+ expect (format_dropdown ).to_be_visible ()
139
+
140
+ if toolbar == 'toolmanager' :
141
+ # Location in status bar is not supported by ToolManager.
142
+ return
143
+
144
+ ax .set_position ([0 , 0 , 1 , 1 ])
145
+ bbox = page .locator ('canvas.mpl-canvas' ).bounding_box ()
146
+ x , y = bbox ['x' ] + bbox ['width' ] / 2 , bbox ['y' ] + bbox ['height' ] / 2
147
+ page .mouse .move (x , y , steps = 2 )
148
+ message = page .locator ('span.mpl-message' )
149
+ expect (message ).to_have_text ('x=0.500 y=0.500' )
0 commit comments