def test_annotateAndAnnotated(self): # There's a bug somewhere which means annotating the table with the # version annotation, then using the table as a FileAnnotation on # an object, causes the version annotation to be lost # Closing and reopening the table seems to work (see # FeatureTable.createTable) cli, sess = self.create_client() ft = FeatureTable(client=cli, tableName=self.tableName) fts = ['a [0]', 'a [1]', 'b [0]'] ft.createTable(fts, version=self.version) tid = ft.tc.tableId self.assertEqual(self.version, unwrapVersion(ft.versiontag)) vertag = WndcharmStorage.getVersion(ft.conn, 'OriginalFile', tid) self.assertEqual(self.version, unwrapVersion(vertag)) p = omero.model.ProjectI() p.setName(wrap('tmp')) p = self.sess.getUpdateService().saveAndReturnObject(p) pid = unwrap(p.getId()) p = ft.conn.getObject('Project', pid) WndcharmStorage.addFileAnnotationTo(ft.tc, p) vertag = WndcharmStorage.getVersion(ft.conn, 'OriginalFile', tid) self.assertEqual(self.version, unwrapVersion(vertag)) self.delete('/Project', pid) self.delete('/OriginalFile', tid)
def create_table(self): cli, sess = self.create_client() ft = FeatureTable(client=cli, tableName=self.tableName) fts = ['a [0]', 'a [1]', 'b [0]'] ft.createTable(fts, version=self.version) tid = ft.tc.tableId ft.close() return tid
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_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_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_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 create_table_with_data(self): cli, sess = self.create_client() ft = FeatureTable(client=cli, tableName=self.tableName) fts = ['a [0]', 'a [1]', 'b [0]'] ft.createTable(fts, version=self.version) cols = ft.tc.getHeaders() cols[0].values = [7, 8] cols[1].values = [[1., 2.], [3., 4.]] cols[2].values = [[5.], [6.]] ft.tc.addData(cols) tid = ft.tc.tableId ft.close() return tid
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_tableContainsId(self): tid = self.create_table_with_data() ft = FeatureTable(client=self.cli, tableName=self.tableName) ft.openTable(tid) self.assertTrue(ft.tableContainsId(7))