def test_ErrorEntryNotInDB(): '''Test the class ErrorEntryNotInDB (error when an entry doesn't exist in a database)''' # This file is not created, just a tmp path test_entry = "TestEntry" # Test instantiation test_error = NCBImetaErrors.ErrorEntryNotInDB(test_entry) # Test str representation (error message) error_output = str(test_error) error_expect = ("\n\nThe entry does not exist in the database." + "\n" + "Unknown entry found: " + test_entry) assert error_output == error_expect
#-----------------------------------------------------------------------# # File Setup # #-----------------------------------------------------------------------# # get list of column names in anchor table cur.execute('''SELECT * FROM {}'''.format(db_anchor)) db_col_names = [ description[0] for description in cur.description if description[0] != "id" ] anchor_col_names = [description[0] for description in cur.description] # Check to make sure the unique header is present in the anchor table for unique_header in unique_header_list: if unique_header not in db_col_names: print("Column not in DB: " + unique_header + ".", flush=True) raise NCBImetaErrors.ErrorEntryNotInDB(unique_header) # get list of column names in accessory tables for table in db_accessory_list: cur.execute('''SELECT * FROM {}'''.format(table)) for header in [ description[0] for description in cur.description if description[0] != "id" ]: db_col_names.append(header) # Prepare the columns for the final join table dupl_col_names = set( [col for col in db_col_names if db_col_names.count(col) > 1]) if len(dupl_col_names) > 0: raise NCBImetaErrors.ErrorColumnsNotUnique(dupl_col_names)