-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_slice.py
More file actions
59 lines (41 loc) · 1.53 KB
/
Copy pathtest_slice.py
File metadata and controls
59 lines (41 loc) · 1.53 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
import pytest
from sqlobject import IntCol, SQLObject
from sqlobject.tests.dbtest import setupClass, supports
########################################
# Slicing tests
########################################
def listrange(*args):
"""Always return a list, for py3k compatibility"""
return list(range(*args))
class Counter(SQLObject):
number = IntCol(notNull=True)
class TestSlice:
def setup_method(self, meth):
setupClass(Counter)
for i in range(100):
Counter(number=i)
def counterEqual(self, counters, value):
if not supports('limitSelect'):
pytest.skip("limitSelect isn't supported")
assert [c.number for c in counters] == value
def test_slice(self):
self.counterEqual(
Counter.select(None, orderBy='number'), listrange(100))
self.counterEqual(
Counter.select(None, orderBy='number')[10:20],
listrange(10, 20))
self.counterEqual(
Counter.select(None, orderBy='number')[20:30][:5],
listrange(20, 25))
self.counterEqual(
Counter.select(None, orderBy='number')[20:30][1:5],
listrange(21, 25))
self.counterEqual(
Counter.select(None, orderBy='number')[:-10],
listrange(0, 90))
self.counterEqual(
Counter.select(None, orderBy='number', reversed=True),
listrange(99, -1, -1))
self.counterEqual(
Counter.select(None, orderBy='-number'),
listrange(99, -1, -1))