Update of /cvsroot/myoledb/myoledb3/test
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19474
Modified Files:
test_dbapi.py
Log Message:
added setup and teardown methods to drop tables to ensure consistency
moved repeat query test over from test_bugs.py
Index: test_dbapi.py
===================================================================
RCS file: /cvsroot/myoledb/myoledb3/test/test_dbapi.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_dbapi.py 28 Jun 2006 10:59:33 -0000 1.5
+++ test_dbapi.py 28 Jun 2006 11:07:34 -0000 1.6
@@ -26,30 +26,50 @@
cursor.execute(query)
return cursor
- def test_simple(self):
- """runs a simple insert and checks that a select returns the expected results"""
+ def setup_method(self, method):
+ """ensures table for test method doesn't exist"""
+ self.tablename = method.__name__
+ self.safedrop(self.tablename)
+
+ def teardown_method(self, method):
+ """ensures method table is dropped"""
+ self.safedrop(self.tablename)
+
+ def safedrop(self, tablename):
+ """drops the given table name, ignoring errors"""
try:
- self.execute_query("drop table test_simple")
+ self.execute_query("drop table %s" % tablename)
except Exception, e:
pass
- self.execute_query("create table test_simple(x text, y text)")
- self.execute_query("insert into test_simple(x, y) values('test', 'me')")
- results = self.execute_query("select x, y from test_simple").fetchall()
+
+ def test_simple(self):
+ """runs a simple insert and checks that a select returns the expected results"""
+ self.execute_query("create table %s(x text, y text)" % self.tablename)
+ self.execute_query("insert into %s(x, y) values('test', 'me')" % self.tablename)
+ results = self.execute_query("select x, y from %s" % self.tablename).fetchall()
assert len(results) == 1
assert list(results[0]) == ["test", "me"]
def test_count_type(self):
"""checks that select count(*) returns an integer"""
- try:
- self.execute_query("drop table test_count_type")
- except Exception, e:
- pass
- self.execute_query("create table test_count_type(x text, y text)")
- self.execute_query("insert into test_count_type(x, y) values('test', 'me')")
- results = self.execute_query("select count(*) from test_count_type").fetchall()
+ self.execute_query("create table %s(x text, y text)" % self.tablename)
+ self.execute_query("insert into %s(x, y) values('test', 'me')" % self.tablename)
+ results = self.execute_query("select count(*) from %s" % self.tablename).fetchall()
assert len(results) == 1
assert list(results[0]) == [1]
+ def test_repeat_query(self):
+ """tests that running the same query twice produces the same number of rows"""
+ self.execute_query("create table %s(x char(20), y char(20));" % self.tablename)
+ insertsql = "insert into %s(x, y) values('test', 'me');" % self.tablename
+ for n in range(5):
+ self.execute_query(insertsql)
+ selectsql = "select * from %s" % self.tablename
+ resultset1 = self.execute_query(selectsql).fetchall()
+ resultset2 = self.execute_query(selectsql).fetchall()
+ assert len(resultset1) == len(resultset2) == 5
+ assert resultset1 == resultset2
+
class Test_MySQLdb(MySqlTester):
"""Uses MySQLdb as the DBAPI provider (see http://mysql-python.sourceforge.net/) - doesn't use OLE DB, as reference
If any tests fail here, we shouldn't expect them to neccessarily pass when using MyOleDb, it may be a mysql issue"""
|