diff --git a/tests/test_xyscreens.py b/tests/test_xyscreens.py index ca86ab0..c3aa878 100644 --- a/tests/test_xyscreens.py +++ b/tests/test_xyscreens.py @@ -118,7 +118,7 @@ def test_position_halfway(self): screen = XYScreens(_SERIAL_PORT, 10, 10) screen.down() time.sleep(5) - self.assertAlmostEqual(50.0, screen.position(), delta=0.5) + self.assertAlmostEqual(50.0, screen.position(), delta=0.3) def test_change_direction_down(self): screen = XYScreens(_SERIAL_PORT, 10, 10, 100) @@ -143,14 +143,14 @@ def test_set_position_downward(self): screen.set_position(50.0) (state, position) = screen.update_status() self.assertIs(XYScreensState.STOPPED, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) def test_set_position_upward(self): screen = XYScreens(_SERIAL_PORT, 10, 10, 100.0) screen.set_position(50.0) (state, position) = screen.update_status() self.assertIs(XYScreensState.STOPPED, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) @async_test async def test_async_down(self): @@ -189,6 +189,7 @@ async def test_async_state_closing(self): screen = XYScreens(_SERIAL_PORT, 60, 60, 100) await screen.async_up() self.assertIs(XYScreensState.UPWARD, screen.state()) + await screen.async_stop() @async_test async def test_async_state_stopped(self): @@ -203,6 +204,7 @@ async def test_async_state_downward(self): screen = XYScreens(_SERIAL_PORT, 10, 10) await screen.async_down() self.assertIs(XYScreensState.DOWNWARD, screen.state()) + await screen.async_stop() @async_test async def test_async_state_down(self): @@ -230,7 +232,8 @@ async def test_async_position_halfway(self): screen = XYScreens(_SERIAL_PORT, 10, 10) await screen.async_down() await asyncio.sleep(5) - self.assertAlmostEqual(50.0, screen.position(), delta=0.5) + self.assertAlmostEqual(50.0, screen.position(), delta=0.3) + await screen.async_stop() @async_test async def test_async_change_direction_down(self): @@ -240,7 +243,8 @@ async def test_async_change_direction_down(self): await screen.async_down() (state, position) = screen.update_status() self.assertIs(XYScreensState.DOWNWARD, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) + await screen.async_stop() @async_test async def test_async_change_direction_up(self): @@ -250,7 +254,8 @@ async def test_async_change_direction_up(self): await screen.async_up() (state, position) = screen.update_status() self.assertIs(XYScreensState.UPWARD, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) + await screen.async_stop() @async_test async def test_async_set_position_downward(self): @@ -259,7 +264,7 @@ async def test_async_set_position_downward(self): await asyncio.sleep(5.1) (state, position) = screen.update_status() self.assertIs(XYScreensState.STOPPED, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) @async_test async def test_async_set_position_upward(self): @@ -268,7 +273,18 @@ async def test_async_set_position_upward(self): await asyncio.sleep(5.1) (state, position) = screen.update_status() self.assertIs(XYScreensState.STOPPED, state) - self.assertAlmostEqual(50.0, position, delta=0.5) + self.assertAlmostEqual(50.0, position, delta=0.3) + + @async_test + async def test_async_set_position_stop(self): + """Test stopping the screen while it is moving to a given position.""" + screen = XYScreens(_SERIAL_PORT, 10, 10) + await screen.async_down() + await asyncio.sleep(5) + await screen.async_stop() + (state, position) = screen.update_status() + self.assertIs(XYScreensState.STOPPED, state) + self.assertAlmostEqual(50.0, position, delta=0.3) def test_restore_position_up(self): screen = XYScreens(_SERIAL_PORT, 60)