Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Jan 4, 2023
1 parent 7ba7bd5 commit 72218be
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 23 deletions.
21 changes: 1 addition & 20 deletions tests/runtime/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
from .mouse import move_cursor_left
from .proc import exit_process

import logger


def check(handler):
test_cases = [
move_cursor_left,
exit_process
]

num_of_case = len(test_cases)
for i, case in enumerate(test_cases):
if case(handler):
logger.info("Case {}/{}: {} is successed.".format(
i + 1, num_of_case, case.__name__))
else:
logger.error("Case {}/{}: {} is failed.".format(
i + 1, num_of_case, case.__name__))
from .check import check
19 changes: 19 additions & 0 deletions tests/runtime/checks/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logger

from . import mouse
from . import proc


def check(handler):
test_cases = [] \
+ mouse.get_cases() \
+ proc.get_cases()

num_of_case = len(test_cases)
for i, case in enumerate(test_cases):
if case(handler):
logger.info("Case {}/{}: {} is successed.".format(
i + 1, num_of_case, case.__name__))
else:
logger.error("Case {}/{}: {} is failed.".format(
i + 1, num_of_case, case.__name__))
48 changes: 45 additions & 3 deletions tests/runtime/checks/mouse.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
import pydirectinput as pdi
from win import get_cursor_pos


def get_cases():
return [
move_cursor_left,
move_cursor_right,
move_cursor_up,
move_cursor_down
]


def move_cursor_left(handler):
handler.send_command('<to_insert><ctrl-]>')

x = pdi.position()[0]
x = get_cursor_pos()[0]
handler.send_command('h' * 100)
delta = abs(pdi.position()[0] - x)
delta = x - get_cursor_pos()[0]

handler.send_command('<to_insert>')
return delta > 0


def move_cursor_right(handler):
handler.send_command('<to_insert><ctrl-]>')

x = get_cursor_pos()[0]
handler.send_command('l' * 100)
delta = get_cursor_pos()[0] - x

handler.send_command('<to_insert>')
return delta > 0


def move_cursor_up(handler):
handler.send_command('<to_insert><ctrl-]>')

y = get_cursor_pos()[1]
handler.send_command('k' * 100)
delta = y - get_cursor_pos()[1]

handler.send_command('<to_insert>')
return delta > 0


def move_cursor_down(handler):
handler.send_command('<to_insert><ctrl-]>')

y = get_cursor_pos()[1]
handler.send_command('j' * 100)
delta = get_cursor_pos()[1] - y

handler.send_command('<to_insert>')
return delta > 0
6 changes: 6 additions & 0 deletions tests/runtime/checks/proc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
def get_cases():
return [
exit_process
]


def exit_process(handler):
result_1 = handler.check_if_alive()
handler.send_command('<to_gui_normal>:exit<cr>')
Expand Down
5 changes: 5 additions & 0 deletions tests/runtime/win.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pydirectinput as pdi


def get_cursor_pos():
return pdi.position()

0 comments on commit 72218be

Please sign in to comment.