From 72218beff1848559f0a3fd0a812ba0d462a5ad7c Mon Sep 17 00:00:00 2001 From: pit-ray Date: Thu, 5 Jan 2023 00:09:00 +0900 Subject: [PATCH] add test case --- tests/runtime/checks/__init__.py | 21 +------------- tests/runtime/checks/check.py | 19 +++++++++++++ tests/runtime/checks/mouse.py | 48 ++++++++++++++++++++++++++++++-- tests/runtime/checks/proc.py | 6 ++++ tests/runtime/win.py | 5 ++++ 5 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 tests/runtime/checks/check.py create mode 100644 tests/runtime/win.py diff --git a/tests/runtime/checks/__init__.py b/tests/runtime/checks/__init__.py index 6c82484d..2d1a120b 100644 --- a/tests/runtime/checks/__init__.py +++ b/tests/runtime/checks/__init__.py @@ -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 diff --git a/tests/runtime/checks/check.py b/tests/runtime/checks/check.py new file mode 100644 index 00000000..e2ac59cf --- /dev/null +++ b/tests/runtime/checks/check.py @@ -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__)) diff --git a/tests/runtime/checks/mouse.py b/tests/runtime/checks/mouse.py index 79723c96..c2d765bf 100644 --- a/tests/runtime/checks/mouse.py +++ b/tests/runtime/checks/mouse.py @@ -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('') - 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('') + return delta > 0 + + +def move_cursor_right(handler): + handler.send_command('') + + x = get_cursor_pos()[0] + handler.send_command('l' * 100) + delta = get_cursor_pos()[0] - x + + handler.send_command('') + return delta > 0 + + +def move_cursor_up(handler): + handler.send_command('') + + y = get_cursor_pos()[1] + handler.send_command('k' * 100) + delta = y - get_cursor_pos()[1] + + handler.send_command('') + return delta > 0 + + +def move_cursor_down(handler): + handler.send_command('') + + y = get_cursor_pos()[1] + handler.send_command('j' * 100) + delta = get_cursor_pos()[1] - y handler.send_command('') return delta > 0 diff --git a/tests/runtime/checks/proc.py b/tests/runtime/checks/proc.py index 2f467cf9..9c06a748 100644 --- a/tests/runtime/checks/proc.py +++ b/tests/runtime/checks/proc.py @@ -1,3 +1,9 @@ +def get_cases(): + return [ + exit_process + ] + + def exit_process(handler): result_1 = handler.check_if_alive() handler.send_command(':exit') diff --git a/tests/runtime/win.py b/tests/runtime/win.py new file mode 100644 index 00000000..407a97ac --- /dev/null +++ b/tests/runtime/win.py @@ -0,0 +1,5 @@ +import pydirectinput as pdi + + +def get_cursor_pos(): + return pdi.position()