|
4 | 4 | frommatplotlib.backend_basesimport (
|
5 | 5 | FigureCanvasBase,LocationEvent,MouseButton,MouseEvent,
|
6 | 6 | NavigationToolbar2,RendererBase)
|
| 7 | +frommatplotlib.backend_toolsimportRubberbandBase |
7 | 8 | frommatplotlib.figureimportFigure
|
8 | 9 | frommatplotlib.testing._markersimportneeds_pgf_xelatex
|
9 | 10 | importmatplotlib.pyplotasplt
|
@@ -349,3 +350,56 @@ def test_interactive_pan(key, mouseend, expectedxlim, expectedylim):
|
349 | 350 | # Should be close, but won't be exact due to screen integer resolution
|
350 | 351 | asserttuple(ax.get_xlim())==pytest.approx(expectedxlim,abs=0.02)
|
351 | 352 | asserttuple(ax.get_ylim())==pytest.approx(expectedylim,abs=0.02)
|
| 353 | + |
| 354 | + |
| 355 | +deftest_toolmanager_remove(): |
| 356 | +expected_warning_regex= ( |
| 357 | +r"Treat the new Tool classes introduced in " |
| 358 | +r"v[0-9]*.[0-9]* as experimental for now; " |
| 359 | +"the API and rcParam may change in future versions.") |
| 360 | +withpytest.warns(UserWarning,match=expected_warning_regex): |
| 361 | +plt.rcParams['toolbar']='toolmanager' |
| 362 | +fig=plt.gcf() |
| 363 | +initial_len=len(fig.canvas.manager.toolmanager.tools) |
| 364 | +assert'forward'infig.canvas.manager.toolmanager.tools.keys() |
| 365 | +fig.canvas.manager.toolmanager.remove_tool('forward') |
| 366 | +assertlen(fig.canvas.manager.toolmanager.tools)==initial_len-1 |
| 367 | +assert'forward'notinfig.canvas.manager.toolmanager.tools.keys() |
| 368 | + |
| 369 | + |
| 370 | +deftest_toolmanager_get_tool(): |
| 371 | +expected_warning_regex= ( |
| 372 | +r"Treat the new Tool classes introduced in " |
| 373 | +r"v[0-9]*.[0-9]* as experimental for now; " |
| 374 | +"the API and rcParam may change in future versions.") |
| 375 | +withpytest.warns(UserWarning,match=expected_warning_regex): |
| 376 | +plt.rcParams['toolbar']='toolmanager' |
| 377 | +fig=plt.gcf() |
| 378 | +rubberband=fig.canvas.manager.toolmanager.get_tool('rubberband') |
| 379 | +assertisinstance(rubberband,RubberbandBase) |
| 380 | +assertfig.canvas.manager.toolmanager.get_tool(rubberband)isrubberband |
| 381 | +withpytest.warns(UserWarning, |
| 382 | +match="ToolManager does not control tool 'foo'"): |
| 383 | +assertfig.canvas.manager.toolmanager.get_tool('foo')isNone |
| 384 | +assertfig.canvas.manager.toolmanager.get_tool('foo',warn=False)isNone |
| 385 | + |
| 386 | +withpytest.warns(UserWarning, |
| 387 | +match="ToolManager does not control tool 'foo'"): |
| 388 | +assertfig.canvas.manager.toolmanager.trigger_tool('foo')isNone |
| 389 | + |
| 390 | + |
| 391 | +deftest_toolmanager_update_keymap(): |
| 392 | +expected_warning_regex= ( |
| 393 | +r"Treat the new Tool classes introduced in " |
| 394 | +r"v[0-9]*.[0-9]* as experimental for now; " |
| 395 | +"the API and rcParam may change in future versions.") |
| 396 | +withpytest.warns(UserWarning,match=expected_warning_regex): |
| 397 | +plt.rcParams['toolbar']='toolmanager' |
| 398 | +fig=plt.gcf() |
| 399 | +assert'v'infig.canvas.manager.toolmanager.get_tool_keymap('forward') |
| 400 | +withpytest.warns(UserWarning, |
| 401 | +match="Key c changed from back to forward"): |
| 402 | +fig.canvas.manager.toolmanager.update_keymap('forward','c') |
| 403 | +assertfig.canvas.manager.toolmanager.get_tool_keymap('forward')== ['c'] |
| 404 | +withpytest.raises(KeyError,match="'foo' not in Tools"): |
| 405 | +fig.canvas.manager.toolmanager.update_keymap('foo','c') |