summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Vasile <james@hackervisions.org>2011-11-22 19:10:07 -0500
committerJames Vasile <james@hackervisions.org>2011-11-22 19:10:07 -0500
commit15f9ded0c9a5345fbb61a8204d0958aa83399de5 (patch)
tree02b74eb8bec0297d4413914d3913dd070ffb909a
parent5cf233967aba413a9cb8a52120f5291ddcc7f02d (diff)
proper tests
-rw-r--r--withsqlite.py79
1 files changed, 60 insertions, 19 deletions
diff --git a/withsqlite.py b/withsqlite.py
index 89ff51a..4281a5e 100644
--- a/withsqlite.py
+++ b/withsqlite.py
@@ -50,6 +50,64 @@ a.popitem() remove and return an arbitrary (key, value) pair
a.iteritems() return an iterator over (key, value) pairs
a.iterkeys() return an iterator over the mapping's keys
a.itervalues() return an iterator over the mapping's values
+
+>>> with sqlite_db("test") as db:
+... db.clear()
+... db.items()
+...
+[]
+>>> with sqlite_db("test") as db:
+... db['a']="test"
+... db.items()
+...
+[(u'a', u'test')]
+>>> with sqlite_db("test") as db:
+... db['as']="test"
+... db.items()
+...
+[(u'a', u'test'), (u'as', u'test')]
+>>> with sqlite_db("test") as db:
+... db['b']=[1,2,3,4,5]
+... del db['b']
+...
+>>> with sqlite_db("test") as db:
+... db.items()
+... len(db)
+...
+[(u'a', u'test'), (u'as', u'test')]
+2
+>>> with sqlite_db("test") as db:
+... db.keys()
+...
+[u'a', u'as']
+>>> with sqlite_db("test") as db:
+... db.values()
+...
+[u'test', u'test']
+>>> with sqlite_db("test") as db:
+... db.get('b',5)
+...
+5
+>>> with sqlite_db("test") as db:
+... db.get('b')
+...
+>>> with sqlite_db("test") as db:
+... db.get('c',5)
+...
+5
+>>> with sqlite_db("test") as db:
+... 'as' in db
+...
+True
+>>> with sqlite_db("test") as db:
+... 'asdf' not in db
+...
+True
+>>> with sqlite_db("test") as db:
+... db.has_key('as')
+...
+True
+>>>
"""
def __init__(self, fname):
@@ -129,22 +187,5 @@ a.itervalues() return an iterator over the mapping's values
self.crsr.execute("delete from store")
if __name__=="__main__":
- ## This would really be better as proper tests
- with sqlite_db("test") as db:
- db.clear()
- db['a']="test"
- db['as']="test"
- db['b']=[1,2,3,4,5]
- db['c']=[1,2,3,4,5]
- db['d']="who?"
- del db['b']
- print len(db)
- print db.keys()
- print db.values()
- print db.items()
- print db.get('b',5)
- print db.get('b')
- print db.get('c',5)
- print 'as' in db
- print 'asdf' not in db
- print db.has_key('as')
+ import doctest
+ doctest.testmod()