Skip to content

Commit a0583f4

Browse files
authored
Merge pull request #23 from JE-Chen/dev
Dev
2 parents 80800f7 + 277085e commit a0583f4

File tree

37 files changed

+739
-296
lines changed

37 files changed

+739
-296
lines changed

.circleci/config.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ version: 2.1
22

33
orbs:
44
windows: circleci/[email protected]
5-
macos: circleci/[email protected]
65
python: circleci/[email protected]
76

87
jobs:
@@ -63,6 +62,9 @@ jobs:
6362
- run:
6463
command: python ./test/unit_test/record/record_test.py
6564
name: record_test
65+
- run:
66+
command: python ./test/unit_test/total_record_test/total_record_test.py
67+
name: total_record_test
6668
# execute
6769
- run:
6870
command: python ./test/unit_test/execute_action/execute_action_test.py
@@ -91,6 +93,11 @@ jobs:
9193
command: python ./test/unit_test/argparse/argparse_test.py
9294
name: argparse_test
9395

96+
# integrated_test
97+
- run:
98+
command: python ./test/integrated_test/total_record_and_html_report_test/total_record_and_html_report_test.py
99+
name: total_record_and_html_report_test
100+
94101
build-and-test-windows-stable:
95102
executor:
96103
name: windows/default
@@ -104,7 +111,7 @@ jobs:
104111
name: pip install --upgrade --user pip setuptools wheel
105112
# pip require package
106113
- run:
107-
command: pip install --user -r dev_requirements.txt
114+
command: pip install --user -r requirements.txt
108115
name: pip dev_requirements.txt
109116
# screen test
110117
- run:
@@ -148,6 +155,9 @@ jobs:
148155
- run:
149156
command: python ./test/unit_test/record/record_test.py
150157
name: record_test
158+
- run:
159+
command: python ./test/unit_test/total_record_test/total_record_test.py
160+
name: total_record_test
151161
# execute
152162
- run:
153163
command: python ./test/unit_test/execute_action/execute_action_test.py
@@ -176,6 +186,11 @@ jobs:
176186
command: python ./test/unit_test/argparse/argparse_test.py
177187
name: argparse_test
178188

189+
# integrated_test
190+
- run:
191+
command: python ./test/integrated_test/total_record_and_html_report_test/total_record_and_html_report_test.py
192+
name: total_record_and_html_report_test
193+
179194
workflows:
180195
main:
181196
jobs:

.idea/workspace.xml

Lines changed: 65 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev_setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="je_auto_control_dev",
8-
version="0.0.08",
8+
version="0.0.14",
99
author="JE-Chen",
1010
author_email="[email protected]",
1111
description="auto testing",
@@ -34,3 +34,5 @@
3434

3535
# python dev_setup.py sdist bdist_wheel
3636
# python -m twine upload dist/*
37+
38+

docs/source/example/executor_example/execute_action.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ AutoControlGUI Execute action
7171
]
7272
print("\n\n")
7373
execute_action(test_list)
74-
print(test_record.record_list)
75-
print(test_record.error_record_list)
74+
7675
7776
7877

je_auto_control/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@
5757
# timeout
5858
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
5959
# test record
60-
from je_auto_control.utils.test_record.record_test_result_class import test_record
60+
from je_auto_control.utils.test_record.record_test_class import test_record
6161

6262
# utils image
6363
from je_auto_control.wrapper.auto_control_image import screenshot
6464

65+
# html report
66+
67+
from je_auto_control.utils.html_report.html_report_generate import generate_html

je_auto_control/utils/exception/exception_tag.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
linux_import_error = "should be only loaded on linux"
66
osx_import_error = "should be only loaded on MacOS"
77
windows_import_error = "should be only loaded on windows"
8-
macos_record_error = "macos can't use recorder"
8+
macos_record_error = "macos cant use recorder"
99
# keyboard tags
1010
keyboard_error = "Auto control keyboard error"
1111
keyboard_press_key = "keyboard press key error"
1212
keyboard_release_key = "keyboard release key error"
1313
keyboard_type_key = "keyboard type key error"
1414
keyboard_write = "keyboard write error"
15-
keyboard_write_cant_find = "keyboard write error can't find key"
15+
keyboard_write_cant_find = "keyboard write error cant find key"
1616
keyboard_hotkey = "keyboard hotkey error"
1717
# mouse tags
1818
mouse_error = "Auto control mouse error"
@@ -28,19 +28,21 @@
2828
screen_get_size = "screen get size error"
2929
screen_screenshot = "screen screenshot error"
3030
# table tags
31-
table_cant_find_key = "can't find key error"
31+
table_cant_find_key = "cant find key error"
3232
# image tags
33-
cant_find_image = "can't find image"
33+
cant_find_image = "cant find image"
3434
find_image_error_variable = "variable error"
3535
# listener tags
3636
listener_error = "Auto control listener error"
3737
# test_record tags
38-
record_queue_error = "can't get test_record queue it's none are you using stop test_record before test_record"
38+
record_queue_error = "cant get test_record queue its none are you using stop test_record before test_record"
3939
record_not_found_action_error = "test_record action not found"
4040
# json action file tag
41-
cant_execute_action_error = "can't execute action"
42-
cant_find_json_error = "can't find json file"
43-
cant_save_json_error = "can't save json file"
41+
cant_execute_action_error = "cant execute action"
42+
cant_find_json_error = "cant find json file"
43+
cant_save_json_error = "cant save json file"
4444
action_is_null_error = "json action is null"
4545
# timeout tag
4646
timeout_need_on_main_error = "should put timeout function on main"
47+
# HTML
48+
html_generate_no_data_tag = "record is None"

je_auto_control/utils/exception/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,11 @@ class AutoControlActionException(AutoControlException):
6060
# timeout
6161
class AutoControlTimeoutException(AutoControlException):
6262
pass
63+
64+
65+
# html exception
66+
67+
class HTMLException(AutoControlException):
68+
pass
69+
70+

je_auto_control/utils/executor/action_executor.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
from je_auto_control import AutoControlActionException
32
from je_auto_control import AutoControlActionNullException
43
from je_auto_control import check_key_is_press
54
from je_auto_control import click_mouse
@@ -25,7 +24,7 @@
2524
from je_auto_control.utils.exception.exception_tag import cant_execute_action_error
2625
from je_auto_control.utils.exception.exceptions import AutoControlActionException
2726

28-
from je_auto_control.utils.test_record.record_test_result_class import test_record
27+
from je_auto_control.utils.test_record.record_test_class import record_total
2928

3029
event_dict = {
3130
# mouse
@@ -57,33 +56,33 @@
5756
}
5857

5958

60-
def execute_event(action: list):
61-
event = event_dict.get(action[0])
62-
if len(action) == 2:
63-
event(**action[1])
64-
elif len(action) == 1:
65-
event()
66-
else:
67-
raise AutoControlActionException(cant_execute_action_error)
68-
69-
7059
def execute_action(action_list: list):
7160
"""
7261
use to execute all action on action list(action file or program list)
7362
:param action_list the list include action
7463
for loop the list and execute action
7564
"""
7665
execute_record_string = ""
77-
if action_list is None:
78-
raise AutoControlActionNullException(action_is_null_error)
79-
for action in action_list:
80-
try:
81-
execute_event(action)
82-
temp_string = "execute: " + str(action)
83-
print(temp_string)
84-
test_record.record_list.append(temp_string)
85-
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
86-
except Exception as error:
87-
print(repr(error), file=sys.stderr)
88-
test_record.error_record_list.append([action, repr(error)])
66+
try:
67+
if action_list is None:
68+
raise AutoControlActionNullException(action_is_null_error)
69+
for action in action_list:
70+
event = event_dict.get(action[0])
71+
if len(action) == 2:
72+
param = action[1]
73+
event(**action[1])
74+
elif len(action) == 1:
75+
param = None
76+
event()
77+
else:
78+
raise AutoControlActionException(cant_execute_action_error)
79+
try:
80+
temp_string = "execute: " + str(action)
81+
print(temp_string)
82+
record_total(action[0], param)
83+
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
84+
except AutoControlActionException as error:
85+
record_total(action[0], param, repr(error))
86+
except Exception as error:
87+
print(repr(error), file=sys.stderr)
8988
return execute_record_string

je_auto_control/utils/html_report/__init__.py

Whitespace-only changes.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import sys
2+
3+
from je_auto_control.utils.test_record.record_test_class import test_record
4+
from je_auto_control.utils.exception.exceptions import HTMLException
5+
from je_auto_control.utils.exception.exception_tag import html_generate_no_data_tag
6+
from threading import Lock
7+
8+
lock = Lock()
9+
10+
html_string = \
11+
r"""
12+
<!DOCTYPE html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="UTF-8"/>
16+
<title>AutoControl Report</title>
17+
18+
<style>
19+
20+
body{{
21+
font-size: 100%;
22+
}}
23+
24+
h1{{
25+
font-size: 2em;
26+
}}
27+
28+
.main_table {{
29+
margin: 0 auto;
30+
border-collapse: collapse;
31+
width: 75%;
32+
font-size: 1.5em;
33+
}}
34+
35+
.event_table_head {{
36+
border: 3px solid #262626;
37+
background-color: aqua;
38+
font-family: "Times New Roman", sans-serif;
39+
text-align: center;
40+
}}
41+
42+
.failure_table_head {{
43+
border: 3px solid #262626;
44+
background-color: #f84c5f;
45+
font-family: "Times New Roman", sans-serif;
46+
text-align: center;
47+
}}
48+
49+
.table_data_field_title {{
50+
border: 3px solid #262626;
51+
padding: 0;
52+
margin: 0;
53+
background-color: #dedede;
54+
font-family: "Times New Roman", sans-serif;
55+
text-align: center;
56+
width: 25%;
57+
}}
58+
59+
.table_data_field_text {{
60+
border: 3px solid #262626;
61+
padding: 0;
62+
margin: 0;
63+
background-color: #dedede;
64+
font-family: "Times New Roman", sans-serif;
65+
text-align: left;
66+
width: 75%;
67+
}}
68+
69+
.text {{
70+
text-align: center;
71+
font-family: "Times New Roman", sans-serif;
72+
}}
73+
</style>
74+
</head>
75+
<body>
76+
<h1 class="text">
77+
Test Report
78+
</h1>
79+
{event_table}
80+
</body>
81+
</html>
82+
""".strip()
83+
84+
event_table = \
85+
r"""
86+
<table class="main_table">
87+
<thead>
88+
<tr>
89+
<th colspan="2" class="{table_head_class}">Test Report</th>
90+
</tr>
91+
</thead>
92+
<tbody>
93+
<tr>
94+
<td class="table_data_field_title">function_name</td>
95+
<td class="table_data_field_text">{function_name}</td>
96+
</tr>
97+
<tr>
98+
<td class="table_data_field_title">param</td>
99+
<td class="table_data_field_text">{param}</td>
100+
</tr>
101+
<tr>
102+
<td class="table_data_field_title">time</td>
103+
<td class="table_data_field_text">{time}</td>
104+
</tr>
105+
<tr>
106+
<td class="table_data_field_title">exception</td>
107+
<td class="table_data_field_text">{exception}</td>
108+
</tr>
109+
</tbody>
110+
</table>
111+
<br>
112+
""".strip()
113+
114+
115+
def make_html_table(event_str: str, record_data: dict, table_head: str):
116+
event_str = "".join(
117+
[
118+
event_str,
119+
event_table.format(
120+
table_head_class=table_head,
121+
function_name=record_data.get("function_name"),
122+
param=record_data.get("local_param"),
123+
time=record_data.get("time"),
124+
exception=record_data.get("program_exception"),
125+
)
126+
]
127+
)
128+
return event_str
129+
130+
131+
def generate_html(html_name: str = "default_name"):
132+
"""
133+
:param html_name: save html file name
134+
:return: html_string
135+
"""
136+
if len(test_record.total_record_list) == 0:
137+
raise HTMLException(html_generate_no_data_tag)
138+
else:
139+
event_str = ""
140+
for record_data in test_record.total_record_list:
141+
# because data on record_data all is str
142+
if record_data.get("program_exception") == "None":
143+
event_str = make_html_table(event_str, record_data, "event_table_head")
144+
else:
145+
event_str = make_html_table(event_str, record_data, "failure_table_head")
146+
new_html_string = html_string.format(event_table=event_str)
147+
try:
148+
lock.acquire()
149+
with open(html_name + ".html", "w+") as file_to_write:
150+
file_to_write.write(
151+
new_html_string
152+
)
153+
except Exception as error:
154+
print(repr(error), file=sys.stderr)
155+
finally:
156+
lock.release()
157+
return new_html_string

0 commit comments

Comments
 (0)