def compare_return_codes(name, flag, expected_return, fails): ret = 0 this_return = global_variables.code_returned expected = global_variables.get_return_code(expected_return) if this_return == expected_return: print('{0} returned \'{1}\' as expected'.format(name, expected)) else: ret = 1 fails.append('{0}: {1} {2}'.format(name, flag, expected_return)) print('Incorrect Return: {0} Expected: ' '{1}'.format(global_variables.get_return_code(this_return), global_variables.get_return_code(expected_return))) return ret
def run_deviser_test(name, flag, expected_return): """ General function for running command-line Deviser tests. :param name: general name of test :param flag: a command-line flag :param expected_return: what we expect the test to return. :return: 0 on success, 1 on failure """ error = gv.get_return_code(expected_return) filename = test_functions.set_up_test(name, flag, error) args = [] if flag in ['-g', '-l', 'wrong']: args.append('deviser') args.append(flag) args.append(filename) elif flag == 'missing': args.append('deviser') args.append(filename) generate_deviser(args) fail = test_functions.compare_return_codes(name, flag, expected_return, fails) print('') return fail
def compare_return_codes(name, flag, expected_return, fails): """ Compare return code from a test with that expected. :param name: general name of test :param flag: a command-line flag :param expected_return: expected return code from a test :param fails: list of failure cases :return: 0 on success, 1 on failure. """ ret = 0 this_return = gv.code_returned expected = gv.get_return_code(expected_return) if this_return == expected_return: print('{0} returned \'{1}\' as expected'.format(name, expected)) else: ret = 1 fails.append('{0}: {1} {2}'.format(name, flag, expected_return)) print('Incorrect Return: {0} Expected: ' '{1}'.format(gv.get_return_code(this_return), gv.get_return_code(expected_return))) return ret
def run_deviser_test(name, flag, expected_return): error = global_variables.get_return_code(expected_return) filename = test_functions.set_up_test(name, flag, error) args = [] if flag == '-g'or flag == '-l': args.append('deviser') args.append(flag) args.append(filename) elif flag == 'missing': args.append('deviser') args.append(filename) elif flag == 'wrong': args.append('deviser') args.append(flag) args.append(filename) generate_deviser(args) fail = test_functions.compare_return_codes(name, flag, expected_return, fails) print('') return fail
def report_error(code, message): global_variables.code_returned = code print('{0}'.format(global_variables.get_return_code(code))) print('{0}'.format(message))