@@ -26,15 +26,14 @@ def setUp(self) -> None:
2626 self .counter .__enter__ .return_value = (
2727 self .counter
2828 ) # return self as a context manager
29- type(self .counter ).count = PropertyMock (side_effect = [0 , 0 , 1 ])
29+ type(self .counter ).count = PropertyMock (side_effect = [0 , 0 , 1 , 0 , 0 , 1 ])
3030 self .countio .Counter .return_value = self .counter
3131 self .asyncio = MagicMock ()
3232 self .asyncio .sleep = AsyncMock ()
3333 self .patch_asyncio = patch ("async_button.asyncio" , self .asyncio )
3434 self .patch_asyncio .start ()
3535 self .edge_rise = self .countio .Edge .RISE
3636 self .edge_fall = self .countio .Edge .FALL
37- self .simple_button_class = async_button .SimpleButton
3837
3938 def tearDown (self ) -> None :
4039 self .patch_asyncio .stop ()
@@ -49,25 +48,54 @@ async def test_pressed_active_high(self):
4948 self .assertEqual (self .asyncio .sleep .await_count , 2 )
5049
5150 async def test_released_active_high (self ):
52- button = self . simple_button_class ("P1" , True )
51+ button = async_button . SimpleButton ("P1" , True )
5352 await button .released ()
5453 self .countio .Counter .assert_called_once_with (
5554 "P1" , edge = self .edge_fall , pull = digitalio .Pull .DOWN
5655 )
5756 self .assertEqual (self .asyncio .sleep .await_count , 2 )
5857
5958 async def test_pressed_active_low (self ):
60- button = self . simple_button_class ("P1" , False )
59+ button = async_button . SimpleButton ("P1" , False )
6160 await button .pressed ()
6261 self .countio .Counter .assert_called_once_with (
6362 "P1" , edge = self .edge_fall , pull = digitalio .Pull .UP
6463 )
6564 self .assertEqual (self .asyncio .sleep .await_count , 2 )
6665
6766 async def test_released_active_low (self ):
68- button = self . simple_button_class ("P1" , False )
67+ button = async_button . SimpleButton ("P1" , False )
6968 await button .released ()
7069 self .countio .Counter .assert_called_once_with (
7170 "P1" , edge = self .edge_rise , pull = digitalio .Pull .UP
7271 )
7372 self .assertEqual (self .asyncio .sleep .await_count , 2 )
73+
74+ async def test_pull_false_is_respected (self ):
75+ button = async_button .SimpleButton ("P1" , False , pull = False )
76+ await button .released ()
77+ self .countio .Counter .assert_called_once_with (
78+ "P1" , edge = self .edge_rise , pull = None
79+ )
80+ self .assertEqual (self .asyncio .sleep .await_count , 2 )
81+
82+ async def test_default_interval (self ):
83+ button = async_button .SimpleButton ("P1" , False )
84+ await button .pressed ()
85+ self .asyncio .sleep .assert_awaited_with (0.05 )
86+ await button .released ()
87+ self .asyncio .sleep .assert_awaited_with (0.05 )
88+
89+ async def test_interval_zero (self ):
90+ button = async_button .SimpleButton ("P1" , False , interval = 0 )
91+ await button .pressed ()
92+ self .asyncio .sleep .assert_awaited_with (0 )
93+ await button .released ()
94+ self .asyncio .sleep .assert_awaited_with (0 )
95+
96+ async def test_other_interval (self ):
97+ button = async_button .SimpleButton ("P1" , False , interval = 1.25 )
98+ await button .pressed ()
99+ self .asyncio .sleep .assert_awaited_with (1.25 )
100+ await button .released ()
101+ self .asyncio .sleep .assert_awaited_with (1.25 )
0 commit comments