Пример #1
0
    def testPrimitiveColSourceCases(self):
        """
        Testing column source construction from primitive cases
        """

        with self.subTest(msg="colSource with bool"):
            col1 = TableTools.colSource(True)
            self.assertEqual(col1.getType().toString(),
                             'class java.lang.Boolean')
            # print("table from bool = \n{}".format(TableTools.html(TableTools.newTable(1, {'bool1': col1}))))

            col2 = TableTools.colSource(True, False, None)
            self.assertEqual(col2.getType().toString(),
                             'class java.lang.Boolean')
            # print("table from bool varargs = \n{}".format(TableTools.html(TableTools.newTable(3, {'bool2': col2}))))

        with self.subTest(msg="colSource with int"):
            col1 = TableTools.colSource(1)
            self.assertEqual(col1.getType().toString(), 'long')
            # print("table from int = \n{}".format(TableTools.html(TableTools.newTable(1, {'int1': col1}))))

            col2 = TableTools.colSource(1, 2, None)
            self.assertEqual(col2.getType().toString(), 'long')
            # print("table from int varargs = \n{}".format(TableTools.html(TableTools.newTable(3, {'int2': col2}))))

        with self.subTest(msg="colSource with float"):
            col1 = TableTools.colSource(1.0)
            self.assertEqual(col1.getType().toString(), 'double')
            # print("table from float = \n{}".format(TableTools.html(TableTools.newTable(1, {'float1': col1}))))

            col2 = TableTools.colSource(1.0, 2.0, None)
            self.assertEqual(col2.getType().toString(), 'double')
            # print("table from float varargs = \n{}".format(TableTools.html(TableTools.newTable(3, {'float2': col2}))))

        with self.subTest(msg="colSource with string"):
            col1 = TableTools.colSource('one')
            self.assertEqual(col1.getType().toString(),
                             'class java.lang.String')
            # print("table from string = \n{}".format(TableTools.html(TableTools.newTable(1, {'string1': col1}))))

            col2 = TableTools.colSource('one', 'two', None)
            self.assertEqual(col2.getType().toString(),
                             'class java.lang.String')
            # print("table from string varargs = \n{}".format(TableTools.html(TableTools.newTable(3, {'string2': col2}))))

        with self.subTest(msg="colSource with datetime"):
            col1 = TableTools.colSource(datetime.utcnow())
            self.assertEqual(col1.getType().toString(),
                             'class io.deephaven.db.tables.utils.DBDateTime')
            # print("table from string = \n{}".format(TableTools.html(TableTools.newTable(1, {'datetime1': col1}))))

            col2 = TableTools.colSource(datetime.utcnow(), datetime.utcnow(),
                                        None)
            self.assertEqual(col2.getType().toString(),
                             'class io.deephaven.db.tables.utils.DBDateTime')
            # print("table from datetime varargs = \n{}".format(TableTools.html(TableTools.newTable(3, {'datetime2': col2}))))

        with self.subTest(msg="colSource with date"):
            col1 = TableTools.colSource(date.today())
            self.assertEqual(col1.getType().toString(),
                             'class io.deephaven.db.tables.utils.DBDateTime')
            # print("table from string = \n{}".format(TableTools.html(TableTools.newTable(1, {'date1': col1}))))

            col2 = TableTools.colSource(date.today(), date.today(), None)
            self.assertEqual(col2.getType().toString(),
                             'class io.deephaven.db.tables.utils.DBDateTime')
Пример #2
0
    def testColumnSource(self):
        """
        Test cases for colSource(), objColSource() methods & associated newTable() method
        """

        # type inference does not work for list and dicts (i.e. not converted to java collections & maps)
        colSources = []
        names = []
        mapSources = {}

        with self.subTest(msg="colSource with byte"):
            key, val = "byte", TableTools.colSource(self.nByteArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with short"):
            key, val = "short", TableTools.colSource(self.nShortArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with int"):
            key, val = "int", TableTools.colSource(self.nIntArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with long"):
            key, val = "long", TableTools.colSource(self.nLongArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with float"):
            key, val = "float", TableTools.colSource(self.nFloatArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with double"):
            key, val = "double", TableTools.colSource(self.nDoubleArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with char"):
            key, val = "char", TableTools.colSource(self.nCharArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with string"):
            key, val = "string", TableTools.colSource(self.nStringArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with boolean"):
            key, val = "boolean", TableTools.colSource(self.nBooleanArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val
        with self.subTest(msg="colSource with time"):
            key, val = "time", TableTools.colSource(self.nTimeArray)
            names.append(key)
            colSources.append(val)
            mapSources[key] = val

        with self.subTest(msg="newTable with name and column source list"):
            self.assertGreater(len(colSources),
                               0)  # make sure that we even do something useful
            print("table from [names], [sources] = \n{}".format(
                TableTools.html(TableTools.newTable(3, names, colSources))))

        with self.subTest(msg="newTable with {name: column source} map"):
            self.assertGreater(len(mapSources),
                               0)  # make sure that we even do something useful
            print("table from [names : sources] = \n{}".format(
                TableTools.html(TableTools.newTable(3, mapSources))))
        del names, colSources, mapSources

        names, colSources = [], []
        with self.subTest(msg="colSource with int list"):
            key, val = "intList", TableTools.colSource(self.intList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="colSource with float list"):
            key, val = "floatList", TableTools.colSource(self.floatList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="colSource with string list"):
            key, val = "strList", TableTools.colSource(self.stringList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="colSource with char list"):
            key, val = "charList", TableTools.colSource(self.charList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="colSource with boolean list"):
            key, val = "boolList", TableTools.colSource(self.booleanList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="colSource with time list"):
            key, val = "time", TableTools.colSource(self.timeList)
            names.append(key)
            colSources.append(val)
        print("table from colSource with lists = \n{}".format(
            TableTools.html(TableTools.newTable(3, names, colSources))))
        del names, colSources

        names, colSources = [], []
        with self.subTest(msg="objColSource with string"):
            key, val = "string", TableTools.objColSource(self.nStringArray)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="objColSource with boolean"):
            key, val = "boolean", TableTools.objColSource(self.nBooleanArray)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="objColSource with time"):
            key, val = "time", TableTools.objColSource(self.nTimeArray)
            names.append(key)
            colSources.append(val)
        # NOTE: this one is kinda dumb...probably not what anyone wants
        with self.subTest(msg="objColSource with double primitive"):
            key, val = "double", TableTools.objColSource(self.nDoubleArray)
            names.append(key)
            colSources.append(val)
        print("table from objColSource = \n{}".format(
            TableTools.html(TableTools.newTable(3, names, colSources))))
        del names, colSources

        names, colSources = [], []
        with self.subTest(msg="objColSource with string list"):
            key, val = "string", TableTools.objColSource(self.stringList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="objColSource with boolean list"):
            key, val = "boolean", TableTools.objColSource(self.booleanList)
            names.append(key)
            colSources.append(val)
        with self.subTest(msg="objColSource with time list"):
            key, val = "time", TableTools.objColSource(self.timeList)
            names.append(key)
            colSources.append(val)
        # NOTE: this one is kinda dumb...probably not what anyone wants
        with self.subTest(msg="objColSource with float list"):
            key, val = "double", TableTools.objColSource(self.floatList)
            names.append(key)
            colSources.append(val)
        print("table from objColSource with lists = \n{}".format(
            TableTools.html(TableTools.newTable(3, names, colSources))))
        del names, colSources