-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_sqlite.py
More file actions
106 lines (83 loc) · 3.42 KB
/
test_sqlite.py
File metadata and controls
106 lines (83 loc) · 3.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import threading
from sqlobject import *
from sqlobject.tests.dbtest import *
from sqlobject.tests.dbtest import setSQLiteConnectionFactory
from test_basic import TestSO1
class SQLiteFactoryTest(SQLObject):
name = StringCol()
def test_sqlite_factory():
setupClass(SQLiteFactoryTest)
if SQLiteFactoryTest._connection.dbName == "sqlite":
if not SQLiteFactoryTest._connection.using_sqlite2:
return
factory = [None]
def SQLiteConnectionFactory(sqlite):
class MyConnection(sqlite.Connection):
pass
factory[0] = MyConnection
return MyConnection
setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)
conn = SQLiteFactoryTest._connection.makeConnection()
assert factory[0]
assert isinstance(conn, factory[0])
def test_sqlite_factory_str():
setupClass(SQLiteFactoryTest)
if SQLiteFactoryTest._connection.dbName == "sqlite":
if not SQLiteFactoryTest._connection.using_sqlite2:
return
factory = [None]
def SQLiteConnectionFactory(sqlite):
class MyConnection(sqlite.Connection):
pass
factory[0] = MyConnection
return MyConnection
from sqlobject.sqlite import sqliteconnection
sqliteconnection.SQLiteConnectionFactory = SQLiteConnectionFactory
setSQLiteConnectionFactory(SQLiteFactoryTest, "SQLiteConnectionFactory")
conn = SQLiteFactoryTest._connection.makeConnection()
assert factory[0]
assert isinstance(conn, factory[0])
del sqliteconnection.SQLiteConnectionFactory
def test_sqlite_aggregate():
setupClass(SQLiteFactoryTest)
if SQLiteFactoryTest._connection.dbName == "sqlite":
if not SQLiteFactoryTest._connection.using_sqlite2:
return
def SQLiteConnectionFactory(sqlite):
class MyConnection(sqlite.Connection):
def __init__(self, *args, **kwargs):
super(MyConnection, self).__init__(*args, **kwargs)
self.create_aggregate("group_concat", 1, self.group_concat)
class group_concat:
def __init__(self):
self.acc = []
def step(self, value):
if isinstance(value, basestring):
self.acc.append(value)
else:
self.acc.append(str(value))
def finalize(self):
self.acc.sort()
return ", ".join(self.acc)
return MyConnection
setSQLiteConnectionFactory(SQLiteFactoryTest, SQLiteConnectionFactory)
SQLiteFactoryTest(name='sqlobject')
SQLiteFactoryTest(name='sqlbuilder')
assert SQLiteFactoryTest.select(orderBy="name").accumulateOne("group_concat", "name") == \
"sqlbuilder, sqlobject"
def do_select():
list(TestSO1.select())
def test_sqlite_threaded():
setupClass(TestSO1)
t = threading.Thread(target=do_select)
t.start()
t.join()
# This should reuse the same connection as the connection
# made above (at least will with most database drivers, but
# this will cause an error in SQLite):
do_select()
def test_empty_string():
setupClass(TestSO1)
test = TestSO1(name=None, passwd='')
assert test.name is None
assert test.passwd == ''