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

Skip to content

Commit a4193b6

Browse files
committed
WebAgg: Add a test for resizing the figure
1 parent 91089d9 commit a4193b6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/matplotlib/tests/test_backend_webagg.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,32 @@ def test_webagg_general(random_port, page):
8383
raise ImageComparisonFailure(err)
8484

8585

86+
@pytest.mark.backend('webagg')
87+
def test_webagg_resize(random_port, page):
88+
fig, ax = plt.subplots(facecolor='w')
89+
orig_bbox = fig.bbox.frozen()
90+
91+
# Don't start the Tornado event loop, but use the existing event loop
92+
# started by the `page` fixture.
93+
WebAggApplication.initialize(port=random_port)
94+
WebAggApplication.started = True
95+
96+
page.goto(f'http://{WebAggApplication.address}:{WebAggApplication.port}/')
97+
98+
canvas = page.locator('canvas.mpl-canvas')
99+
100+
# Resize the canvas to be twice as big.
101+
bbox = canvas.bounding_box()
102+
x, y = bbox['x'] + bbox['width'] - 1, bbox['y'] + bbox['height'] - 1
103+
page.mouse.move(x, y)
104+
page.mouse.down()
105+
page.mouse.move(x + bbox['width'], y + bbox['height'])
106+
page.mouse.up()
107+
108+
assert fig.bbox.height == orig_bbox.height * 2
109+
assert fig.bbox.width == orig_bbox.width * 2
110+
111+
86112
@pytest.mark.backend('webagg')
87113
@pytest.mark.parametrize('toolbar', ['toolbar2', 'toolmanager'])
88114
def test_webagg_toolbar(random_port, page, toolbar):

0 commit comments

Comments
 (0)