def test_ErrorTableNotInDB(tmpdir): '''Test the class ErrorTableNotInDB (error when a table doesn't exist in a database)''' # This file is not created, just a tmp path tmpfile = os.path.join(tmpdir.strpath, "tmpfile") # Test instantiation test_error = NCBImetaErrors.ErrorTableNotInDB(tmpfile) # Test str representation (error message) error_output = str(test_error) error_expect = ("\n\nThe table does not exist in the database." + "\n" + "Unknown table found: " + tmpfile) assert error_output == error_expect
raise NCBImetaErrors.ErrorAnnotFileNotExists(annot_file_name) # no errors were raised, safe to connect to db cur = conn.cursor() #---------------------------Check Table---------------------------------# # Check table name table_name = db_table table_name_sanitize = NCBImetaUtilities.sql_sanitize(table_name) if table_name != table_name_sanitize: raise NCBImetaErrors.ErrorSQLNameSanitize(table_name, table_name_sanitize) # Check table exists if not NCBImetaUtilities.table_exists(cur, db_table): raise NCBImetaErrors.ErrorTableNotInDB(db_table) #-----------------------------------------------------------------------# # File Setup # #-----------------------------------------------------------------------# # get list of column names in Table cur.execute('''SELECT * FROM {}'''.format(db_table)) db_col_names = [description[0] for description in cur.description] #-----------------------------------------------------------------------# # Annotation Setup # #-----------------------------------------------------------------------# annot_file = open(annot_file_name, "r") annot_dict = {}
for table_name in table_name_list: table_name_sanitize = NCBImetaUtilities.sql_sanitize(table_name) if table_name != table_name_sanitize: raise NCBImetaErrors.ErrorSQLNameSanitize(table_name, table_name_sanitize) # Check the column names for col_name in unique_header_list: col_name_sanitize = NCBImetaUtilities.sql_sanitize(col_name) if col_name != col_name_sanitize: raise NCBImetaErrors.ErrorSQLNameSanitize(col_name, col_name_sanitize) #---------------------------Check Tables Existence----------------------# if not NCBImetaUtilities.table_exists(cur, db_anchor): raise NCBImetaErrors.ErrorTableNotInDB(db_anchor) for table in db_accessory_list: if not NCBImetaUtilities.table_exists(cur, table): raise NCBImetaErrors.ErrorTableNotInDB(table) #-----------------------------------------------------------------------# # 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]