def test_bulkLoadFeatures(self):
        tid = self.create_table_with_data()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        ft.openTable(tid)

        names, values, ids = ft.bulkLoadFeatures()
        self.assertEqual(names, ['a [0]', 'a [1]', 'b [0]'])
        self.assertEqual(values, [[1., 2., 5.], [3., 4., 6.]])
        self.assertEqual(ids, [7, 8])
    def test_loadFeatures(self):
        tid = self.create_table_with_data()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        ft.openTable(tid)

        names, values = ft.loadFeatures(7)
        self.assertEqual(names, ['a [0]', 'a [1]', 'b [0]'])
        self.assertEqual(values, [1., 2., 5.])

        names, values = ft.loadFeatures(8)
        self.assertEqual(names, ['a [0]', 'a [1]', 'b [0]'])
        self.assertEqual(values, [3., 4., 6.])
    def test_saveFeatures(self):
        tid = self.create_table_with_data()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        ft.openTable(tid)
        fts = TestFeatures()
        ft.saveFeatures(101, fts)

        self.assertEqual(ft.tc.getNumberOfRows(), 3)
        xs = ft.tc.readArray([0, 1, 2], 0, 4, chunk=3)
        self.assertEqual(xs[0].values, [7, 8, 101])
        self.assertEqual(xs[1].values, [[1., 2.], [3., 4.], [10., 11.]])
        self.assertEqual(xs[2].values, [[5.], [6.], [12.]])
    def test_openTable(self):
        # The any version is handled by test_createTable() so just test the
        # specific version
        tid = self.create_table()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        ft.openTable(tid)
        self.assertEqual(self.version, unwrapVersion(ft.versiontag))
        ft.close()

        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        self.assertRaises(
            WndcharmStorage.WndcharmStorageError, ft.openTable,
            tid, self.otherversion)
    def test_createTable(self):
        tid = self.create_table()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        ft.openTable(tid)
        self.assertEqual(self.version, unwrapVersion(ft.versiontag))

        vertag = WndcharmStorage.getVersion(ft.conn, 'OriginalFile', tid)
        self.assertEqual(self.version, unwrapVersion(vertag))

        headers = ft.tc.getHeaders()
        self.assertEqual(len(headers), 3)
        self.assertEqual([h.name for h in headers], ['id', 'a', 'b'])
        self.assertEqual([h.size for h in headers[1:]], [2, 1])
    def test_isTableCompatible(self):
        tid = self.create_table()
        ft = FeatureTable(client=self.cli, tableName=self.tableName)
        t = ft.openTable(tid, self.version)

        fts = TestFeatures()
        self.assertTrue(ft.isTableCompatible(fts))
        fts.names.append('a [2]')
        fts.values.append(13.)
        self.assertFalse(ft.isTableCompatible(fts))
 def test_tableContainsId(self):
     tid = self.create_table_with_data()
     ft = FeatureTable(client=self.cli, tableName=self.tableName)
     ft.openTable(tid)
     self.assertTrue(ft.tableContainsId(7))