forked from postgrespro/testgres.common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
56 lines (46 loc) · 1.42 KB
/
exceptions.py
File metadata and controls
56 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding: utf-8
import typing
class TestgresException(Exception):
@property
def message(self) -> str:
assert isinstance(self, TestgresException)
r = super().__str__()
assert r is not None
assert type(r) is str
return r
@property
def source(self) -> typing.Optional[str]:
assert isinstance(self, TestgresException)
return None
def __str__(self) -> str:
r = self.message
assert type(r) is str
return r
class InvalidOperationException(TestgresException):
_message: str
_source: typing.Optional[str]
def __init__(self, message: str, source: typing.Optional[str] = None):
assert type(message) is str
assert source is None or type(source) is str
super().__init__()
self._message = message
self._source = source
return
@property
def message(self) -> str:
assert type(self._message) is str
return self._message
@property
def source(self) -> typing.Optional[str]:
assert self._source is None or type(self._source) is str
return self._source
def __repr__(self) -> str:
# It must be overrided!
assert type(self) is InvalidOperationException
r = "{}({}, {})".format(
__class__.__name__,
repr(self._message),
repr(self._source),
)
assert type(r) is str
return r