| 1 |
|
| 2 |
import jpype.dbapi2 as dbapi2 |
| 3 |
import common |
| 4 |
import time |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class SQLModuleTestCase(common.JPypeTestCase): |
| 9 |
def setUp(self): |
| 10 |
common.JPypeTestCase.setUp(self) |
| 11 |
|
| 12 |
def assertIsSubclass(self, a, b): |
| 13 |
self.assertTrue(issubclass(a, b), "`%s` is not a subclass of `%s`" % (a.__name__, b.__name__)) |
| 14 |
|
| 15 |
def testConstants(self): |
| 16 |
self.assertEqual(dbapi2.apilevel, "2.0") |
| 17 |
self.assertEqual(dbapi2.threadsafety, 2) |
| 18 |
self.assertEqual(dbapi2.paramstyle, "qmark") |
| 19 |
|
| 20 |
def testExceptions(self): |
| 21 |
self.assertIsSubclass(dbapi2.Warning, Exception) |
| 22 |
self.assertIsSubclass(dbapi2.Error, Exception) |
| 23 |
self.assertIsSubclass(dbapi2.InterfaceError, dbapi2.Error) |
| 24 |
self.assertIsSubclass(dbapi2.DatabaseError, dbapi2.Error) |
| 25 |
self.assertIsSubclass(dbapi2._SQLException, dbapi2.Error) |
| 26 |
self.assertIsSubclass(dbapi2.DataError, dbapi2.DatabaseError) |
| 27 |
self.assertIsSubclass(dbapi2.OperationalError, dbapi2.DatabaseError) |
| 28 |
self.assertIsSubclass(dbapi2.IntegrityError, dbapi2.DatabaseError) |
| 29 |
self.assertIsSubclass(dbapi2.InternalError, dbapi2.DatabaseError) |
| 30 |
self.assertIsSubclass(dbapi2.InternalError, dbapi2.DatabaseError) |
| 31 |
self.assertIsSubclass(dbapi2.ProgrammingError, dbapi2.DatabaseError) |
| 32 |
self.assertIsSubclass(dbapi2.NotSupportedError, dbapi2.DatabaseError) |
| 33 |
|
| 34 |
def testConnectionExceptions(self): |
| 35 |
cx = dbapi2.Connection |
| 36 |
self.assertEqual(cx.Warning, dbapi2.Warning) |
| 37 |
self.assertEqual(cx.Error, dbapi2.Error) |
| 38 |
self.assertEqual(cx.InterfaceError, dbapi2.InterfaceError) |
| 39 |
self.assertEqual(cx.DatabaseError, dbapi2.DatabaseError) |
| 40 |
self.assertEqual(cx.DataError, dbapi2.DataError) |
| 41 |
self.assertEqual(cx.OperationalError, dbapi2.OperationalError) |
| 42 |
self.assertEqual(cx.IntegrityError, dbapi2.IntegrityError) |
| 43 |
self.assertEqual(cx.InternalError, dbapi2.InternalError) |
| 44 |
self.assertEqual(cx.InternalError, dbapi2.InternalError) |
| 45 |
self.assertEqual(cx.ProgrammingError, dbapi2.ProgrammingError) |
| 46 |
self.assertEqual(cx.NotSupportedError, dbapi2.NotSupportedError) |
| 47 |
|
| 48 |
def test_Date(self): |
| 49 |
d1 = dbapi2.Date(2002, 12, 25) |
| 50 |
d2 = dbapi2.DateFromTicks( |
| 51 |
time.mktime((2002, 12, 25, 0, 0, 0, 0, 0, 0)) |
| 52 |
) |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
def test_Time(self): |
| 57 |
t1 = dbapi2.Time(13, 45, 30) |
| 58 |
t2 = dbapi2.TimeFromTicks( |
| 59 |
time.mktime((2001, 1, 1, 13, 45, 30, 0, 0, 0)) |
| 60 |
) |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
def test_Timestamp(self): |
| 65 |
t1 = dbapi2.Timestamp(2002, 12, 25, 13, 45, 30) |
| 66 |
t2 = dbapi2.TimestampFromTicks( |
| 67 |
time.mktime((2002, 12, 25, 13, 45, 30, 0, 0, 0)) |
| 68 |
) |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
def test_Binary(self): |
| 73 |
b = dbapi2.Binary(b"Something") |
| 74 |
b = dbapi2.Binary(b"") |
| 75 |
|
| 76 |
def test_STRING(self): |
| 77 |
self.assertTrue(hasattr(dbapi2, "STRING"), "module.STRING must be defined") |
| 78 |
|
| 79 |
def test_BINARY(self): |
| 80 |
self.assertTrue( |
| 81 |
hasattr(dbapi2, "BINARY"), "module.BINARY must be defined." |
| 82 |
) |
| 83 |
|
| 84 |
def test_NUMBER(self): |
| 85 |
self.assertTrue( |
| 86 |
hasattr(dbapi2, "NUMBER"), "module.NUMBER must be defined." |
| 87 |
) |
| 88 |
|
| 89 |
def test_DATETIME(self): |
| 90 |
self.assertTrue( |
| 91 |
hasattr(dbapi2, "DATETIME"), "module.DATETIME must be defined." |
| 92 |
) |
| 93 |
|
| 94 |
def test_ROWID(self): |
| 95 |
self.assertTrue(hasattr(dbapi2, "ROWID"), "module.ROWID must be defined.") |
| 96 |
|
| 97 |
|
| 98 |
class SQLTablesTestCase(common.JPypeTestCase): |
| 99 |
def setUp(self): |
| 100 |
common.JPypeTestCase.setUp(self) |
| 101 |
|
| 102 |
def testStr(self): |
| 103 |
for i in dbapi2._types: |
| 104 |
self.assertIsInstance(str(i), str) |
| 105 |
|
| 106 |
def testRepr(self): |
| 107 |
for i in dbapi2._types: |
| 108 |
self.assertIsInstance(repr(i), str) |