Skip to content

Commit

Permalink
Add assert for client connection
Browse files Browse the repository at this point in the history
  • Loading branch information
hbatagelo committed May 24, 2024
1 parent ce8bc8a commit 46e62ef
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mir-ci/mir_ci/tests/robot/platforms/vnc/Vnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def match(self, template: str, timeout: int = 5) -> List[dict]:
:raises ImageNotFoundError: if no match is found within the timeout
"""
await self.connect()
assert self._client is not None, "Client must be connected"
regions = []
end_time = time.time() + float(timeout)
screenshot = None
Expand Down Expand Up @@ -87,11 +88,13 @@ async def match(self, template: str, timeout: int = 5) -> List[dict]:
@keyword
async def type_string(self, text: str):
await self.connect()
assert self._client is not None, "Client must be connected"
self._client.keyboard.write(text)

@keyword
async def move_pointer_to_absolute(self, x: int, y: int) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
self._client.mouse.move(x, y)
self._pointer_position = (x, y)

Expand All @@ -105,6 +108,7 @@ async def move_pointer_to_proportional(self, x: float, y: float) -> tuple[int, i
@keyword
async def walk_pointer_to_absolute(self, x: int, y: int, step_distance: int, delay: float) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
assert step_distance > 0, "Step distance must be positive"

if self._pointer_position is None:
Expand Down Expand Up @@ -137,25 +141,29 @@ async def walk_pointer_to_proportional(
@keyword
async def press_pointer_button(self, button: str) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
mask = 1 << Button[button]
self._client.mouse.buttons |= mask
self._client.mouse._write()

@keyword
async def release_pointer_button(self, button: str) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
mask = 1 << Button[button]
self._client.mouse.buttons &= ~mask
self._client.mouse._write()

@keyword
async def click_pointer_button(self, button: str) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
self._client.mouse.click(Button[button])

@keyword
async def release_buttons(self) -> None:
await self.connect()
assert self._client is not None, "Client must be connected"
self._client.mouse.buttons = 0
self._client.mouse._write()

Expand All @@ -171,6 +179,7 @@ def get_absolute_from_proportional(self, x: float, y: float) -> tuple[int, int]:
of the output.
:return tuple containing the corresponding absolute x and y coordinates.
"""
assert self._client is not None, "Client must be connected"
assert 0 <= x <= 1, "x not in range 0..1"
assert 0 <= y <= 1, "y not in range 0..1"
assert self._client.video.width > 0, "Output width must be greater than 0"
Expand Down

0 comments on commit 46e62ef

Please sign in to comment.