1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2020-2024 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19from xdevice import Error, ErrorCategory
20
21
22class _CommonErr:
23    """Code_0201xxx,汇总常见的、未归类的问题"""
24    Code_0201001 = Error(**{"error": "File path does not exist, path: {}",
25                            "category": "{}",
26                            "code": "0201001"})
27    Code_0201002 = Error(**{"error": "Json file does not exist, file: {}",
28                            "category": ErrorCategory.Environment,
29                            "code": "0201002"})
30    Code_0201003 = Error(**{"error": "generate test report failed",
31                            "code": "0201003"})
32    Code_0201004 = Error(**{"error": "The test task is terminated abnormally",
33                            "code": "0201004",
34                            "suggestions": "测试任务被异常终止"})
35    Code_0201005 = Error(**{"error": "Failed to obtain the idle port",
36                            "category": ErrorCategory.Environment,
37                            "code": "0201005"})
38    Code_0201006 = Error(**{"error": "The source image for image comparison does not exist, source: {}",
39                            "category": ErrorCategory.Script,
40                            "code": "0201006"})
41    Code_0201007 = Error(**{"error": "The target image for image comparison does not exist, target: {}",
42                            "category": ErrorCategory.Script,
43                            "code": "0201007"})
44    Code_0201008 = Error(**{"error": "Resource file does not exist, file: {}",
45                            "category": ErrorCategory.Environment,
46                            "code": "0201008",
47                            "suggestions": "测试资源文件不存在"})
48    Code_0201009 = Error(**{"error": "Failed to write content to the file",
49                            "category": ErrorCategory.Environment,
50                            "code": "0201009"})
51    Code_0201010 = Error(**{"error": "Failed to read content from the file",
52                            "category": ErrorCategory.Environment,
53                            "code": "0201010"})
54    Code_0201011 = Error(**{"error": "Unsupported system environment",
55                            "category": ErrorCategory.Environment,
56                            "code": "0201011"})
57    Code_0201012 = Error(**{"error": "Syntax error in test specifier '{}'",
58                            "category": ErrorCategory.Environment,
59                            "code": "0201012"})
60    Code_0201013 = Error(**{"error": "Invalid test case name '{}'",
61                            "category": ErrorCategory.Environment,
62                            "code": "0201013"})
63    Code_0201014 = Error(**{"error": "Can't find prepare script '{}'",
64                            "category": ErrorCategory.Environment,
65                            "code": "0201014"})
66    Code_0201015 = Error(**{"error": "prepare script's setup step execution may be error",
67                            "category": ErrorCategory.Script,
68                            "code": "0201015"})
69    Code_0201016 = Error(**{"error": "prepare script's teardown step execution may be error",
70                            "category": ErrorCategory.Script,
71                            "code": "0201016"})
72    Code_0201017 = Error(**{"error": "Failed to instantiate the test runner",
73                            "code": "0201017"})
74
75
76class _DeviceErr:
77    """Code_0202xxx,归类rpc、uitest、测试设备等问题"""
78    Code_0202001 = Error(**{"error": "[{}] Reconnect to device rpc service is more than {} times, raise",
79                            "category": ErrorCategory.Environment,
80                            "code": "0202001"})
81    Code_0202002 = Error(**{"error": "Receive 0 byte, harmony abc rpc server is disconnected!",
82                            "category": ErrorCategory.Environment,
83                            "code": "0202002"})
84    Code_0202003 = Error(**{"error": "Receive 0 byte, harmony rpc server is disconnected!",
85                            "category": ErrorCategory.Environment,
86                            "code": "0202003"})
87    Code_0202004 = Error(**{"error": "Receive 0 byte, rpc server is disconnected!",
88                            "category": ErrorCategory.Environment,
89                            "code": "0202004"})
90    Code_0202005 = Error(**{"error": "install harmony {} rpc failed, reason: {}",
91                            "code": "0202005"})
92    Code_0202006 = Error(**{"error": "accessibility pid is not found",
93                            "category": ErrorCategory.Environment,
94                            "code": "0202006"})
95    Code_0202007 = Error(**{"error": "Fail to create inner UiDriver",
96                            "code": "0202007"})
97    Code_0202008 = Error(**{"error": "Fail to create UiDriver",
98                            "code": "0202008"})
99    Code_0202009 = Error(**{"error": "Fail to connect AAMS",
100                            "code": "0202009"})
101
102    # Code_02023xx,测试设备
103    Code_0202301 = Error(**{"error": "webview init failed",
104                            "code": "0202301"})
105    Code_0202302 = Error(**{"error": "Fail to connect to device, error: {}",
106                            "category": ErrorCategory.Environment,
107                            "code": "0202302",
108                            "suggestions": "无法连接设备或向设备发送指令,设备可能已断开连接"})
109    Code_0202303 = Error(**{"error": "Connector command execution timeout, error: {}",
110                            "category": ErrorCategory.Environment,
111                            "code": "0202303",
112                            "suggestions": "设备调试命令运行超时"})
113    Code_0202304 = Error(**{"error": "Connector command execution timeout, error: {}",
114                            "category": ErrorCategory.Environment,
115                            "code": "0202304",
116                            "suggestions": "设备调试命令运行超时"})
117    Code_0202305 = Error(**{"error": "device rpc process is not found",
118                            "category": ErrorCategory.Environment,
119                            "code": "0202305"})
120    Code_0202306 = Error(**{"error": "device cannot be found or is offline",
121                            "category": ErrorCategory.Environment,
122                            "code": "0202306"})
123    Code_0202307 = Error(**{"error": "Failed to install test app, error: {}",
124                            "category": ErrorCategory.Environment,
125                            "code": "0202307"})
126
127
128class _TestCaseErr:
129    """Code_0203xxx,归类用例、用例执行等问题"""
130    Code_0203001 = Error(**{"error": "Can't load file {}, error: {}",
131                            "category": ErrorCategory.Script,
132                            "code": "0203001",
133                            "suggestions": "1、测试用例导入模块失败;2、若导入的模块没有被使用,则删除对应的代码行"})
134    Code_0203002 = Error(**{"error": "{}",
135                            "category": ErrorCategory.Script,
136                            "code": "0203002"})
137    Code_0203003 = Error(**{"error": "Step {} result TestError!",
138                            "category": ErrorCategory.Script,
139                            "code": "0203003"})
140    Code_0203004 = Error(**{"error": "The self.tests variable of the test case is incorrectly assigned, "
141                                     "current assigned: {}",
142                            "category": ErrorCategory.Script,
143                            "code": "0203004",
144                            "suggestions": "测试用例的self.tests变量赋值异常,需将它赋值为用例文件里定义的测试方法"})
145    Code_0203005 = Error(**{"error": "传参错误!请用list列表传递待重试运行的用例信息",
146                            "code": "0203005"})
147    Code_0203006 = Error(**{"error": "ImportError occurred, error: {}",
148                            "category": ErrorCategory.Script,
149                            "code": "0203006",
150                            "suggestions": "Python三方库、AW接口等载入异常,导致用例执行失败"})
151    Code_0203007 = Error(**{"error": "Failed to initialize the device object in the TestCase",
152                            "code": "0203007"})
153    Code_0203008 = Error(**{"error": "The parameter type is incorrect, error: {}",
154                            "code": "0203008",
155                            "suggestions": "参数类型错误"})
156    Code_0203009 = Error(**{"error": "No device has assigned for test source",
157                            "code": "0203009",
158                            "suggestions": "测试用例未分配到设备资源"})
159    Code_0203010 = Error(**{"error": "No config file for test source '{}'",
160                            "category": ErrorCategory.Script,
161                            "code": "0203010"})
162    Code_0203011 = Error(**{"error": "No test list to run",
163                            "category": ErrorCategory.Script,
164                            "code": "0203011"})
165    Code_0203012 = Error(**{"error": "No test list found",
166                            "category": ErrorCategory.Script,
167                            "code": "0203012"})
168    Code_0203013 = Error(**{"error": "The field of [py_file] in file {}.json only support one item, now is {}",
169                            "category": ErrorCategory.Script,
170                            "code": "0203013",
171                            "suggestions": "测试用例json的py_file字段只能配置一个用例py"})
172    Code_0203014 = Error(**{"error": "The field of [testsuite] in file testsuite json is not set",
173                            "category": ErrorCategory.Script,
174                            "code": "0203014",
175                            "suggestions": "测试套json的testsuite字段未配置测试套py"})
176    Code_0203015 = Error(**{"error": "You can only use the loop decorator in a test case",
177                            "category": ErrorCategory.Script,
178                            "code": "0203015",
179                            "suggestions": "只能在测试用例里使用loop装饰器"})
180    Code_0203016 = Error(**{"error": "The file name of the test case must be the same as the class name",
181                            "category": ErrorCategory.Script,
182                            "code": "0203016",
183                            "suggestions": "测试用例的文件名与类名必须保持一致"})
184    Code_0203017 = Error(**{"error": "Failed to run the test suite, error: {}",
185                            "category": ErrorCategory.Script,
186                            "code": "0203017",
187                            "suggestions": "测试套运行失败"})
188
189
190class _AssertionErr:
191    """Code_0204xxx,断言错误提示"""
192    Code_0204001 = Error(**{"error": "{}",
193                            "category": ErrorCategory.Script,
194                            "code": "0204001",
195                            "suggestions": "自定义断言错误提示语"})
196    Code_0204002 = Error(**{"error": "断言错误:由'=='条件确定的两个对象的值不相等",
197                            "category": ErrorCategory.Script,
198                            "code": "0204002"})
199    Code_0204003 = Error(**{"error": "断言错误:由'!='条件确定的两个对象的值相等",
200                            "category": ErrorCategory.Script,
201                            "code": "0204003"})
202    Code_0204004 = Error(**{"error": "断言错误:检查对象不为false",
203                            "category": ErrorCategory.Script,
204                            "code": "0204004"})
205    Code_0204005 = Error(**{"error": "断言错误:检查对象不为true",
206                            "category": ErrorCategory.Script,
207                            "code": "0204005"})
208    Code_0204006 = Error(**{"error": "断言错误:两个对象的id不相同",
209                            "category": ErrorCategory.Script,
210                            "code": "0204006"})
211    Code_0204007 = Error(**{"error": "断言错误:两个对象的id相同",
212                            "category": ErrorCategory.Script,
213                            "code": "0204007"})
214    Code_0204008 = Error(**{"error": "断言错误:检查对象不为None",
215                            "category": ErrorCategory.Script,
216                            "code": "0204008"})
217    Code_0204009 = Error(**{"error": "断言错误:检查对象为None",
218                            "category": ErrorCategory.Script,
219                            "code": "0204009"})
220    Code_0204010 = Error(**{"error": "断言错误:检查对象不在对象容器中",
221                            "category": ErrorCategory.Script,
222                            "code": "0204010"})
223    Code_0204011 = Error(**{"error": "断言错误:检查对象在对象容器中",
224                            "category": ErrorCategory.Script,
225                            "code": "0204011"})
226    Code_0204012 = Error(**{"error": "断言错误:检查对象不是另一对象的实例",
227                            "category": ErrorCategory.Script,
228                            "code": "0204012"})
229    Code_0204013 = Error(**{"error": "断言错误:检查对象是另一对象的实例",
230                            "category": ErrorCategory.Script,
231                            "code": "0204013"})
232    Code_0204014 = Error(**{"error": "断言错误:",
233                            "category": ErrorCategory.Script,
234                            "code": "0204014"})
235    Code_0204015 = Error(**{"error": "断言错误:检查对象的值(四舍五入比较)几乎不等于另一对象的值",
236                            "category": ErrorCategory.Script,
237                            "code": "0204015"})
238    Code_0204016 = Error(**{"error": "断言错误:检查对象的值(四舍五入比较)几乎等于另一对象的值",
239                            "category": ErrorCategory.Script,
240                            "code": "0204016"})
241    Code_0204017 = Error(**{"error": "断言错误:检查对象的值小于另一对象的值",
242                            "category": ErrorCategory.Script,
243                            "code": "0204017"})
244    Code_0204018 = Error(**{"error": "断言错误:检查对象的值大于等于另一对象的值",
245                            "category": ErrorCategory.Script,
246                            "code": "0204018"})
247    Code_0204019 = Error(**{"error": "断言错误:检查对象的值大于另一对象的值",
248                            "category": ErrorCategory.Script,
249                            "code": "0204019"})
250    Code_0204020 = Error(**{"error": "断言错误:两个字典对象不相等",
251                            "category": ErrorCategory.Script,
252                            "code": "0204020"})
253    Code_0204021 = Error(**{"error": "断言错误:两个集合对象不相等",
254                            "category": ErrorCategory.Script,
255                            "code": "0204021"})
256    Code_0204022 = Error(**{"error": "断言错误:两个元组对象不相等",
257                            "category": ErrorCategory.Script,
258                            "code": "0204022"})
259    Code_0204023 = Error(**{"error": "断言错误:两个列表对象不相等",
260                            "category": ErrorCategory.Script,
261                            "code": "0204023"})
262    Code_0204024 = Error(**{"error": "断言错误:两个序列对象不相等",
263                            "category": ErrorCategory.Script,
264                            "code": "0204024"})
265    Code_0204025 = Error(**{"error": "断言错误:两个多行字符串不相等",
266                            "category": ErrorCategory.Script,
267                            "code": "0204025"})
268    Code_0204026 = Error(**{"error": "断言错误:Expect: {}, Actual: {}",
269                            "category": ErrorCategory.Script,
270                            "code": "0204026"})
271
272
273class ErrorMessage:
274    Common: _CommonErr = _CommonErr()
275    Device: _DeviceErr = _DeviceErr()
276    TestCase: _TestCaseErr = _TestCaseErr()
277    Assertion: _AssertionErr = _AssertionErr()
278