Skip to content
Merged

Dev #34

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ jobs:
- run:
command: python ./test/unit_test/timeout/timeout_test.py
name: timeout_test
# argparse
- run:
command: python ./test/unit_test/argparse/argparse_test.py
name: argparse_test
# html report test
- run:
command: python ./test/unit_test/html_report/html_report_test.py
name: html_report_test

# GUI Test
# image detect
- run:
Expand All @@ -88,10 +97,6 @@ jobs:
- run:
command: python ./test/gui_test/image/locate_image_center.py
name: locate_image_center_test
# argparse
- run:
command: python ./test/unit_test/argparse/argparse_test.py
name: argparse_test

# integrated_test
- run:
Expand Down Expand Up @@ -173,6 +178,11 @@ jobs:
- run:
command: python ./test/unit_test/timeout/timeout_test.py
name: timeout_test
# html report test
- run:
command: python ./test/unit_test/html_report/html_report_test.py
name: html_report_test

# GUI Test
# image detect
- run:
Expand All @@ -189,6 +199,7 @@ jobs:
command: python ./test/unit_test/argparse/argparse_test.py
name: argparse_test


# integrated_test
- run:
command: python ./test/integrated_test/total_record_and_html_report_test/total_record_and_html_report_test.py
Expand Down
68 changes: 39 additions & 29 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ documentation available at [https://python-jeautocontrol.readthedocs.io/en/lates
pip install je_auto_control
```

```

```

## Info

* requirement
Expand Down
2 changes: 1 addition & 1 deletion dev_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control_dev",
version="0.0.20",
version="0.0.21",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# timeout
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
# test record
from je_auto_control.utils.test_record.record_test_class import test_record
from je_auto_control.utils.test_record.record_test_class import test_record_instance

# utils image
from je_auto_control.wrapper.auto_control_image import screenshot
Expand Down
31 changes: 21 additions & 10 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
from je_auto_control.utils.exception.exceptions import AutoControlActionException
from je_auto_control.utils.json.json_file import read_action_json

from je_auto_control.utils.test_record.record_test_class import record_total
from je_auto_control.utils.test_record.record_test_class import record_action_to_list
from je_auto_control.utils.test_record.record_test_class import test_record_instance

from je_auto_control.utils.html_report.html_report_generate import generate_html

event_dict = {
# mouse
Expand Down Expand Up @@ -54,7 +57,11 @@
"locate_and_click": locate_and_click,
# screen
"size": size,
"screenshot": screenshot
"screenshot": screenshot,
# test record
"set_record_enable": test_record_instance.set_record_enable,
# generate html
"generate_html": generate_html,
}


Expand All @@ -69,18 +76,22 @@ def execute_action(action_list: list) -> str:
if action_list is None:
raise AutoControlActionNullException(action_is_null_error)
for action in action_list:
event = event_dict.get(action[0])
if len(action) == 2:
event(**action[1])
elif len(action) == 1:
event()
else:
raise AutoControlActionException(cant_execute_action_error)
try:
event = event_dict.get(action[0])
if len(action) == 2:
event(**action[1])
elif len(action) == 1:
event()
else:
raise AutoControlActionException(cant_execute_action_error)
except Exception as error:
print(repr(error), file=sys.stderr)
record_action_to_list("execute_action", None, repr(error))
temp_string = "execute: " + str(action)
print(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
except Exception as error:
record_total("execute_action", action_list, repr(error))
record_action_to_list("execute_action", action_list, repr(error))
print(repr(error), file=sys.stderr)
return execute_record_string

Expand Down
6 changes: 3 additions & 3 deletions je_auto_control/utils/html_report/html_report_generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from je_auto_control.utils.test_record.record_test_class import test_record
from je_auto_control.utils.test_record.record_test_class import test_record_instance
from je_auto_control.utils.exception.exceptions import HTMLException
from je_auto_control.utils.exception.exception_tag import html_generate_no_data_tag
from threading import Lock
Expand Down Expand Up @@ -134,11 +134,11 @@ def generate_html(html_name: str = "default_name") -> str:
:param html_name: save html file name
:return: html_string
"""
if len(test_record.total_record_list) == 0:
if len(test_record_instance.test_record_list) == 0:
raise HTMLException(html_generate_no_data_tag)
else:
event_str = ""
for record_data in test_record.total_record_list:
for record_data in test_record_instance.test_record_list:
# because data on record_data all is str
if record_data.get("program_exception") == "None":
event_str = make_html_table(event_str, record_data, "event_table_head")
Expand Down
19 changes: 11 additions & 8 deletions je_auto_control/utils/test_record/record_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@

class TestRecord(object):

def __init__(self, init_total_record: bool = False):
self.init_total_record = init_total_record
self.total_record_list = list()
def __init__(self, init_record: bool = False):
self.init_record = init_record
self.test_record_list = list()

def clean_record(self) -> None:
self.total_record_list = list()
self.test_record_list = list()

def set_record_enable(self, set_enable: bool = True):
self.init_record = set_enable

test_record = TestRecord()

test_record_instance = TestRecord()

def record_total(function_name: str, local_param, program_exception: str = None) -> None:
if not test_record.init_total_record:

def record_action_to_list(function_name: str, local_param, program_exception: str = None) -> None:
if not test_record_instance.init_record:
pass
else:
test_record.total_record_list.append(
test_record_instance.test_record_list.append(
{
"function_name": function_name,
"local_param": local_param,
Expand Down
18 changes: 9 additions & 9 deletions je_auto_control/wrapper/auto_control_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from je_auto_control.wrapper.auto_control_mouse import click_mouse
from je_auto_control.wrapper.auto_control_mouse import set_position
from je_auto_control.utils.image.screenshot import pil_screenshot
from je_auto_control.utils.test_record.record_test_class import record_total
from je_auto_control.utils.test_record.record_test_class import record_action_to_list


def locate_all_image(image, detect_threshold: [float, int] = 1,
Expand All @@ -26,12 +26,12 @@ def locate_all_image(image, detect_threshold: [float, int] = 1,
except ImageNotFoundException as error:
raise ImageNotFoundException(find_image_error_variable + " " + repr(error))
if image_data_array[0] is True:
record_total("locate_all_image", param)
record_action_to_list("locate_all_image", param)
return image_data_array[1]
else:
raise ImageNotFoundException(cant_find_image)
except Exception as error:
record_total("locate_all_image", param, repr(error))
record_action_to_list("locate_all_image", param, repr(error))
print(repr(error), file=sys.stderr)


Expand All @@ -52,12 +52,12 @@ def locate_image_center(image, detect_threshold: [float, int] = 1, draw_image: b
height = image_data_array[1][2] - image_data_array[1][0]
width = image_data_array[1][3] - image_data_array[1][1]
center = [int(height / 2), int(width / 2)]
record_total("locate_image_center", param)
record_action_to_list("locate_image_center", param)
return [image_data_array[1][0] + center[0], image_data_array[1][1] + center[1]]
else:
raise ImageNotFoundException(cant_find_image)
except Exception as error:
record_total("locate_image_center", param, repr(error))
record_action_to_list("locate_image_center", param, repr(error))
print(repr(error), file=sys.stderr)


Expand Down Expand Up @@ -86,12 +86,12 @@ def locate_and_click(
image_center_y = image_data_array[1][1] + center[1]
set_position(int(image_center_x), int(image_center_y))
click_mouse(mouse_keycode)
record_total("locate_and_click", param)
record_action_to_list("locate_and_click", param)
return [image_center_x, image_center_y]
else:
raise ImageNotFoundException(cant_find_image)
except Exception as error:
record_total("locate_and_click", param, repr(error))
record_action_to_list("locate_and_click", param, repr(error))
print(repr(error), file=sys.stderr)


Expand All @@ -103,8 +103,8 @@ def screenshot(file_path: str = None, region: list = None) -> List[Union[int, in
"""
param = locals()
try:
record_total("screenshot", param)
record_action_to_list("screenshot", param)
return pil_screenshot(file_path, region)
except Exception as error:
print(repr(error), file=sys.stderr)
record_total("screenshot", param, repr(error))
record_action_to_list("screenshot", param, repr(error))
38 changes: 19 additions & 19 deletions je_auto_control/wrapper/auto_control_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from je_auto_control.wrapper.platform_wrapper import keyboard
from je_auto_control.wrapper.platform_wrapper import keyboard_check
from je_auto_control.wrapper.platform_wrapper import keys_table
from je_auto_control.utils.test_record.record_test_class import record_total
from je_auto_control.utils.test_record.record_test_class import record_action_to_list


def press_key(keycode: [int, str], is_shift: bool = False, skip_record: bool = False) -> str:
Expand All @@ -38,19 +38,19 @@ def press_key(keycode: [int, str], is_shift: bool = False, skip_record: bool = F
elif sys.platform in ["darwin"]:
keyboard.press_key(keycode, is_shift=is_shift)
if skip_record is False:
record_total("press_key", param)
record_action_to_list("press_key", param)
return str(keycode)
except AutoControlKeyboardException as error:
if skip_record is False:
record_total("press_key", param, repr(error))
record_action_to_list("press_key", param, repr(error))
raise AutoControlKeyboardException(keyboard_press_key + " " + repr(error))
except TypeError as error:
if skip_record is False:
record_total("press_key", param, repr(error))
record_action_to_list("press_key", param, repr(error))
raise AutoControlKeyboardException(repr(error))
except Exception as error:
if skip_record is False:
record_total("press_key", param, repr(error))
record_action_to_list("press_key", param, repr(error))
else:
raise AutoControlKeyboardException(repr(error))
print(repr(error), file=sys.stderr)
Expand All @@ -76,19 +76,19 @@ def release_key(keycode: [int, str], is_shift: bool = False, skip_record: bool =
elif sys.platform in ["darwin"]:
keyboard.release_key(keycode, is_shift=is_shift)
if skip_record is False:
record_total("release_key", param)
record_action_to_list("release_key", param)
return str(keycode)
except AutoControlKeyboardException as error:
if skip_record is False:
record_total("release_key", param, repr(error))
record_action_to_list("release_key", param, repr(error))
raise AutoControlKeyboardException(keyboard_release_key + " " + repr(error))
except TypeError as error:
if skip_record is False:
record_total("release_key", param, repr(error))
record_action_to_list("release_key", param, repr(error))
raise AutoControlKeyboardException(repr(error))
except Exception as error:
if skip_record is False:
record_total("release_key", param, repr(error))
record_action_to_list("release_key", param, repr(error))
else:
raise AutoControlKeyboardException(repr(error))
print(repr(error), file=sys.stderr)
Expand All @@ -107,19 +107,19 @@ def type_key(keycode: [int, str], is_shift: bool = False, skip_record: bool = Fa
press_key(keycode, is_shift, skip_record=True)
release_key(keycode, is_shift, skip_record=True)
if skip_record is False:
record_total("type_key", param)
record_action_to_list("type_key", param)
return str(keycode)
except AutoControlKeyboardException as error:
if skip_record is False:
record_total("type_key", param, repr(error))
record_action_to_list("type_key", param, repr(error))
raise AutoControlKeyboardException(keyboard_type_key + " " + repr(error))
except TypeError as error:
if skip_record is False:
record_total("type_key", param, repr(error))
record_action_to_list("type_key", param, repr(error))
raise AutoControlKeyboardException(repr(error))
except Exception as error:
if skip_record is False:
record_total("type_key", param, repr(error))
record_action_to_list("type_key", param, repr(error))
print(repr(error), file=sys.stderr)


Expand All @@ -134,10 +134,10 @@ def check_key_is_press(keycode: [int, str]) -> bool:
get_key_code = keycode
else:
get_key_code = keys_table.get(keycode)
record_total("check_key_is_press", param)
record_action_to_list("check_key_is_press", param)
return keyboard_check.check_key_is_press(keycode=get_key_code)
except Exception as error:
record_total("check_key_is_press", param, repr(error))
record_action_to_list("check_key_is_press", param, repr(error))
print(repr(error), file=sys.stderr)


Expand Down Expand Up @@ -166,12 +166,12 @@ def write(write_string: str, is_shift: bool = False) -> str:
except AutoControlKeyboardException as error:
print(keyboard_write_cant_find, single_string, sep="\t", file=sys.stderr)
raise AutoControlKeyboardException(keyboard_write_cant_find)
record_total("write", param)
record_action_to_list("write", param)
return record_write_string
except AutoControlKeyboardException as error:
raise AutoControlKeyboardException(keyboard_write + " " + repr(error))
except Exception as error:
record_total("write", param, repr(error))
record_action_to_list("write", param, repr(error))
print(repr(error), file=sys.stderr)


Expand Down Expand Up @@ -203,10 +203,10 @@ def hotkey(key_code_list: list, is_shift: bool = False) -> Tuple[str, str]:
release_key(key, is_shift, skip_record=True)
]
)
record_total("hotkey", param)
record_action_to_list("hotkey", param)
return record_hotkey_press_string, record_hotkey_release_string
except AutoControlKeyboardException as error:
raise AutoControlKeyboardException(keyboard_hotkey + " " + repr(error))
except Exception as error:
record_total("hotkey", param, repr(error))
record_action_to_list("hotkey", param, repr(error))
print(repr(error), file=sys.stderr)
Loading