diff --git a/src/test/data/create_hsqldb.sql b/src/test/data/create_hsqldb.sql new file mode 100644 index 0000000..92cd376 --- /dev/null +++ b/src/test/data/create_hsqldb.sql @@ -0,0 +1,12 @@ +create table Account ( +"ACCOUNT_ID" TIMESTAMP default CURRENT_TIMESTAMP not null, +"ACCOUNT_NO" INTEGER not null, +"BALANCE" DECIMAL default 0.0 not null, +"BLOCKING" DECIMAL, +"DBL_COL" DOUBLE, +"OPENED_AT" DATE, +"VALID" BOOLEAN, +"PRODUCT_NAME" VARCHAR(50), +primary key ("ACCOUNT_ID") +); + diff --git a/src/test/test_integration.py b/src/test/test_integration.py index cddbc7c..3f8cc0a 100644 --- a/src/test/test_integration.py +++ b/src/test/test_integration.py @@ -17,21 +17,50 @@ # License along with JayDeBeApi. If not, see # . -from os import path import jaydebeapi + +import os import sys +import threading import unittest2 as unittest -this_dir = path.dirname(path.abspath(__file__)) -jar_dir = path.abspath(path.join(this_dir, '..', '..', - 'build', 'lib')) -create_sql = path.join(this_dir, 'data', 'create.sql') -insert_sql = path.join(this_dir, 'data', 'insert.sql') +this_dir = os.path.dirname(os.path.abspath(__file__)) + +def jar(jar_file): + return os.path.abspath(os.path.join(this_dir, '..', '..', 'build', 'lib', + jar_file)) + +_DRIVERS = { + #http://bitbucket.org/xerial/sqlite-jdbc + 'sqlite_xerial': ( 'org.sqlite.JDBC', 'jdbc:sqlite::memory:', + jar('sqlite-jdbc-3.7.2.jar'), None), + # http://hsqldb.org/ + 'hsqldb': ( 'org.hsqldb.jdbcDriver', ['jdbc:hsqldb:mem:.', 'SA', ''], + jar('hsqldb.jar'), None), + 'db2jcc': ( 'com.ibm.db2.jcc.DB2Driver', + ['jdbc:db2://4.100.73.81:50000/db2t', 'user', 'passwd'], + jar('jarfile.jar'), None), + # driver from http://www.ch-werner.de/javasqlite/ seems to be + # crap as it returns decimal values as VARCHAR type + 'sqlite_werner': ( 'SQLite.JDBCDriver', 'jdbc:sqlite:/:memory:', + jar('sqlite.jar'), None), + # Oracle Thin Driver + 'oracle_thin': ('oracle.jdbc.OracleDriver', + ['jdbc:oracle:thin:@//hh-cluster-scan:1521/HH_TPP', + 'user', 'passwd'], + jar('jarfile.jar'), None) + } def is_jython(): return sys.platform.lower().startswith('java') +def driver_name(): + try: + return os.environ['INTEGRATION_TEST_DRIVER'] + except KeyError: + return 'sqlite_xerial' + class IntegrationTest(unittest.TestCase): def sql_file(self, filename): @@ -60,30 +89,26 @@ class IntegrationTest(unittest.TestCase): return sqlite3, sqlite3.connect(':memory:') def connect(self): - # http://www.zentus.com/sqlitejdbc/ - conn = jaydebeapi.connect('org.sqlite.JDBC', - 'jdbc:sqlite::memory:', - path.join(jar_dir, 'sqlitejdbc-v056.jar')) - # http://hsqldb.org/ - # conn = jaydebeapi.connect('org.hsqldb.jdbcDriver', - # ['jdbc:hsqldb:mem:.', 'SA', ''], - # 'hsqldb.jar') - # conn = jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', - # ['jdbc:db2://4.100.73.81:50000/db2t', - # user, passwd]) - # driver from http://www.ch-werner.de/javasqlite/ seems to be - # crap as it returns decimal values as VARCHAR type - # conn = jaydebeapi.connect('SQLite.JDBCDriver', - # 'jdbc:sqlite:/:memory:', 'sqlite.jar') - # Oracle Thin Driver - # conn = jaydebeapi.connect('oracle.jdbc.OracleDriver', - # ['jdbc:oracle:thin:@//hh-cluster-scan:1521/HH_TPP', - # user, passwd]) + driver = driver_name() + driver_class, driver_args, driver_jars, driver_libs = _DRIVERS[driver] + conn = jaydebeapi.connect(driver_class, driver_args, driver_jars, + driver_libs) return jaydebeapi, conn + def _driver_specific_sql(self, data_file): + driver = driver_name() + sql_file = os.path.join(this_dir, 'data', '%s_%s.sql' % (data_file, + driver)) + if os.path.exists(sql_file): + return sql_file + else: + return os.path.join(this_dir, 'data', '%s.sql' % data_file) + def setUp(self): (self.dbapi, self.conn) = self.connect() + create_sql = self._driver_specific_sql('create') self.sql_file(create_sql) + insert_sql = self._driver_specific_sql('insert') self.sql_file(insert_sql) def tearDown(self): diff --git a/test.py b/test.py index 7046c47..21a3454 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,7 @@ #!/usr/bin/env python """Run unittests in the `tests` directory.""" +from optparse import OptionParser import os import sys @@ -18,8 +19,12 @@ adjust_sys_path('src') import unittest2 def main(): + parser = OptionParser() + parser.add_option("-x", "--xml", action="store_true", dest="xml", + help="write test report in xunit file format") + (options, args) = parser.parse_args(sys.argv) suite = unittest2.loader.TestLoader().discover('src/test') - if len(sys.argv) > 1 and '--xml' in sys.argv: + if options.xml: import xmlrunner runner = xmlrunner.XMLTestRunner(output='build/test-reports') else: