def verify_conditions(question_directory,config,condition_list): ''' purpose verify each condition in condition_list on first failed condition, return error message otherwise, return None preconditions question_directory is a directory containing a config file config is a Python module reference condition_list is a list where each element is a list of two strings ''' conditions_dictionary = {} for condition in condition_list: conditions_dictionary[condition[0]] = condition[1] for v in ['product_family','question_type','message','parity', 'code_word_indexes']: if not (v in dir(config)): return(conditions_dictionary['variables_defined']) if not (config.product_family == 'hamming'): return(conditions_dictionary['product_family']) if not (config.question_type in ['fill','find_error']): return(conditions_dictionary['question_type']) if not (type(config.parity) is int and config.parity in [0,1]): return(conditions_dictionary['parity']) if not (type(config.message) == str and len(config.message) > 0): return conditions_dictionary['message'] for character in config.message: if not (character in ['0','1']): return conditions_dictionary['message'] code_word_length = hamming_util.get_code_word_length( len(config.message)) if config.question_type == 'fill': if not (type(config.code_word_indexes) is list and len(config.code_word_indexes) == len(set(config.code_word_indexes))): return conditions_dictionary['fill'] for i in config.code_word_indexes: if not (i in range(1,code_word_length+1)): return conditions_dictionary['fill'] if config.question_type == 'find_error': if not (type(config.code_word_indexes) is int): return conditions_dictionary['find_error'] if not (config.code_word_indexes in range(1,code_word_length+1)): return conditions_dictionary['find_error'] return None # no errors found
def verify_conditions(question_directory, config, condition_list): ''' purpose verify each condition in condition_list on first failed condition, return error message otherwise, return None preconditions question_directory is a directory containing a config file config is a Python module reference condition_list is a list where each element is a list of two strings ''' conditions_dictionary = {} for condition in condition_list: conditions_dictionary[condition[0]] = condition[1] for v in [ 'product_family', 'question_type', 'message', 'parity', 'code_word_indexes' ]: if not (v in dir(config)): return (conditions_dictionary['variables_defined']) if not (config.product_family == 'hamming'): return (conditions_dictionary['product_family']) if not (config.question_type in ['fill', 'find_error']): return (conditions_dictionary['question_type']) if not (type(config.parity) is int and config.parity in [0, 1]): return (conditions_dictionary['parity']) if not (type(config.message) == str and len(config.message) > 0): return conditions_dictionary['message'] for character in config.message: if not (character in ['0', '1']): return conditions_dictionary['message'] code_word_length = hamming_util.get_code_word_length(len(config.message)) if config.question_type == 'fill': if not (type(config.code_word_indexes) is list and len(config.code_word_indexes) == len( set(config.code_word_indexes))): return conditions_dictionary['fill'] for i in config.code_word_indexes: if not (i in range(1, code_word_length + 1)): return conditions_dictionary['fill'] if config.question_type == 'find_error': if not (type(config.code_word_indexes) is int): return conditions_dictionary['find_error'] if not (config.code_word_indexes in range(1, code_word_length + 1)): return conditions_dictionary['find_error'] return None # no errors found
def verify_conditions(template,condition_list): ''' purpose verify each condition in condition_list on first failed condition, return error message otherwise, return None preconditions template was returned by file_util.dynamic_import() condition_list is a list where each element is a list of two strings ''' # convert conditions to dictionary conditions_dictionary = {} for condition in condition_list: conditions_dictionary[condition[0]] = condition[1] # test the conditions if not ('tuples' in dir(template)): return conditions_dictionary['tuples_defined'] if not (type(template.tuples) == list): return conditions_dictionary['tuples_list'] group_list = [] for group in template.tuples: if not (type(group) == list and len(group) >= 2): return conditions_dictionary['group_format'] + \ '\n\tgroup: ' + str(group) if not (type(group[0]) == str and group[0] not in group_list): return conditions_dictionary['group_unique'] + \ '\n\tgroup: ' + str(group) else: group_list.append(group[0]) for tuple in group[1:]: if not (type(tuple) == list and len(tuple) == 3): return conditions_dictionary['tuple_format'] + \ '\n\ttuple: ' + str(tuple) if not (type(tuple[0]) == str and len(tuple[0]) > 0): return conditions_dictionary['message'] + \ '\n\ttuple: ' + str(tuple) for character in tuple[0]: if not (character in ['0','1']): return conditions_dictionary[ \ 'message'] + '\n\ttuple: ' + str(tuple) if not (tuple[1] in [0,1]): return conditions_dictionary['parity'] + \ '\n\ttuple: ' + str(tuple) code_word_length = hamming_util.get_code_word_length( len(tuple[0])) if type(tuple[2]) == list: if not (len(tuple[2]) == len(set(tuple[2]))): return conditions_dictionary[ \ 'fill'] + '\n\ttuple: ' + str(tuple) for i in tuple[2]: if not ( i in range(1,code_word_length+1)): return conditions_dictionary[ \ 'fill'] + '\n\ttuple: ' + \ str(tuple) elif type(tuple[2]) == int: if not ( tuple[2] in range(1,code_word_length+1)): return conditions_dictionary[ \ 'find_error'] + '\n\ttuple: ' + \ str(tuple) else: return conditions_dictionary['indexes'] + \ '\n\ttuple: ' + str(tuple) # all passed return None
def verify_conditions(template, condition_list): ''' purpose verify each condition in condition_list on first failed condition, return error message otherwise, return None preconditions template was returned by file_util.dynamic_import() condition_list is a list where each element is a list of two strings ''' # convert conditions to dictionary conditions_dictionary = {} for condition in condition_list: conditions_dictionary[condition[0]] = condition[1] # test the conditions if not ('tuples' in dir(template)): return conditions_dictionary['tuples_defined'] if not (type(template.tuples) == list): return conditions_dictionary['tuples_list'] group_list = [] for group in template.tuples: if not (type(group) == list and len(group) >= 2): return conditions_dictionary['group_format'] + \ '\n\tgroup: ' + str(group) if not (type(group[0]) == str and group[0] not in group_list): return conditions_dictionary['group_unique'] + \ '\n\tgroup: ' + str(group) else: group_list.append(group[0]) for tuple in group[1:]: if not (type(tuple) == list and len(tuple) == 3): return conditions_dictionary['tuple_format'] + \ '\n\ttuple: ' + str(tuple) if not (type(tuple[0]) == str and len(tuple[0]) > 0): return conditions_dictionary['message'] + \ '\n\ttuple: ' + str(tuple) for character in tuple[0]: if not (character in ['0', '1']): return conditions_dictionary[ \ 'message'] + '\n\ttuple: ' + str(tuple) if not (tuple[1] in [0, 1]): return conditions_dictionary['parity'] + \ '\n\ttuple: ' + str(tuple) code_word_length = hamming_util.get_code_word_length(len(tuple[0])) if type(tuple[2]) == list: if not (len(tuple[2]) == len(set(tuple[2]))): return conditions_dictionary[ \ 'fill'] + '\n\ttuple: ' + str(tuple) for i in tuple[2]: if not (i in range(1, code_word_length + 1)): return conditions_dictionary[ \ 'fill'] + '\n\ttuple: ' + \ str(tuple) elif type(tuple[2]) == int: if not (tuple[2] in range(1, code_word_length + 1)): return conditions_dictionary[ \ 'find_error'] + '\n\ttuple: ' + \ str(tuple) else: return conditions_dictionary['indexes'] + \ '\n\ttuple: ' + str(tuple) # all passed return None