1
1
import importlib
2
+ from unittest .mock import patch
2
3
3
4
from matplotlib import path , transforms
4
5
from matplotlib .backend_bases import (
5
6
FigureCanvasBase , KeyEvent , LocationEvent , MouseButton , MouseEvent ,
6
- NavigationToolbar2 , RendererBase )
7
+ NavigationToolbar2 , RendererBase , TimerBase )
7
8
from matplotlib .backend_tools import RubberbandBase
8
9
from matplotlib .figure import Figure
9
10
from matplotlib .testing ._markers import needs_pgf_xelatex
@@ -581,3 +582,24 @@ def test_interactive_pan_zoom_events(tool, button, patch_vis, forward_nav, t_s):
581
582
# Check if twin-axes are properly triggered
582
583
assert ax_t .get_xlim () == pytest .approx (ax_t_twin .get_xlim (), abs = 0.15 )
583
584
assert ax_b .get_xlim () == pytest .approx (ax_b_twin .get_xlim (), abs = 0.15 )
585
+
586
+
587
+ def test_timer_properties ():
588
+ # Setting a property to the same value should not trigger the
589
+ # private setter call again.
590
+ timer = TimerBase (100 )
591
+ with patch .object (timer , '_timer_set_interval' ) as mock :
592
+ timer .interval = 200
593
+ mock .assert_called_once ()
594
+ assert timer .interval == 200
595
+ timer .interval = 200
596
+ # Make sure it wasn't called again
597
+ mock .assert_called_once ()
598
+
599
+ with patch .object (timer , '_timer_set_single_shot' ) as mock :
600
+ timer .single_shot = True
601
+ mock .assert_called_once ()
602
+ assert timer ._single
603
+ timer .single_shot = True
604
+ # Make sure it wasn't called again
605
+ mock .assert_called_once ()
0 commit comments