Skip to content

Dev #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 28, 2022
Merged

Dev #23

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: 17 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: 2.1

orbs:
windows: circleci/windows@2.4.1
macos: circleci/macos@2.0.1
python: circleci/python@1.5.0

jobs:
Expand Down Expand Up @@ -63,6 +62,9 @@ jobs:
- run:
command: python ./test/unit_test/record/record_test.py
name: record_test
- run:
command: python ./test/unit_test/total_record_test/total_record_test.py
name: total_record_test
# execute
- run:
command: python ./test/unit_test/execute_action/execute_action_test.py
Expand Down Expand Up @@ -91,6 +93,11 @@ 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
name: total_record_and_html_report_test

build-and-test-windows-stable:
executor:
name: windows/default
Expand All @@ -104,7 +111,7 @@ jobs:
name: pip install --upgrade --user pip setuptools wheel
# pip require package
- run:
command: pip install --user -r dev_requirements.txt
command: pip install --user -r requirements.txt
name: pip dev_requirements.txt
# screen test
- run:
Expand Down Expand Up @@ -148,6 +155,9 @@ jobs:
- run:
command: python ./test/unit_test/record/record_test.py
name: record_test
- run:
command: python ./test/unit_test/total_record_test/total_record_test.py
name: total_record_test
# execute
- run:
command: python ./test/unit_test/execute_action/execute_action_test.py
Expand Down Expand Up @@ -176,6 +186,11 @@ 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
name: total_record_and_html_report_test

workflows:
main:
jobs:
Expand Down
114 changes: 65 additions & 49 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 3 additions & 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.08",
version="0.0.14",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down Expand Up @@ -34,3 +34,5 @@

# python dev_setup.py sdist bdist_wheel
# python -m twine upload dist/*


3 changes: 1 addition & 2 deletions docs/source/example/executor_example/execute_action.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ AutoControlGUI Execute action
]
print("\n\n")
execute_action(test_list)
print(test_record.record_list)
print(test_record.error_record_list)




5 changes: 4 additions & 1 deletion je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@
# timeout
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
# test record
from je_auto_control.utils.test_record.record_test_result_class import test_record
from je_auto_control.utils.test_record.record_test_class import test_record

# utils image
from je_auto_control.wrapper.auto_control_image import screenshot

# html report

from je_auto_control.utils.html_report.html_report_generate import generate_html
18 changes: 10 additions & 8 deletions je_auto_control/utils/exception/exception_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
linux_import_error = "should be only loaded on linux"
osx_import_error = "should be only loaded on MacOS"
windows_import_error = "should be only loaded on windows"
macos_record_error = "macos can't use recorder"
macos_record_error = "macos cant use recorder"
# keyboard tags
keyboard_error = "Auto control keyboard error"
keyboard_press_key = "keyboard press key error"
keyboard_release_key = "keyboard release key error"
keyboard_type_key = "keyboard type key error"
keyboard_write = "keyboard write error"
keyboard_write_cant_find = "keyboard write error can't find key"
keyboard_write_cant_find = "keyboard write error cant find key"
keyboard_hotkey = "keyboard hotkey error"
# mouse tags
mouse_error = "Auto control mouse error"
Expand All @@ -28,19 +28,21 @@
screen_get_size = "screen get size error"
screen_screenshot = "screen screenshot error"
# table tags
table_cant_find_key = "can't find key error"
table_cant_find_key = "cant find key error"
# image tags
cant_find_image = "can't find image"
cant_find_image = "cant find image"
find_image_error_variable = "variable error"
# listener tags
listener_error = "Auto control listener error"
# test_record tags
record_queue_error = "can't get test_record queue it's none are you using stop test_record before test_record"
record_queue_error = "cant get test_record queue its none are you using stop test_record before test_record"
record_not_found_action_error = "test_record action not found"
# json action file tag
cant_execute_action_error = "can't execute action"
cant_find_json_error = "can't find json file"
cant_save_json_error = "can't save json file"
cant_execute_action_error = "cant execute action"
cant_find_json_error = "cant find json file"
cant_save_json_error = "cant save json file"
action_is_null_error = "json action is null"
# timeout tag
timeout_need_on_main_error = "should put timeout function on main"
# HTML
html_generate_no_data_tag = "record is None"
8 changes: 8 additions & 0 deletions je_auto_control/utils/exception/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ class AutoControlActionException(AutoControlException):
# timeout
class AutoControlTimeoutException(AutoControlException):
pass


# html exception

class HTMLException(AutoControlException):
pass


47 changes: 23 additions & 24 deletions je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from je_auto_control import AutoControlActionException
from je_auto_control import AutoControlActionNullException
from je_auto_control import check_key_is_press
from je_auto_control import click_mouse
Expand All @@ -25,7 +24,7 @@
from je_auto_control.utils.exception.exception_tag import cant_execute_action_error
from je_auto_control.utils.exception.exceptions import AutoControlActionException

from je_auto_control.utils.test_record.record_test_result_class import test_record
from je_auto_control.utils.test_record.record_test_class import record_total

event_dict = {
# mouse
Expand Down Expand Up @@ -57,33 +56,33 @@
}


def execute_event(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)


def execute_action(action_list: list):
"""
use to execute all action on action list(action file or program list)
:param action_list the list include action
for loop the list and execute action
"""
execute_record_string = ""
if action_list is None:
raise AutoControlActionNullException(action_is_null_error)
for action in action_list:
try:
execute_event(action)
temp_string = "execute: " + str(action)
print(temp_string)
test_record.record_list.append(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
except Exception as error:
print(repr(error), file=sys.stderr)
test_record.error_record_list.append([action, repr(error)])
try:
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:
param = action[1]
event(**action[1])
elif len(action) == 1:
param = None
event()
else:
raise AutoControlActionException(cant_execute_action_error)
try:
temp_string = "execute: " + str(action)
print(temp_string)
record_total(action[0], param)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
except AutoControlActionException as error:
record_total(action[0], param, repr(error))
except Exception as error:
print(repr(error), file=sys.stderr)
return execute_record_string
Empty file.
157 changes: 157 additions & 0 deletions je_auto_control/utils/html_report/html_report_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import sys

from je_auto_control.utils.test_record.record_test_class import test_record
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

lock = Lock()

html_string = \
r"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>AutoControl Report</title>

<style>

body{{
font-size: 100%;
}}

h1{{
font-size: 2em;
}}

.main_table {{
margin: 0 auto;
border-collapse: collapse;
width: 75%;
font-size: 1.5em;
}}

.event_table_head {{
border: 3px solid #262626;
background-color: aqua;
font-family: "Times New Roman", sans-serif;
text-align: center;
}}

.failure_table_head {{
border: 3px solid #262626;
background-color: #f84c5f;
font-family: "Times New Roman", sans-serif;
text-align: center;
}}

.table_data_field_title {{
border: 3px solid #262626;
padding: 0;
margin: 0;
background-color: #dedede;
font-family: "Times New Roman", sans-serif;
text-align: center;
width: 25%;
}}

.table_data_field_text {{
border: 3px solid #262626;
padding: 0;
margin: 0;
background-color: #dedede;
font-family: "Times New Roman", sans-serif;
text-align: left;
width: 75%;
}}

.text {{
text-align: center;
font-family: "Times New Roman", sans-serif;
}}
</style>
</head>
<body>
<h1 class="text">
Test Report
</h1>
{event_table}
</body>
</html>
""".strip()

event_table = \
r"""
<table class="main_table">
<thead>
<tr>
<th colspan="2" class="{table_head_class}">Test Report</th>
</tr>
</thead>
<tbody>
<tr>
<td class="table_data_field_title">function_name</td>
<td class="table_data_field_text">{function_name}</td>
</tr>
<tr>
<td class="table_data_field_title">param</td>
<td class="table_data_field_text">{param}</td>
</tr>
<tr>
<td class="table_data_field_title">time</td>
<td class="table_data_field_text">{time}</td>
</tr>
<tr>
<td class="table_data_field_title">exception</td>
<td class="table_data_field_text">{exception}</td>
</tr>
</tbody>
</table>
<br>
""".strip()


def make_html_table(event_str: str, record_data: dict, table_head: str):
event_str = "".join(
[
event_str,
event_table.format(
table_head_class=table_head,
function_name=record_data.get("function_name"),
param=record_data.get("local_param"),
time=record_data.get("time"),
exception=record_data.get("program_exception"),
)
]
)
return event_str


def generate_html(html_name: str = "default_name"):
"""
:param html_name: save html file name
:return: html_string
"""
if len(test_record.total_record_list) == 0:
raise HTMLException(html_generate_no_data_tag)
else:
event_str = ""
for record_data in test_record.total_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")
else:
event_str = make_html_table(event_str, record_data, "failure_table_head")
new_html_string = html_string.format(event_table=event_str)
try:
lock.acquire()
with open(html_name + ".html", "w+") as file_to_write:
file_to_write.write(
new_html_string
)
except Exception as error:
print(repr(error), file=sys.stderr)
finally:
lock.release()
return new_html_string
Loading