Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv28189/tests
Modified Files:
test.py
Log Message:
Added iteration test
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** test.py 10 Jul 2003 19:25:47 -0000 1.20
--- test.py 17 Jul 2003 01:20:18 -0000 1.21
***************
*** 2,5 ****
--- 2,6 ----
from SQLObject import *
from mx import DateTime
+ from __future__ import generators
########################################
***************
*** 128,131 ****
--- 129,197 ----
('joe', 'robbins'), ('tim', 'jackson'),
('zoe', 'robbins')])
+
+ ########################################
+ ## Select results
+ ########################################
+
+ class IterTest(SQLObject):
+ name = StringCol()
+
+ class IterationTestCase(SQLObjectTest):
+ '''Test basic iteration techniques'''
+
+ classes = [IterTest]
+
+ names = ('a', 'b', 'c')
+
+ def inserts(self):
+ for name in self.names:
+ IterTest.new(name=name)
+
+ def test_00_normal(self):
+ count = 0
+ for test in IterTest.select():
+ count += 1
+ self.failIf(count != len(self.names))
+
+ def test_01_turn_to_list(self):
+ count = 0
+ for test in list(IterTest.select()):
+ count += 1
+ self.failIf(count != len(self.names))
+
+ def test_02_generator(self):
+ def enumerate(iterable):
+ i = 0
+ for obj in iterable:
+ yield i, obj
+ i += 1
+ all = IterTest.select()
+ count = 0
+ for i, test in enumerate(all):
+ count += 1
+ self.failIf(count != len(self.names))
+
+ def test_03_ranged_indexed(self):
+ all = IterTest.select()
+ count = 0
+ for i in range(len(all)):
+ test = all[i]
+ count += 1
+ self.failIf(count != len(self.names))
+
+ def test_04_indexed_ended_by_exception(self):
+ all = IterTest.select()
+ count = 0
+ try:
+ while 1:
+ test = all[count]
+ count = count+1
+ # Stop the test if it's gone on too long
+ if count > len(self.names):
+ break
+ except IndexError:
+ pass
+ self.failIf(count != len(self.names))
+
########################################
|