def test_SearchableFields(self): """Check that searchable fields are properly selected. """ VTAPP.slotFileCloseAll() # Opening a file automatically selects the root node of that file # in the tree viewer VTAPP.slotFileOpen(self.filepath) VTAPP.otLV.setOpen(VTAPP.otLV.selectedItem(), True) # Select /table_samples/nested_table group = VTAPP.otLV.findItem('table_samples', 0) VTAPP.otLV.setOpen(group, True) table = VTAPP.otLV.findItem('nested_table', 0) VTAPP.otLV.setSelected(table, True) # Get the info dictionary of the table dbdoc = VTAPP.dbManager.getDB(table.getFilepath()) leafdoc = VTAPP.leavesManager.createLeafDoc(dbdoc, table.where) source_table = leafdoc.node info = leaves_manager.setInfoDictionary(source_table) # Find the searchable fields leaves_manager.setSearchableFields(source_table, info) # Compares searchable fields with the expected value expected_sfields = sets.Set(['ID', 'col0 (long ID)']) self.assertEqual(info['valid_fields'], expected_sfields, """The only searchable field should be %s""" % expected_sfields) # Inspect the condition variables expected_condvars = source_table.cols._f_col('long ID') expected_condvars_keys = ['col0'] self.assertEqual(info['condvars'].keys(), expected_condvars_keys, """The only condvar name should be %s""" % expected_condvars_keys) self.assertEqual(info['condvars']['col0'], expected_condvars, """The only condvar should be %s""" % expected_condvars)
def test_InitialCondition(self): """Check that the initial condition (if any) is correctly set. """ VTAPP.slotFileCloseAll() # Opening a file automatically selects the root node of that file # in the tree viewer VTAPP.slotFileOpen(self.filepath) VTAPP.otLV.setOpen(VTAPP.otLV.selectedItem(), True) # Select /table_samples/nested_table group = VTAPP.otLV.findItem('table_samples', 0) VTAPP.otLV.setOpen(group, True) table = VTAPP.otLV.findItem('nested_table', 0) VTAPP.otLV.setSelected(table, True) # Get the info dictionary of the table dbdoc = VTAPP.dbManager.getDB(table.getFilepath()) leafdoc = VTAPP.leavesManager.createLeafDoc(dbdoc, table.where) source_table = leafdoc.node info = leaves_manager.setInfoDictionary(source_table) leaves_manager.setSearchableFields(source_table, info) # Set the initial condition initial_cond = leaves_manager.setInitialCondition(\ VTAPP.leavesManager.last_query_info, info) # Compare with the expected initial condition expected_value = '' self.assertEqual(initial_cond, expected_value, """The initial condition should be empty""")
def test_QueryComponents(self): """Check that the query dialog works fine. """ VTAPP.slotFileCloseAll() # Opening a file automatically selects the root node of that file # in the tree viewer VTAPP.slotFileOpen(self.filepath) VTAPP.otLV.setOpen(VTAPP.otLV.selectedItem(), True) # Select /table_samples/nested_table group = VTAPP.otLV.findItem('table_samples', 0) VTAPP.otLV.setOpen(group, True) table = VTAPP.otLV.findItem('nested_table', 0) VTAPP.otLV.setSelected(table, True) # Get the info dictionary of the table dbdoc = VTAPP.dbManager.getDB(table.getFilepath()) leafdoc = VTAPP.leavesManager.createLeafDoc(dbdoc, table.where) source_table = leafdoc.node info = leaves_manager.setInfoDictionary(source_table) leaves_manager.setSearchableFields(source_table, info) # Set the initial condition initial_cond = leaves_manager.setInitialCondition(\ VTAPP.leavesManager.last_query_info, info) # Launch the query dialog VTAPP.leavesManager.query_info = {} qdlg = queryDlg.QueryDlg(VTAPP.leavesManager.query_info, info, [], 0, initial_cond, source_table) # The right thing would be something like # qdlg.query_le.setText('query line edit content') # qdlg.name_le.setText('name line edit content') # qdlg.indices_column.setText('my_indices') # qdlg.rstart.setValue(1) # qdlg.rstop.setValue(10) # qdlg.rstep.setValue(2) # qdlg.slotAccept() # Unfortunately it doesn''t work. I think it is due to the fact that we # do not enter the main execution loop of ViTables. As a consequence we # have to do qdlg.query_info['condition'] = 'query line edit content' qdlg.query_info['ft_name'] = 'name line edit content' qdlg.query_info['indices_field_name'] = 'my_indices' qdlg.query_info['rows_range'] = (0, 10, 2) del qdlg # Compare values expected_info = {} expected_info['condition'] = 'query line edit content' expected_info['ft_name'] = 'name line edit content' expected_info['indices_field_name'] = 'my_indices' expected_info['rows_range'] = (0, 10, 2) recovered_query_info = VTAPP.leavesManager.getQueryInfo() self.assertEqual(VTAPP.leavesManager.query_info, expected_info, """The expected query info is not what expected. %s %s""" % (expected_info, recovered_query_info))
def test_GetTableInfo(self): """Check the dictionary with information about the table being queried. """ VTAPP.slotFileCloseAll() # Opening a file automatically selects the root node of that file # in the tree viewer VTAPP.slotFileOpen(self.filepath) VTAPP.otLV.setOpen(VTAPP.otLV.selectedItem(), True) # Select /table_samples/nested_table group = VTAPP.otLV.findItem('table_samples', 0) VTAPP.otLV.setOpen(group, True) table = VTAPP.otLV.findItem('nested_table', 0) VTAPP.otLV.setSelected(table, True) # Get the info dictionary of the table dbdoc = VTAPP.dbManager.getDB(table.getFilepath()) leafdoc = VTAPP.leavesManager.createLeafDoc(dbdoc, table.where) source_table = leafdoc.node info = leaves_manager.setInfoDictionary(source_table) # The expected info dictionary expected_info = {} expected_info['nrows'] = source_table.nrows expected_info['src_filepath'] = source_table._v_file.filename expected_info['src_path'] = source_table._v_pathname expected_info['name'] = source_table._v_name expected_info['col_names'] = sets.Set(source_table.colnames) expected_info['col_shapes'] = \ dict((k, v.shape) for (k, v) in source_table.coldescrs.iteritems()) expected_info['col_types'] = source_table.coltypes expected_info['condvars'] = {} expected_info['valid_fields'] = [] # Compares with the expected dictionary bad_value = None for k in expected_info.keys(): if info[k] != expected_info[k]: bad_value = k break self.assertEqual(bad_value, None, """There is a problem with the %s key""" % bad_value)