-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_exceptions.py
More file actions
40 lines (31 loc) · 1.21 KB
/
test_exceptions.py
File metadata and controls
40 lines (31 loc) · 1.21 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
import pytest
from sqlobject import SQLObject, StringCol
from sqlobject.dberrors import DatabaseError, DuplicateEntryError, \
OperationalError, ProgrammingError
from sqlobject.tests.dbtest import getConnection, raises, setupClass, supports
########################################
# Table aliases and self-joins
########################################
class SOTestException(SQLObject):
name = StringCol(unique=True, length=100)
class SOTestExceptionWithNonexistingTable(SQLObject):
pass
def test_exceptions():
if not supports("exceptions"):
pytest.skip("exceptions aren't supported")
setupClass(SOTestException)
SOTestException(name="test")
raises(DuplicateEntryError, SOTestException, name="test")
connection = getConnection()
SOTestExceptionWithNonexistingTable.setConnection(connection)
try:
list(SOTestExceptionWithNonexistingTable.select())
except ProgrammingError as e:
assert e.args[0].code in (1146, '42P01')
except OperationalError:
assert connection.dbName == 'sqlite'
except DatabaseError:
assert connection.dbName == 'postgres' \
and connection.driver == 'pg8000'
else:
assert False, "DID NOT RAISE"