Skip to content

Commit e0e954e

Browse files
author
Evgeniy Sidenko
committed
Initial merge
0 parents  commit e0e954e

File tree

427 files changed

+41665
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

427 files changed

+41665
-0
lines changed

Examples/README.md

Lines changed: 14 additions & 0 deletions

Examples/RunExamples.py

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# Запускает все тесты из подкаталога
2+
# Входные параметры:
3+
# Автор: Сиденко Е.В.
4+
# Дата: 31.03.2023
5+
# Версия: 1.0
6+
import sys
7+
import os
8+
from aspose.imaging import License
9+
from datetime import datetime
10+
import re
11+
12+
src_dir = ""
13+
output_dir = ""
14+
data_dir = ""
15+
lic_file = ""
16+
group_code = 0
17+
group_filter = []
18+
file_name_filter = None
19+
save_output_files = False
20+
21+
22+
def fill_groups(groups: int) -> None:
23+
group_dict = {
24+
1: 'DRAWING_AND_FORMATTING_IMAGES',
25+
2: 'MODIFYING_AND_CONVERTING_IMAGES',
26+
4: 'MEMORY_STRATEGIES',
27+
8: 'ADDITIONAL_FEATURES',
28+
16: 'TEST_FILE_FORMATS'
29+
}
30+
31+
global group_filter
32+
33+
for key, value in group_dict.items():
34+
if groups & key != 0:
35+
group_filter.append(value)
36+
del group_dict
37+
38+
39+
def need_skip_by_name(file_path: str) -> bool:
40+
global file_name_filter
41+
if file_name_filter is None:
42+
return False
43+
return not file_name_filter.match(file_path)
44+
45+
46+
def need_skip_by_group(code_txt: str) -> bool:
47+
if group_filter == "":
48+
return False
49+
first_line = code_txt.split('\n', 1)[0]
50+
if first_line.startswith("# GROUP: "):
51+
group_name = first_line[8:].strip()
52+
if group_name in group_filter:
53+
return False
54+
elif 'MODIFYING_AND_CONVERTING_IMAGES' in group_filter:
55+
return False
56+
57+
return True
58+
59+
60+
def parse_args():
61+
length = len(sys.argv)
62+
if (length - 1) % 2 != 0:
63+
usage()
64+
exit()
65+
66+
params = {}
67+
68+
# get value or default
69+
def get_dict_value_def(p_name, p_default=""):
70+
p_value = params.get(p_name)
71+
return p_value if p_value is not None else p_default
72+
73+
for it in range(1, length, 2):
74+
t_name = sys.argv[it]
75+
value = sys.argv[it + 1]
76+
if not t_name.startswith('--'):
77+
usage()
78+
exit()
79+
params[t_name] = value
80+
81+
global src_dir, data_dir, output_dir, lic_file, save_output_files, \
82+
file_name_filter, group_code
83+
src_dir = os.path.abspath(get_dict_value_def('--src-dir', "src"))
84+
data_dir = os.path.abspath(get_dict_value_def('--data-dir', "data"))
85+
output_dir = os.path.abspath(get_dict_value_def('--output-dir', "output"))
86+
lic_file = get_dict_value_def('--license')
87+
group_filter_str = get_dict_value_def('--groups', '255')
88+
file_name_filter_str = get_dict_value_def('--file-filter')
89+
save_output_files = get_dict_value_def('--save-output', 'false').lower() == 'true'
90+
91+
if file_name_filter_str != "":
92+
file_name_filter = re.compile(file_name_filter_str)
93+
94+
group_code = int(group_filter_str)
95+
fill_groups(group_code)
96+
97+
del params, file_name_filter_str, group_filter_str
98+
99+
100+
def usage():
101+
print("Using:")
102+
print("python", sys.argv[0], "Arguments")
103+
print("Arguments:")
104+
print(" --src-dir <path to the root example dir>")
105+
print(" Default: ./src")
106+
print(" --data-dir <path to the root data dir>")
107+
print(" Default: ./data")
108+
print(" --output-dir <path to the output dir>")
109+
print(" Default: ./output")
110+
print(" --license <path to a license file>")
111+
print(" Default: No license")
112+
print(" --save-output (true/false)")
113+
print(" Default: false")
114+
print(" --groups groups-flag")
115+
print(" groups-flag can contains the following bit masks")
116+
print(" 1 - Test drawing and formatting images")
117+
print(" 2 - Test modifying and converting images")
118+
print(" 4 - Test of memory strategies")
119+
print(" 8 - Test additional Aspose.Imaging features")
120+
print(" 16 - Test file formats")
121+
print(" Default: All")
122+
print(" --file-filter 'regex'")
123+
print(" Default: All files")
124+
print(" --help")
125+
126+
127+
# Process the arguments
128+
parse_args()
129+
130+
# Validate the paths
131+
if not os.path.exists(src_dir):
132+
print("Does not exists path:", src_dir)
133+
usage()
134+
exit()
135+
136+
if not os.path.exists(data_dir):
137+
print("Does not exists path:", data_dir)
138+
usage()
139+
exit()
140+
141+
if not os.path.exists(output_dir):
142+
os.mkdir(output_dir)
143+
144+
# Set license if it exists
145+
if len(lic_file) > 0 and lic_file != "none":
146+
lic = License()
147+
lic.set_license(lic_file)
148+
149+
150+
# function loads the source code for executing
151+
def load_example(file_name):
152+
with open(file_name, "rb") as s_file:
153+
pref = s_file.read(3)
154+
155+
with open(file_name, "rt") as s_file:
156+
# if we have a BOM then skip it
157+
if pref[0] == 0xef and pref[1] == 0xbb and pref[2] == 0xbf:
158+
s_file.seek(3)
159+
s_code = s_file.read()
160+
161+
return s_code
162+
163+
164+
def get_data_root_dir():
165+
return data_dir
166+
167+
168+
def get_output_dir():
169+
return output_dir
170+
171+
172+
globals_parameter = {'get_data_root_dir': get_data_root_dir, 'get_output_dir': get_output_dir}
173+
174+
src_dir_len = len(src_dir) + 1
175+
file_count = 0
176+
177+
os.environ['TEMPLATE_DIR'] = data_dir
178+
if save_output_files:
179+
os.environ['SAVE_OUTPUT'] = "1"
180+
181+
error_tests = {}
182+
183+
184+
def print_header(text):
185+
print("|--------------------------------------------------")
186+
print("|", datetime.now())
187+
print("|", text)
188+
print("|--------------------------------------------------")
189+
190+
191+
start_time = datetime.now()
192+
193+
print_header("STARTING...")
194+
195+
# Run all examples
196+
for root, dirs, files in os.walk(src_dir):
197+
for name in files:
198+
if not name.endswith(".py"):
199+
continue
200+
src_file = os.path.join(root, name)
201+
if need_skip_by_name(src_file):
202+
continue
203+
code = load_example(src_file)
204+
if need_skip_by_group(code):
205+
continue
206+
print_header("RUN FILE: " + src_file[src_dir_len:])
207+
file_count += 1
208+
try:
209+
exec(code, globals_parameter, None)
210+
except Exception as ex:
211+
error_tests[src_file] = ex
212+
213+
err_count = len(error_tests)
214+
print("|--------------------------------------------------")
215+
if err_count == 0:
216+
print_header(f"\n| FINISHED! NO ERROR WAS FOUND!\n| PROCESSED: {file_count} FILES.\n|")
217+
else:
218+
print_header(f"FINISHED WITH ERRORS! PROCESSED {file_count} files.")
219+
print("| ERROR COUNT", err_count)
220+
print("| ERROR LIST:")
221+
index = 1
222+
for file, error in error_tests.items():
223+
print(f"| {index} - {file}")
224+
print("| ", error)
225+
index += 1
226+
print("|--------------------------------------------------")
227+
228+
print("|", "PROCESSING TIME:", (datetime.now() - start_time))
39.1 KB
Binary file not shown.
13.9 KB
Binary file not shown.
10.4 KB
1.65 KB

Examples/data/DrawingAndFormattingImages/asposenet_220_src02.DrawImage.svg

Lines changed: 18 additions & 0 deletions
1.65 KB
706 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)