def print_post_run_stats(tests_passed, total_tests, durations): if durations: avg_median = avg_and_median_from_durations(durations) print('Average running time: {}\n' 'Median running time: {}\n'.format( duration_to_string(avg_median[0]), duration_to_string(avg_median[1])), end='') if tests_passed < total_tests: print('*** You\'ve passed {}/{} tests. ***'.format( tests_passed, total_tests)) else: print('*** You\'ve passed ALL tests. Congratulations! ***')
def print_post_run_stats(tests_passed, total_tests, durations): if durations: avg_median = avg_and_median_from_durations(durations) print( 'Average running time: {}\n' 'Median running time: {}\n'.format( duration_to_string(avg_median[0]), duration_to_string(avg_median[1])), end='') if tests_passed < total_tests: print('*** You\'ve passed {}/{} tests. ***'.format( tests_passed, total_tests)) else: print('*** You\'ve passed ALL tests. Congratulations! ***')
def print_test_info(test_result, test_nr, total_tests, diagnostic, timer): diagnostic = diagnostic.rstrip('\n') caret_at_line_start = print_test_info.__dict__.get('caret_at_line_start', True) if not caret_at_line_start: clear_line_if_tty() total_tests_str = str(total_tests) print('Test ', end='') print_test_result(test_result) print(' ({:>{test_nr_w}}/{})'.format(test_nr, total_tests_str, diagnostic, test_nr_w=len(total_tests_str)), end='', flush=True) if timer is not None: print(' [{}]'.format(duration_to_string(timer.get_microseconds())), end='', flush=True) print_test_info.caret_at_line_start = False if test_result != TestResult.PASSED: print(' {}'.format(diagnostic), flush=True) print_test_info.caret_at_line_start = True
def print_test_info(test_result, test_nr, total_tests, diagnostic, timer): diagnostic = diagnostic.rstrip('\n') return_caret_if_tty_output() total_tests_str = str(total_tests) print('Test ', end='') print_test_result(test_result) print( ' ({:>{test_nr_w}}/{})'.format( test_nr, total_tests_str, diagnostic, test_nr_w=len(total_tests_str)), end='', flush=True) if timer.has_valid_result(): print( ' [{}]'.format(duration_to_string(timer.get_microseconds())), end='', flush=True) if test_result != TestResult.PASSED: print(' {}'.format(diagnostic))
def print_test_info(test_result, test_nr, total_tests, diagnostic, timer): diagnostic = diagnostic.rstrip("\n") caret_at_line_start = print_test_info.__dict__.get("caret_at_line_start", True) if not caret_at_line_start: clear_line_if_tty() total_tests_str = str(total_tests) print("Test ", end="") print_test_result(test_result) print( " ({:>{test_nr_w}}/{})".format(test_nr, total_tests_str, test_nr_w=len(total_tests_str)), end="", flush=True, ) if timer is not None: print( " [{}]".format(duration_to_string(timer.get_microseconds())), end="", flush=True, ) print_test_info.caret_at_line_start = False if test_result != TestResult.PASSED: print(" {}".format(diagnostic), flush=True) print_test_info.caret_at_line_start = True
def print_test_info(test_result, test_nr, total_tests, diagnostic, timer): diagnostic = diagnostic.rstrip('\n') caret_at_line_start = print_test_info.__dict__.get('caret_at_line_start', True) if not caret_at_line_start: clear_line_if_tty() total_tests_str = str(total_tests) print('Test ', end='') print_test_result(test_result) print( ' ({:>{test_nr_w}}/{})'.format( test_nr, total_tests_str, diagnostic, test_nr_w=len(total_tests_str)), end='', flush=True) if timer is not None: print( ' [{}]'.format(duration_to_string(timer.get_microseconds())), end='', flush=True) print_test_info.caret_at_line_start = False if test_result != TestResult.PASSED: print(' {}'.format(diagnostic), flush=True) print_test_info.caret_at_line_start = True
def print_post_run_stats(tests_passed, total_tests, complexity, durations): if durations: if complexity: print("Time complexity: {}".format(complexity)) avg_median = avg_and_median_from_durations(durations) print( "Average running time: {}\n" "Median running time: {}\n".format( duration_to_string(avg_median[0]), duration_to_string(avg_median[1]), ), end="", ) if tests_passed < total_tests: print("*** You've passed {}/{} tests. ***".format( tests_passed, total_tests)) else: print("*** You've passed ALL tests. Congratulations! ***")
def run_tests(test_data_path, handler, timeout, stop_on_error, res_printer): test_data = split_tsv_file(test_data_path) handler.parse_signature(test_data[0]) param_names = handler.param_names() first_test_idx = 1 test_nr = 0 total_tests = len(test_data) - first_test_idx tests_passed = 0 durations = [] for test_case in test_data[first_test_idx:]: test_nr += 1 test_explanation = test_case.pop() result = TestResult.FAILED test_output = None diagnostic = '' try: if timeout != 0: with concurrent.futures.ThreadPoolExecutor( max_workers=1) as executor: future = executor.submit(handler.run_test, test_case) test_output = future.result(timeout=timeout) result = TestResult.PASSED if test_output.comparison_result \ else TestResult.FAILED else: test_output = handler.run_test(test_case) result = TestResult.PASSED if test_output.comparison_result \ else TestResult.FAILED except TestFailureException as exc: result = TestResult.FAILED diagnostic = str(exc) except concurrent.futures.TimeoutError: result = TestResult.TIMEOUT except RecursionError: result = TestResult.STACK_OVERFLOW except RuntimeError: raise except Exception as exc: result = TestResult.UNKNOWN_EXCEPTION diagnostic = exc.__class__.__name__ + ': ' + str(exc) if test_output is None: test_output = TestOutput(False, TestTimer()) # Append expected value if execution ended due to an exception if not handler.expected_is_void(): test_output.expected = test_case[-1] print_test_info(result, test_nr, total_tests, diagnostic, test_output.timer) tests_passed += 1 if result == TestResult.PASSED else 0 if test_output.timer.has_valid_result(): durations.append(test_output.timer.get_microseconds()) if result != TestResult.PASSED and stop_on_error: if not handler.expected_is_void(): test_case = test_case[:-1] print_failed_test(param_names, test_case, test_output, test_explanation, res_printer) break print() if stop_on_error: if len(durations): print("Average running time: {}".format( duration_to_string(statistics.mean(durations)))) print("Median running time: {}".format( duration_to_string(statistics.median(durations)))) if tests_passed < total_tests: print("*** You've passed {}/{} tests. ***".format( tests_passed, total_tests)) else: print("*** You've passed ALL tests. Congratulations! ***")