Mercurial > p > mysql-python > mysqldb-2
annotate tests/test_MySQLdb_dbapi20.py @ 48:f4fd8c20511c MySQLdb
Read a default file in the test setUp. Since Python 2.4, int() will return longs if needed so make all long references int as in Python 3.0 there is no more long due to int/long unification (new ints are old longs).
author | adustman |
---|---|
date | Sun, 22 Feb 2009 20:01:31 +0000 |
parents | d55bfb1a4701 |
children |
rev | line source |
---|---|
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
1 #!/usr/bin/env python |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
2 import dbapi20 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
3 import unittest |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
4 import MySQLdb |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
5 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
6 class test_MySQLdb(dbapi20.DatabaseAPI20Test): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
7 driver = MySQLdb |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
8 connect_args = () |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
9 connect_kw_args = dict(db='test', |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
10 read_default_file='~/.my.cnf', |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
11 charset='utf8', |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
12 sql_mode="ANSI,STRICT_TRANS_TABLES,TRADITIONAL") |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
13 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
14 def test_setoutputsize(self): pass |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
15 def test_setoutputsize_basic(self): pass |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
16 def test_nextset(self): pass |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
17 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
18 """The tests on fetchone and fetchall and rowcount bogusly |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
19 test for an exception if the statement cannot return a |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
20 result set. MySQL always returns a result set; it's just that |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
21 some things return empty result sets.""" |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
22 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
23 def test_fetchall(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
24 con = self._connect() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
25 try: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
26 cur = con.cursor() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
27 # cursor.fetchall should raise an Error if called |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
28 # without executing a query that may return rows (such |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
29 # as a select) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
30 self.assertRaises(self.driver.Error, cur.fetchall) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
31 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
32 self.executeDDL1(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
33 for sql in self._populate(): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
34 cur.execute(sql) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
35 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
36 # cursor.fetchall should raise an Error if called |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
37 # after executing a a statement that cannot return rows |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
38 ## self.assertRaises(self.driver.Error,cur.fetchall) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
39 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
40 cur.execute('select name from %sbooze' % self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
41 rows = cur.fetchall() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
42 self.failUnless(cur.rowcount in (-1,len(self.samples))) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
43 self.assertEqual(len(rows),len(self.samples), |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
44 'cursor.fetchall did not retrieve all rows' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
45 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
46 rows = [r[0] for r in rows] |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
47 rows.sort() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
48 for i in range(0,len(self.samples)): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
49 self.assertEqual(rows[i],self.samples[i], |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
50 'cursor.fetchall retrieved incorrect rows' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
51 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
52 rows = cur.fetchall() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
53 self.assertEqual( |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
54 len(rows),0, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
55 'cursor.fetchall should return an empty list if called ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
56 'after the whole result set has been fetched' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
57 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
58 self.failUnless(cur.rowcount in (-1,len(self.samples))) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
59 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
60 self.executeDDL2(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
61 cur.execute('select name from %sbarflys' % self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
62 rows = cur.fetchall() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
63 self.failUnless(cur.rowcount in (-1,0)) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
64 self.assertEqual(len(rows),0, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
65 'cursor.fetchall should return an empty list if ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
66 'a select query returns no rows' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
67 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
68 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
69 finally: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
70 con.close() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
71 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
72 def test_fetchone(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
73 con = self._connect() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
74 try: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
75 cur = con.cursor() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
76 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
77 # cursor.fetchone should raise an Error if called before |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
78 # executing a select-type query |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
79 self.assertRaises(self.driver.Error,cur.fetchone) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
80 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
81 # cursor.fetchone should raise an Error if called after |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
82 # executing a query that cannnot return rows |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
83 self.executeDDL1(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
84 ## self.assertRaises(self.driver.Error,cur.fetchone) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
85 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
86 cur.execute('select name from %sbooze' % self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
87 self.assertEqual(cur.fetchone(),None, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
88 'cursor.fetchone should return None if a query retrieves ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
89 'no rows' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
90 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
91 self.failUnless(cur.rowcount in (-1,0)) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
92 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
93 # cursor.fetchone should raise an Error if called after |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
94 # executing a query that cannnot return rows |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
95 cur.execute("insert into %sbooze values ('Victoria Bitter')" % ( |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
96 self.table_prefix |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
97 )) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
98 ## self.assertRaises(self.driver.Error,cur.fetchone) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
99 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
100 cur.execute('select name from %sbooze' % self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
101 r = cur.fetchone() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
102 self.assertEqual(len(r),1, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
103 'cursor.fetchone should have retrieved a single row' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
104 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
105 self.assertEqual(r[0],'Victoria Bitter', |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
106 'cursor.fetchone retrieved incorrect data' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
107 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
108 ## self.assertEqual(cur.fetchone(),None, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
109 ## 'cursor.fetchone should return None if no more rows available' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
110 ## ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
111 self.failUnless(cur.rowcount in (-1,1)) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
112 finally: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
113 con.close() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
114 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
115 # Same complaint as for fetchall and fetchone |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
116 def test_rowcount(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
117 con = self._connect() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
118 try: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
119 cur = con.cursor() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
120 self.executeDDL1(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
121 ## self.assertEqual(cur.rowcount,-1, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
122 ## 'cursor.rowcount should be -1 after executing no-result ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
123 ## 'statements' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
124 ## ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
125 cur.execute("insert into %sbooze values ('Victoria Bitter')" % ( |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
126 self.table_prefix |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
127 )) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
128 ## self.failUnless(cur.rowcount in (-1,1), |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
129 ## 'cursor.rowcount should == number or rows inserted, or ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
130 ## 'set to -1 after executing an insert statement' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
131 ## ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
132 cur.execute("select name from %sbooze" % self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
133 self.failUnless(cur.rowcount in (-1,1), |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
134 'cursor.rowcount should == number of rows returned, or ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
135 'set to -1 after executing a select statement' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
136 ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
137 self.executeDDL2(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
138 ## self.assertEqual(cur.rowcount,-1, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
139 ## 'cursor.rowcount not being reset to -1 after executing ' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
140 ## 'no-result statements' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
141 ## ) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
142 finally: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
143 con.close() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
144 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
145 def test_callproc(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
146 pass # performed in test_MySQL_capabilities |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
147 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
148 def help_nextset_setUp(self,cur): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
149 ''' Should create a procedure called deleteme |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
150 that returns two result sets, first the |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
151 number of rows in booze then "name from booze" |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
152 ''' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
153 sql=""" |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
154 create procedure deleteme() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
155 begin |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
156 select count(*) from %(tp)sbooze; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
157 select name from %(tp)sbooze; |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
158 end |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
159 """ % dict(tp=self.table_prefix) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
160 cur.execute(sql) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
161 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
162 def help_nextset_tearDown(self,cur): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
163 'If cleaning up is needed after nextSetTest' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
164 cur.execute("drop procedure deleteme") |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
165 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
166 def test_nextset(self): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
167 from warnings import warn |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
168 con = self._connect() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
169 try: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
170 cur = con.cursor() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
171 if not hasattr(cur,'nextset'): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
172 return |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
173 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
174 try: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
175 self.executeDDL1(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
176 sql=self._populate() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
177 for sql in self._populate(): |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
178 cur.execute(sql) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
179 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
180 self.help_nextset_setUp(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
181 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
182 cur.callproc('deleteme') |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
183 numberofrows=cur.fetchone() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
184 assert numberofrows[0]== len(self.samples) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
185 assert cur.nextset() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
186 names=cur.fetchall() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
187 assert len(names) == len(self.samples) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
188 s=cur.nextset() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
189 if s: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
190 empty = cur.fetchall() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
191 self.assertEquals(len(empty), 0, |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
192 "non-empty result set after other result sets") |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
193 #warn("Incompatibility: MySQL returns an empty result set for the CALL itself", |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
194 # Warning) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
195 #assert s == None,'No more return sets, should return None' |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
196 finally: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
197 self.help_nextset_tearDown(cur) |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
198 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
199 finally: |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
200 con.close() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
201 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
202 |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
203 if __name__ == '__main__': |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
204 unittest.main() |
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
diff
changeset
|
205 print '''"Huh-huh, he said 'unit'." -- Butthead''' |