1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2022 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
19class TestAssertionError(Exception):
20    """
21    devicetest defined assertion class
22    """
23
24    def __init__(self, error_msg):
25        super(TestAssertionError, self).__init__(error_msg)
26        self.error_msg = error_msg
27
28    def __str__(self):
29        return str(self.error_msg)
30
31
32class RPCException(Exception):
33    def __init__(self, error_msg):
34        super(RPCException, self).__init__(error_msg)
35        self.error_msg = error_msg
36
37    def __str__(self):
38        return str(self.error_msg)
39
40
41class RPCAPIError(RPCException):
42    """Raised when remote API reports an error."""
43
44    def __init__(self, error_msg):
45        super(RPCAPIError, self).__init__(error_msg)
46        self.error_msg = error_msg
47
48    def __str__(self):
49        return str(self.error_msg)
50
51
52class DeccAgentError(Exception):
53    def __init__(self, error_msg):
54        super(DeccAgentError, self).__init__(error_msg)
55        self.error_msg = error_msg
56
57    def __str__(self):
58        return str(self.error_msg)
59
60
61class DeviceTestError(Exception):
62    def __init__(self, error_msg):
63        super(DeviceTestError, self).__init__(error_msg)
64        self.error_msg = error_msg
65
66    def __str__(self):
67        return str(self.error_msg)
68
69
70class BaseTestError(Exception):
71    """Raised for exceptions that occured in BaseTestClass.
72    """
73
74    def __init__(self, error_msg):
75        super(BaseTestError, self).__init__(error_msg)
76        self.error_msg = error_msg
77
78    def __str__(self):
79        return str(self.error_msg)
80
81
82class TestFailure(Exception):
83    """Raised when a check has failed."""
84
85    def __init__(self, error_msg):
86        super(TestFailure, self).__init__(error_msg)
87        self.error_msg = error_msg
88
89    def __str__(self):
90        return str(self.error_msg)
91
92
93class TestError(Exception):
94    """Raised when a step has failed."""
95
96    def __init__(self, error_msg):
97        super(TestError, self).__init__(error_msg)
98        self.error_msg = error_msg
99
100    def __str__(self):
101        return str(self.error_msg)
102
103
104class TestSkip(Exception):
105    """Raised when a test has been skipped."""
106
107    def __init__(self, error_msg):
108        super(TestSkip, self).__init__(error_msg)
109        self.error_msg = error_msg
110
111    def __str__(self):
112        return str(self.error_msg)
113
114
115class TestTerminated(Exception):
116    """Raised when a test has been stopped."""
117
118    def __init__(self, error_msg):
119        super(TestTerminated, self).__init__(error_msg)
120        self.error_msg = error_msg
121
122    def __str__(self):
123        return str(self.error_msg)
124
125
126class TestAbortManual(Exception):
127    """Raised when a manual abort occurs."""
128
129    def __init__(self, error_msg):
130        super(TestAbortManual, self).__init__(error_msg)
131        self.error_msg = error_msg
132
133    def __str__(self):
134        return str(self.error_msg)
135
136
137class TestPrepareError(Exception):
138    """raise exception when prepare error."""
139
140    def __init__(self, error_msg):
141        super(TestPrepareError, self).__init__(error_msg)
142        self.error_msg = error_msg
143
144    def __str__(self):
145        return str(self.error_msg)
146
147
148class DeviceNotFound(Exception):
149    """raise exception when device not found."""
150
151    def __init__(self, error_msg):
152        super(DeviceNotFound, self).__init__(error_msg)
153        self.error_msg = error_msg
154
155    def __str__(self):
156        return str(self.error_msg)
157
158
159class DeviceTestAppInstallError(Exception):
160    """
161    Failed to install the APP
162    """
163
164    def __init__(self, error_msg):
165        super(DeviceTestAppInstallError, self).__init__(error_msg)
166        self.error_msg = error_msg
167
168    def __str__(self):
169        return str(self.error_msg)
170
171
172class DeviceTestRpcNotRunningError(Exception):
173    """
174    RPC not running
175    """
176
177    def __init__(self, error_msg):
178        super(DeviceTestRpcNotRunningError, self).__init__(error_msg)
179        self.error_msg = error_msg
180
181    def __str__(self):
182        return str(self.error_msg)
183
184
185class DeviceTestHdcCommandRejectedException(Exception):
186    """
187    Failed to connect to the device:The device goes offline
188    """
189
190    def __init__(self, error_msg):
191        super(DeviceTestHdcCommandRejectedException, self).__init__(error_msg)
192        self.error_msg = error_msg
193
194    def __str__(self):
195        return str(self.error_msg)
196
197
198class DeviceTestShellCommandUnresponsiveException(Exception):
199    """
200    Running the connector command times out
201    """
202
203    def __init__(self, error_msg):
204        super(DeviceTestShellCommandUnresponsiveException,
205              self).__init__(error_msg)
206        self.error_msg = error_msg
207
208    def __str__(self):
209        return str(self.error_msg)
210
211
212class DoesNotExistError(Exception):
213    """
214    Viewnode is none
215    """
216
217    def __init__(self, error_msg):
218        super(DoesNotExistError, self).__init__(error_msg)
219        self.error_msg = error_msg
220
221    def __str__(self):
222        return str(self.error_msg)
223
224
225class CreateUiDriverFailError(Exception):
226
227    def __init__(self, error_msg):
228        super(CreateUiDriverFailError, self).__init__(error_msg)
229        self.error_msg = error_msg
230
231    def __str__(self):
232        return str(self.error_msg)
233
234
235class ConnectAccessibilityFailError(Exception):
236
237    def __init__(self, error_msg):
238        super(ConnectAccessibilityFailError, self).__init__(error_msg)
239        self.error_msg = error_msg
240
241    def __str__(self):
242        return str(self.error_msg)
243
244
245class ModuleNotAttributeError(Exception):
246    def __init__(self, error_msg):
247        super(ModuleNotAttributeError, self).__init__(error_msg)
248        self.error_msg = error_msg
249
250    def __str__(self):
251        return str(self.error_msg)
252
253
254try:
255    from xdevice import HdcCommandRejectedException
256except ImportError:
257    HdcCommandRejectedException = DeviceTestHdcCommandRejectedException
258try:
259    from xdevice import \
260        ShellCommandUnresponsiveException
261except ImportError:
262    ShellCommandUnresponsiveException = \
263        DeviceTestShellCommandUnresponsiveException
264try:
265    from xdevice import AppInstallError
266except ImportError:
267    AppInstallError = DeviceTestAppInstallError
268
269try:
270    from xdevice import RpcNotRunningError
271except ImportError:
272    RpcNotRunningError = DeviceTestRpcNotRunningError
273