-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_unicode.py
More file actions
84 lines (70 loc) · 2.48 KB
/
Copy pathtest_unicode.py
File metadata and controls
84 lines (70 loc) · 2.48 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
from sqlobject import IntCol, SQLObject, UnicodeCol
from sqlobject.compat import PY2
from sqlobject.tests.dbtest import setupClass
########################################
# Unicode columns
########################################
class SOTestUnicode(SQLObject):
so_count = IntCol(alternateID=True)
col = UnicodeCol(alternateID=True, length=100)
data = [u'\u00f0', u'test', 'ascii test']
items = []
def setup():
global items
items = []
setupClass(SOTestUnicode)
for i, s in enumerate(data):
items.append(SOTestUnicode(so_count=i, col=s))
def test_create():
setup()
for s, item in zip(data, items):
assert item.col == s
conn = SOTestUnicode._connection
if PY2:
rows = conn.queryAll("""
SELECT so_count, col
FROM so_test_unicode
ORDER BY so_count
""")
for so_count, col in rows:
if not isinstance(col, bytes):
col = col.encode('utf-8')
assert data[so_count].encode('utf-8') == col
else:
rows = conn.queryAll("""
SELECT so_count, col
FROM so_test_unicode
ORDER BY so_count
""")
# On python 3, everthings already decoded to unicode
for so_count, col in rows:
assert data[so_count] == col
def test_select():
setup()
for i, value in enumerate(data):
rows = list(SOTestUnicode.select(SOTestUnicode.q.col == value))
assert len(rows) == 1
if PY2:
rows = list(SOTestUnicode.select(SOTestUnicode.q.col == value))
assert len(rows) == 1
rows = list(SOTestUnicode.selectBy(col=value))
assert len(rows) == 1
if PY2:
rows = list(SOTestUnicode.selectBy(col=value))
assert len(rows) == 1
row = SOTestUnicode.byCol(value)
assert row.so_count == i
# starts/endswith/contains
rows = list(SOTestUnicode.select(SOTestUnicode.q.col.startswith("test")))
assert len(rows) == 1
rows = list(SOTestUnicode.select(SOTestUnicode.q.col.endswith("test")))
assert len(rows) == 2
rows = list(SOTestUnicode.select(SOTestUnicode.q.col.contains("test")))
assert len(rows) == 2
rows = list(SOTestUnicode.select(
SOTestUnicode.q.col.startswith(u"\u00f0")))
assert len(rows) == 1
rows = list(SOTestUnicode.select(SOTestUnicode.q.col.endswith(u"\u00f0")))
assert len(rows) == 1
rows = list(SOTestUnicode.select(SOTestUnicode.q.col.contains(u"\u00f0")))
assert len(rows) == 1