More tests on table
This commit is contained in:
parent
8a97902762
commit
7c5779da80
@ -122,6 +122,10 @@ class Table(object):
|
|||||||
for row in rows:
|
for row in rows:
|
||||||
yield row
|
yield row
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
d = self.database.query(self.table.count()).next()
|
||||||
|
return d.values().pop()
|
||||||
|
|
||||||
def distinct(self, *columns, **kw):
|
def distinct(self, *columns, **kw):
|
||||||
qargs = []
|
qargs = []
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -27,6 +27,30 @@ class DatabaseTestCase(unittest.TestCase):
|
|||||||
assert r['num']==len(TEST_DATA), r
|
assert r['num']==len(TEST_DATA), r
|
||||||
|
|
||||||
|
|
||||||
|
class TableTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.db = connect('sqlite:///:memory:')
|
||||||
|
self.tbl = self.db['weather']
|
||||||
|
for row in TEST_DATA:
|
||||||
|
self.tbl.insert(row)
|
||||||
|
|
||||||
|
def test_insert(self):
|
||||||
|
assert len(self.tbl)==len(TEST_DATA), len(self.tbl)
|
||||||
|
self.tbl.insert({
|
||||||
|
'date': datetime(2011, 01, 02),
|
||||||
|
'temperature': -10,
|
||||||
|
'place': 'Berlin'}
|
||||||
|
)
|
||||||
|
assert len(self.tbl)==len(TEST_DATA)+1, len(self.tbl)
|
||||||
|
|
||||||
|
def test_distinct(self):
|
||||||
|
x = list(self.tbl.distinct('place'))
|
||||||
|
assert len(x)==2, x
|
||||||
|
x = list(self.tbl.distinct('place', 'date'))
|
||||||
|
assert len(x)==6, x
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user