|
2 | 2 |
|
3 | 3 | import six |
4 | 4 |
|
5 | | - |
6 | | -class TestgresException(Exception): |
7 | | - pass |
| 5 | +from testgres.operations.exceptions import TestgresException |
| 6 | +from testgres.operations.exceptions import ExecUtilException |
| 7 | +from testgres.operations.exceptions import InvalidOperationException |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class PortForException(TestgresException): |
11 | 11 | pass |
12 | 12 |
|
13 | 13 |
|
14 | | -@six.python_2_unicode_compatible |
15 | | -class ExecUtilException(TestgresException): |
16 | | - def __init__(self, message=None, command=None, exit_code=0, out=None, error=None): |
17 | | - super(ExecUtilException, self).__init__(message) |
18 | | - |
19 | | - self.message = message |
20 | | - self.command = command |
21 | | - self.exit_code = exit_code |
22 | | - self.out = out |
23 | | - self.error = error |
24 | | - |
25 | | - def __str__(self): |
26 | | - msg = [] |
27 | | - |
28 | | - if self.message: |
29 | | - msg.append(self.message) |
30 | | - |
31 | | - if self.command: |
32 | | - command_s = ' '.join(self.command) if isinstance(self.command, list) else self.command, |
33 | | - msg.append(u'Command: {}'.format(command_s)) |
34 | | - |
35 | | - if self.exit_code: |
36 | | - msg.append(u'Exit code: {}'.format(self.exit_code)) |
37 | | - |
38 | | - if self.error: |
39 | | - msg.append(u'---- Error:\n{}'.format(self.error)) |
40 | | - |
41 | | - if self.out: |
42 | | - msg.append(u'---- Out:\n{}'.format(self.out)) |
43 | | - |
44 | | - return self.convert_and_join(msg) |
45 | | - |
46 | | - @staticmethod |
47 | | - def convert_and_join(msg_list): |
48 | | - # Convert each byte element in the list to str |
49 | | - str_list = [six.text_type(item, 'utf-8') if isinstance(item, bytes) else six.text_type(item) for item in |
50 | | - msg_list] |
51 | | - |
52 | | - # Join the list into a single string with the specified delimiter |
53 | | - return six.text_type('\n').join(str_list) |
54 | | - |
55 | | - |
56 | 14 | @six.python_2_unicode_compatible |
57 | 15 | class QueryException(TestgresException): |
58 | 16 | def __init__(self, message=None, query=None): |
@@ -109,5 +67,5 @@ class BackupException(TestgresException): |
109 | 67 | pass |
110 | 68 |
|
111 | 69 |
|
112 | | -class InvalidOperationException(TestgresException): |
113 | | - pass |
| 70 | +assert ExecUtilException.__name__ == "ExecUtilException" |
| 71 | +assert InvalidOperationException.__name__ == "InvalidOperationException" |
0 commit comments