Mercurial > p > mysql-python > mysqldb-2
comparison test_MySQLdb_capabilities.py @ 0:e48810735f11 MySQLdb
Copying 1.2.1 to be the new trunk
author | adustman |
---|---|
date | Sun, 02 Apr 2006 18:20:53 +0000 |
parents | |
children | df195ac92df6 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e48810735f11 |
---|---|
1 #!/usr/bin/env python | |
2 import test_capabilities | |
3 import unittest | |
4 import MySQLdb | |
5 import warnings | |
6 | |
7 warnings.filterwarnings('error') | |
8 | |
9 class test_MySQLdb(test_capabilities.DatabaseTest): | |
10 | |
11 db_module = MySQLdb | |
12 connect_args = () | |
13 connect_kwargs = dict(db='test', read_default_file='~/.my.cnf', | |
14 charset='utf8', sql_mode="ANSI,STRICT_TRANS_TABLES,TRADITIONAL") | |
15 create_table_extra = "ENGINE=INNODB CHARACTER SET UTF8" | |
16 leak_test = True | |
17 | |
18 def quote_identifier(self, ident): | |
19 return "`%s`" % ident | |
20 | |
21 def test_TIME(self): | |
22 from datetime import timedelta | |
23 def generator(row,col): | |
24 return timedelta(0, row*8000) | |
25 self.check_data_integrity( | |
26 ('col1 TIME',), | |
27 generator) | |
28 | |
29 def test_TINYINT(self): | |
30 # Number data | |
31 def generator(row,col): | |
32 v = (row*row) % 256 | |
33 if v > 127: | |
34 v = v-256 | |
35 return v | |
36 self.check_data_integrity( | |
37 ('col1 TINYINT',), | |
38 generator) | |
39 | |
40 def test_SET(self): | |
41 things = 'ash birch cedar larch pine'.split() | |
42 def generator(row, col): | |
43 from sets import Set | |
44 s = Set() | |
45 for i in range(len(things)): | |
46 if (row >> i) & 1: | |
47 s.add(things[i]) | |
48 return s | |
49 self.check_data_integrity( | |
50 ('col1 SET(%s)' % ','.join(["'%s'" % t for t in things]),), | |
51 generator) | |
52 | |
53 def test_stored_procedures(self): | |
54 db = self.connection | |
55 c = self.cursor | |
56 self.create_table(('pos INT', 'tree CHAR(20)')) | |
57 c.executemany("INSERT INTO %s (pos,tree) VALUES (%%s,%%s)" % self.table, | |
58 list(enumerate('ash birch cedar larch pine'.split()))) | |
59 db.commit() | |
60 | |
61 c.execute(""" | |
62 CREATE PROCEDURE test_sp(IN t VARCHAR(255)) | |
63 BEGIN | |
64 SELECT pos FROM %s WHERE tree = t; | |
65 END | |
66 """ % self.table) | |
67 db.commit() | |
68 | |
69 c.callproc('test_sp', ('larch',)) | |
70 rows = c.fetchall() | |
71 self.assertEquals(len(rows), 1) | |
72 self.assertEquals(rows[0][0], 3) | |
73 c.nextset() | |
74 | |
75 c.execute("DROP PROCEDURE test_sp") | |
76 c.execute('drop table %s' % (self.table)) | |
77 | |
78 | |
79 if __name__ == '__main__': | |
80 if test_MySQLdb.leak_test: | |
81 import gc | |
82 gc.enable() | |
83 gc.set_debug(gc.DEBUG_LEAK) | |
84 unittest.main() | |
85 print '''"Huh-huh, he said 'unit'." -- Butthead''' |