Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
singlestore-labs
GitHub Repository: singlestore-labs/singlestoredb-python
Path: blob/main/singlestoredb/tests/test_exceptions.py
469 views
1
#!/usr/bin/env python
2
# type: ignore
3
"""Test SingleStoreDB exceptions."""
4
import unittest
5
6
import singlestoredb as s2
7
8
9
class TestExceptions(unittest.TestCase):
10
11
def test_str(self):
12
exc = s2.Error()
13
assert str(exc) == 'Unknown error', str(exc)
14
15
exc = s2.Error(errno=1)
16
assert str(exc) == '1', str(exc)
17
18
exc = s2.Error(msg='hi there')
19
assert str(exc) == 'hi there', str(exc)
20
21
exc = s2.Error(errno=1, msg='hi there')
22
assert str(exc) == '1: hi there', str(exc)
23
24
exc = s2.Error(errno=1, msg='hi there', sqlstate=9)
25
assert str(exc) == '1 (9): hi there'
26
27
exc = s2.Error(msg='hi there', sqlstate=9)
28
assert str(exc) == '(9): hi there'
29
30
exc = s2.Error(sqlstate=9)
31
assert str(exc) == '(9)'
32
33
def test_repr(self):
34
exc = s2.Error(errno=1, msg='hi there')
35
assert str(exc) == '1: hi there', str(exc)
36
assert str(exc) == repr(exc)
37
38
def test_msg(self):
39
exc = s2.Error(errno=1, msg='hi there')
40
assert exc.msg == exc.errmsg
41
42
43
if __name__ == '__main__':
44
import nose2
45
nose2.main()
46
47