Beispiel #1
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))
Beispiel #2
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])
Beispiel #3
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])
Beispiel #4
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])
Beispiel #5
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])
Beispiel #6
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])