Skip to content

Commit

Permalink
Improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rrooggiieerr committed May 14, 2024
1 parent 0fb6f45 commit d5c7496
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tests/test_xyscreens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit d5c7496

Please sign in to comment.