comparison tests/test_MySQLdb_nonstandard.py @ 40:2d1a3d9e15b2 MySQLdb

Update some of the constants and declarations to post python-2.0 convenience functions, increase related test coverage.
author kylev
date Sun, 15 Feb 2009 07:26:43 +0000
parents df4d804244ec
children e80676c3505f
comparison
equal deleted inserted replaced
39:78e810705b3d 40:2d1a3d9e15b2
1 import unittest 1 import unittest
2 2
3 import _mysql
3 import MySQLdb 4 import MySQLdb
4 from MySQLdb.constants import FIELD_TYPE 5 from MySQLdb.constants import FIELD_TYPE
5 6
6 7
7 class TestDBAPISet(unittest.TestCase): 8 class TestDBAPISet(unittest.TestCase):
16 17
17 def test_set_inequality_membership(self): 18 def test_set_inequality_membership(self):
18 self.assertTrue(FIELD_TYPE.DATE != MySQLdb.STRING) 19 self.assertTrue(FIELD_TYPE.DATE != MySQLdb.STRING)
19 20
20 21
21 class NonStandard(unittest.TestCase): 22 class CoreAPI(unittest.TestCase):
22 """Test _mysql.connection internals.""" 23 """Test _mysql internals."""
23 24
24 def setUp(self): 25 def setUp(self):
25 self.conn = MySQLdb.connect(db='test') 26 self.conn = _mysql.connect(db='test')
26 27
27 def tearDown(self): 28 def tearDown(self):
28 self.conn.close() 29 self.conn.close()
29 30
31 def test_NULL(self):
32 """Should have a NULL constant."""
33 self.assertEqual(_mysql.NULL, 'NULL')
34
35 def test_version(self):
36 """Version information sanity."""
37 self.assertTrue(isinstance(_mysql.__version__, str))
38
39 self.assertTrue(isinstance(_mysql.version_info, tuple))
40 self.assertEqual(len(_mysql.version_info), 5)
41
30 def test_thread_id(self): 42 def test_thread_id(self):
31 tid = self.conn._db.thread_id() 43 tid = self.conn.thread_id()
32 self.assertTrue(isinstance(tid, int), 44 self.assertTrue(isinstance(tid, int),
33 "thread_id didn't return an int.") 45 "thread_id didn't return an int.")
34 46
35 self.assertRaises(TypeError, self.conn._db.thread_id, ('evil',), 47 self.assertRaises(TypeError, self.conn.thread_id, ('evil',),
36 "thread_id shouldn't accept arguments.") 48 "thread_id shouldn't accept arguments.")
37 49
38 def test_affected_rows(self): 50 def test_affected_rows(self):
39 self.assertEquals(self.conn._db.affected_rows(), 0, 51 self.assertEquals(self.conn.affected_rows(), 0,
40 "Should return 0 before we do anything.") 52 "Should return 0 before we do anything.")
41 53
42 54
43 def test_debug(self): 55 def test_debug(self):
44 # FIXME Only actually tests if you lack SUPER 56 # FIXME Only actually tests if you lack SUPER
45 self.assertRaises(MySQLdb.OperationalError, 57 self.assertRaises(MySQLdb.OperationalError,
46 self.conn._db.dump_debug_info) 58 self.conn.dump_debug_info)
47 59
48 def test_charset_name(self): 60 def test_charset_name(self):
49 self.assertTrue(isinstance(self.conn._db.character_set_name(), str), 61 self.assertTrue(isinstance(self.conn.character_set_name(), str),
50 "Should return a string.") 62 "Should return a string.")
51 63
52 def test_host_info(self): 64 def test_host_info(self):
53 self.assertTrue(isinstance(self.conn._db.get_host_info(), str), 65 self.assertTrue(isinstance(self.conn.get_host_info(), str),
54 "Should return a string.") 66 "Should return a string.")
55 67
56 def test_proto_info(self): 68 def test_proto_info(self):
57 self.assertTrue(isinstance(self.conn._db.get_proto_info(), int), 69 self.assertTrue(isinstance(self.conn.get_proto_info(), int),
58 "Should return an int.") 70 "Should return an int.")
59 71
60 def test_server_info(self): 72 def test_server_info(self):
61 self.assertTrue(isinstance(self.conn._db.get_server_info(), str), 73 self.assertTrue(isinstance(self.conn.get_server_info(), str),
62 "Should return an str.") 74 "Should return an str.")
63 75