コード例 #1
0
ファイル: ORACLESource_test.py プロジェクト: nexdatas/writer
    def test_getData_spectrum_trans(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        arr = {
            "int": [
                'select IDENT,IDENT from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevLong64", [1, 0]
            ],
            "long": [
                'select IDENT,NAME from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevLong64", [1, 0]
            ],
            "float": [
                'select IDENT,IDENT from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevLong64", [1, 0]
            ],
            "str": [
                'select NAME,VNAME from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevString", [1, 0]
            ],
            # "str": ['select NAME,VNAME from telefonbuch where ROWNUM <= 1',
            #        "SPECTRUM", "DevString", [1, 0]],
            "unicode": [
                'select NAME,IDENT from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevString", [1, 0]
            ],
            "bool": [
                'select IDENT,IDENT from telefonbuch where ROWNUM <= 1',
                "SPECTRUM", "DevLong64", [1, 0]
            ],
        }

        for a in arr:
            cursor = self._mydb.cursor()
            cursor.execute(arr[a][0])
            value = cursor.fetchall()
            cursor.close()

            arr[a][3] = [len(value[0]), 0]

            ds = DBaseSource()
            ds.query = arr[a][0]
            ds.dbtype = self.__dbtype
            ds.format = arr[a][1]
            ds.user = self.__user
            ds.passwd = self.__passwd
            ds.dsn = self.__dsn
            dt = ds.getData()

            self.checkData(dt, arr[a][1], list(el for el in value[0]),
                           arr[a][2], arr[a][3])
コード例 #2
0
ファイル: ORACLESource_test.py プロジェクト: nexdatas/writer
    def test_getData_scalar(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        arr = {
            "int": [
                'select IDENT from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevLong64", [1, 0]
            ],
            "long": [
                'select IDENT from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevLong64", [1, 0]
            ],
            "float": [
                'select IDENT from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevLong64", [1, 0]
            ],
            "str": [
                'select NAME from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevString", [1, 0]
            ],
            "unicode": [
                'select NAME from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevString", [1, 0]
            ],
            "bool": [
                'select IDENT from telefonbuch where ROWNUM <= 1', "SCALAR",
                "DevLong64", [1, 0]
            ],
        }

        for a in arr:
            cursor = self._mydb.cursor()
            cursor.execute(arr[a][0])
            value = cursor.fetchone()[0]
            cursor.close()

            ds = DBaseSource()
            ds.query = arr[a][0]
            ds.dbtype = self.__dbtype
            ds.format = arr[a][1]
            ds.user = self.__user
            ds.passwd = self.__passwd
            ds.dsn = self.__dsn
            dt = ds.getData()

            #            print a, value, dt,arr[a][0]

            self.checkData(dt, arr[a][1], value, arr[a][2], arr[a][3])
コード例 #3
0
    def test_getData_spectrum_single(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        arr = {
            "int": [
                "SELECT pid FROM device limit 1", "SPECTRUM", "DevLong64",
                [1, 0]
            ],
            "long": [
                "SELECT pid FROM device limit 1", "SPECTRUM", "DevLong64",
                [1, 0]
            ],
            "float": [
                "SELECT pid FROM device limit 1", "SPECTRUM", "DevLong64",
                [1, 0]
            ],
            #            "float":["SELECT pid FROM device limit 1",
            # "SPECTRUM","DevDouble",[1,0]],
            "str": [
                "SELECT name FROM device limit 1", "SPECTRUM", "DevString",
                [1, 0]
            ],
            "unicode": [
                "SELECT name FROM device limit 1", "SPECTRUM", "DevString",
                [1, 0]
            ],
            #            "bool":["SELECT exported FROM device limit 1",
            # "SPECTRUM","DevBoolean",[1,0]],
            "bool": [
                "SELECT exported FROM device limit 1", "SPECTRUM", "DevLong64",
                [1, 0]
            ],
        }

        for a in arr:
            cursor = self._mydb.cursor()
            cursor.execute(arr[a][0])
            value = cursor.fetchone()
            cursor.close()

            arr[a][3][0] = len(value)

            ds = DBaseSource()
            self.setsource(ds)
            ds.query = arr[a][0]
            ds.dbtype = self.__dbtype
            ds.format = arr[a][1]
            ds.dbname = self.__dbname
            dt = ds.getData()

            #            print a, value, dt,arr[a][0]

            self.checkData(dt, arr[a][1], value, arr[a][2], arr[a][3])
コード例 #4
0
    def test_constructor_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, None)
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, None)
コード例 #5
0
    def test_getData_spectrum_trans(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        arr = {
            "int": ["SELECT temp_lo FROM weather limit 1", "SPECTRUM",
                    "DevLong64", [1, 0]],
            "long": ["SELECT temp_lo FROM weather limit 1", "SPECTRUM",
                     "DevLong64", [1, 0]],
            "float": ["SELECT prcp FROM weather limit 1", "SPECTRUM",
                      "DevDouble", [1, 0]],
            "str": ["SELECT city FROM weather limit 1", "SPECTRUM",
                    "DevString", [1, 0]],
            "unicode": ["SELECT city FROM weather limit 1", "SPECTRUM",
                        "DevString", [1, 0]],
            #            "bool":["SELECT exported FROM weather limit 1",
            # "SPECTRUM","DevBoolean",[1,0]],
            "bool": ["SELECT temp_lo FROM weather limit 1", "SPECTRUM",
                     "DevLong64", [1, 0]],
        }

        for a in arr:
            cursor = self._mydb.cursor()
            cursor.execute(arr[a][0])
            value = cursor.fetchall()
            cursor.close()

            arr[a][3] = [len(value[0]), 0]

            ds = DBaseSource()
            ds.query = arr[a][0]
            ds.dbtype = self.__dbtype
            ds.format = arr[a][1]
            ds.dbname = self.__dbname
            dt = ds.getData()

            self.checkData(
                dt, arr[a][1], list(el for el in value[0]), arr[a][2],
                arr[a][3])
コード例 #6
0
    def test_getData_scalar(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        arr = {
            "int": ["SELECT temp_lo FROM weather limit 1", "SCALAR",
                    "DevLong64", [1, 0]],
            "long": ["SELECT temp_lo FROM weather limit 1", "SCALAR",
                     "DevLong64", [1, 0]],
            "float": ["SELECT prcp FROM weather limit 1", "SCALAR",
                      "DevDouble", [1, 0]],
            "str": ["SELECT city FROM weather limit 1", "SCALAR",
                    "DevString", [1, 0]],
            "unicode": ["SELECT city FROM weather limit 1", "SCALAR",
                        "DevString", [1, 0]],
            # "bool":["SELECT exported FROM weather limit 1","SCALAR",
            #    "DevBoolean",[1,0]],
            "bool": ["SELECT temp_lo FROM weather limit 1", "SCALAR",
                     "DevLong64", [1, 0]],
        }

        for a in arr:
            cursor = self._mydb.cursor()
            cursor.execute(arr[a][0])
            value = cursor.fetchone()[0]
            cursor.close()

            ds = DBaseSource()
            ds.query = arr[a][0]
            ds.dbtype = self.__dbtype
            ds.format = arr[a][1]
            ds.dbname = self.__dbname
            dt = ds.getData()

#            print a, value, dt,arr[a][0]

            self.checkData(dt, arr[a][1], value, arr[a][2], arr[a][3])
コード例 #7
0
ファイル: ORACLESource_test.py プロジェクト: nexdatas/writer
    def test_getData_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        query = 'select * from (select IDENT from telefonbuch) ' + \
                'where ROWNUM <= 1'
        format = "SPECTRUM"

        cursor = self._mydb.cursor()
        cursor.execute(query)
        scalar = cursor.fetchone()[0]
        cursor.close()

        ds = DBaseSource()
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = "UNKNOWNDB"
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
        #        dt = ds.getData()
        self.myAssertRaise(cx_Oracle.DatabaseError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
        ds.query = query
        self.myAssertRaise(cx_Oracle.DatabaseError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
        ds.user = self.__user
        ds.passwd = self.__passwd
        ds.query = query
        ds.format = format
        ds.dsn = self.__dsn
        dt = ds.getData()

        self.checkData(dt, 'SPECTRUM', [scalar], 'DevLong64', [1, 0])
コード例 #8
0
    def test_setup_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        dbtype = "MYSQL"
        dbtypeO = "ORACLE"
        # dbtypeP = "PGSQL"
        dbname = "tango"
        query = "select pid from devices;"
        format = "SPECTRUM"
        dsn = "()"
        hostname = 'haso228.desy.de'
        port = '10000'
        mode = 'SYSDBAL'
        user = '******'
        passwd = 'secret'
        mycnf = '/etc/mysql/my.cnf'

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.myAssertRaise(DataSourceSetupError, ds.setup, "<datasource/>")
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, None)
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, None)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.myAssertRaise(DataSourceSetupError, ds.setup,
                           "<datasource><query/></datasource>")
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, '')
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, None)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.myAssertRaise(
            DataSourceSetupError, ds.setup,
            "<datasource><query format='%s' /></datasource>" % format)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, '')
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.myAssertRaise(
            DataSourceSetupError, ds.setup,
            "<datasource><query>%s</query></datasource>" % query)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, None)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "</datasource>" % (format, query)), None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, None)
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbtype='%s'>%s</database></datasource>" %
                     (format, query, dbtypeO, dsn)), None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, dsn)
        self.assertEqual(ds.dbtype, dbtypeO)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query><database/>"
                     "</datasource>" % (format, query)), None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s'/></datasource>" %
                     (format, query, dbname)), None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, None)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s' dbtype='%s'/></datasource>" %
                     (format, query, dbname, dbtype)), None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.user, None)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s' dbtype='%s' user='******'/>"
                     "</datasource>" % (format, query, dbname, dbtype, user)),
            None)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, None)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s' dbtype='%s' user='******' "
                     "passwd='%s' hostname='%s'/></datasource>" %
                     (format, query, dbname, dbtype, user, passwd, hostname)),
            None)
        self.assertEqual(ds.hostname, hostname)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, passwd)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup(
                "<datasource><query format='%s'>%s</query>"
                "<database dbname='%s' dbtype='%s' user='******' "
                "passwd='%s' hostname='%s' port='%s'/></datasource>" %
                (format, query, dbname, dbtype, user, passwd, hostname, port)),
            None)
        self.assertEqual(ds.hostname, hostname)
        self.assertEqual(ds.port, port)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, passwd)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
        self.assertEqual(ds.format, format)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s' dbtype='%s' user='******' "
                     "passwd='%s' hostname='%s' port='%s' mycnf='%s'/>"
                     "</datasource>" % (format, query, dbname, dbtype, user,
                                        passwd, hostname, port, mycnf)), None)
        self.assertEqual(ds.format, format)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.hostname, hostname)
        self.assertEqual(ds.port, port)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, passwd)
        self.assertEqual(ds.mycnf, mycnf)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbname='%s' dbtype='%s' user='******' "
                     "passwd='%s' hostname='%s' port='%s' mycnf='%s'/>"
                     "</datasource>" % (format, query, dbname, dbtype, user,
                                        passwd, hostname, port, mycnf)), None)
        self.assertEqual(ds.format, format)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dbname, dbname)
        self.assertEqual(ds.dbtype, dbtype)
        self.assertEqual(ds.hostname, hostname)
        self.assertEqual(ds.port, port)
        self.assertEqual(ds.dsn, '')
        self.assertEqual(ds.mode, None)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, passwd)
        self.assertEqual(ds.mycnf, mycnf)

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(
            ds.setup("<datasource><query format='%s'>%s</query>"
                     "<database dbtype='%s' user='******' passwd='%s' "
                     "mode='%s'>%s</database></datasource>" %
                     (format, query, dbtypeO, user, passwd, mode, dsn)), None)
        self.assertEqual(ds.format, format)
        self.assertEqual(ds.query, query)
        self.assertEqual(ds.dbname, None)
        self.assertEqual(ds.dbtype, dbtypeO)
        self.assertEqual(ds.hostname, None)
        self.assertEqual(ds.port, None)
        self.assertEqual(ds.dsn, dsn)
        self.assertEqual(ds.mode, mode)
        self.assertEqual(ds.user, user)
        self.assertEqual(ds.passwd, passwd)
        self.assertEqual(ds.mycnf, '/etc/my.cnf')
コード例 #9
0
    def test_str_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        dbtype = "MYSQL"
        dbname = "tango"
        query = "select * from devices;"

        ds = DBaseSource()
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(ds.__str__(), " %s DB %s with %s " % (None, "", None))

        ds = DBaseSource()
        ds.dbtype = dbtype
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(ds.__str__(),
                         " %s DB %s with %s " % (dbtype, "", None))

        ds = DBaseSource()
        ds.dbtype = dbtype
        ds.dbname = dbname
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(ds.__str__(),
                         " %s DB %s with %s " % (dbtype, dbname, None))

        ds = DBaseSource()
        ds.dbtype = dbtype
        ds.dbname = dbname
        ds.query = query
        self.assertTrue(isinstance(ds, DataSource))
        self.assertEqual(ds.__str__(),
                         " %s DB %s with %s " % (dbtype, dbname, query))
コード例 #10
0
    def test_getData_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        query = "select pid from devices;"
        query2 = "SELECT pid FROM device limit 1"
        format = "SPECTRUM"

        cursor = self._mydb.cursor()
        cursor.execute(query2)
        scalar = cursor.fetchone()[0]
        cursor.close()

        ds = DBaseSource()
        self.setsource(ds)
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        self.setsource(ds)
        ds.dbtype = "UNKNOWNDB"
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        self.setsource(ds)
        ds.dbtype = self.__dbtype
        self.myAssertRaise(TypeError, ds.getData)

        ds = DBaseSource()
        self.setsource(ds)
        ds.dbtype = self.__dbtype
        ds.query = query
        self.myAssertRaise(MySQLdb.OperationalError, ds.getData)

        ds = DBaseSource()
        self.setsource(ds)
        ds.dbtype = self.__dbtype
        ds.query = query2
        ds.format = format
        ds.dbname = self.__dbname
        dt = ds.getData()

        self.checkData(dt, 'SPECTRUM', [long(scalar)], 'DevLong64', [1, 0])
コード例 #11
0
    def test_getData_default(self):
        fun = sys._getframe().f_code.co_name
        print("Run: %s.%s() " % (self.__class__.__name__, fun))

        query = "select city from weather limit 1"
        format = "SPECTRUM"

        cursor = self._mydb.cursor()
        cursor.execute(query)
        scalar = cursor.fetchone()[0]
        cursor.close()

        ds = DBaseSource()
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = "UNKNOWNDB"
        self.myAssertRaise(PackageError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
#        dt = ds.getData()
        self.myAssertRaise(TypeError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
        ds.query = query
        self.myAssertRaise(TypeError, ds.getData)

        ds = DBaseSource()
        ds.dbtype = self.__dbtype
        ds.query = query
        ds.format = format
        ds.dbname = self.__dbname
        dt = ds.getData()

        self.checkData(dt, 'SPECTRUM', [scalar], 'DevString', [1, 0])