def do_test(test, normalize): [retcode, actual_html, err] = cmark.to_html(test['markdown']) if retcode == 0: expected_html = test['html'] if normalize: passed = normalize_html(actual_html) == normalize_html(expected_html) else: passed = actual_html == expected_html if passed: return 'pass' else: print_test_header(headertext, example_number,start_line,end_line) sys.stdout.write(test['markdown']) expected_html_lines = '\n'.split(expected_html) actual_html_lines = actual_html.splitlines(True) for diffline in unified_diff(expected_html_lines, actual_html_lines, "expected HTML", "actual HTML"): sys.stdout.write(diffline) sys.stdout.write('\n') return 'fail' else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) print "program returned error code %d" % retcode print(err) return 'error'
def do_test(test, normalize): [retcode, actual_html, err] = cmark.to_html(test['markdown']) if retcode == 0: expected_html = test['html'] if normalize: passed = normalize_html(actual_html) == normalize_html( expected_html) else: passed = actual_html == expected_html if passed: return 'pass' else: print_test_header(headertext, example_number, start_line, end_line) sys.stdout.write(test['markdown']) expected_html_lines = '\n'.split(expected_html) actual_html_lines = actual_html.splitlines(True) for diffline in unified_diff(expected_html_lines, actual_html_lines, "expected HTML", "actual HTML"): sys.stdout.write(diffline) sys.stdout.write('\n') return 'fail' else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) print "program returned error code %d" % retcode print(err) return 'error'
def do_test(test, normalize, result_counts): [retcode, actual_html, err] = cmark.to_html(test['markdown']) if retcode == 0: expected_html = test['html'] unicode_error = None if normalize: try: passed = normalize_html(actual_html) == normalize_html(expected_html) except UnicodeDecodeError as e: unicode_error = e passed = False else: passed = actual_html == expected_html if passed: result_counts['pass'] += 1 else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) sys.stdout.write(test['markdown']) if unicode_error: print("Unicode error: " + str(unicode_error)) print("Expected: " + repr(expected_html)) print("Got: " + repr(actual_html)) else: expected_html_lines = expected_html.splitlines(True) actual_html_lines = actual_html.splitlines(True) for diffline in unified_diff(expected_html_lines, actual_html_lines, "expected HTML", "actual HTML"): sys.stdout.write(diffline) sys.stdout.write('\n') result_counts['fail'] += 1 else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) print("program returned error code %d" % retcode) print(err) result_counts['error'] += 1
def test_html_output(test_case, md4c_version): """Test HTMLRenderer with default render flags on the given example""" skip_if_older_version(md4c_version, test_case['md4c_version']) parser_flags = 0 for extension in test_case['extensions']: parser_flags |= extension_flags[extension] renderer = md4c.HTMLRenderer(parser_flags, 0) output = renderer.parse(test_case['markdown']) assert normalize_html(output) == normalize_html(test_case['html'], False)
def do_test(test, normalize, prev_result): [retcode, actual_html_bytes, err] = cmark.to_html(test['markdown']) if retcode != 0: if prev_result != 'error': print_test_header(test) out("program returned error code %d\n" % retcode) sys.stdout.buffer.write(err) return 'error' expected_html = test['html'] try: actual_html = actual_html_bytes.decode('utf-8') except UnicodeDecodeError as e: if prev_result != 'fail': print_test_header(test) out(test['markdown'] + '\n') out("Unicode error: " + str(e) + '\n') out("Expected: " + repr(expected_html) + '\n') out("Got: " + repr(actual_html_bytes) + '\n') out('\n') return 'fail' if normalize: actual_html = normalize_html(actual_html) + '\n' expected_html = normalize_html(expected_html) + '\n' if actual_html != expected_html: if prev_result != 'fail': print_test_header(test) out(test['markdown'] + '\n') expected_html_lines = expected_html.splitlines(True) actual_html_lines = actual_html.splitlines(True) for diffline in unified_diff(expected_html_lines, actual_html_lines, "expected HTML", "actual HTML"): out(diffline) out('\n') return 'fail' if prev_result and prev_result != 'pass': print_test_header(test) print('fixed!') return 'pass'
def do_test(converter, test, normalize, result_counts): [retcode, actual_html, err] = converter(test['markdown'], test['extensions']) actual_html = re.sub(r'\r\n', '\n', actual_html) if retcode == 0: expected_html = re.sub(r'\r\n', '\n', test['html']) unicode_error = None if expected_html.strip() == '<IGNORE>': passed = True elif normalize: try: passed = normalize_html(actual_html) == normalize_html( expected_html) except UnicodeDecodeError as e: unicode_error = e passed = False else: passed = actual_html == expected_html if passed: result_counts['pass'] += 1 else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) out(test['markdown'] + '\n') if unicode_error: out("Unicode error: " + str(unicode_error) + '\n') out("Expected: " + repr(expected_html) + '\n') out("Got: " + repr(actual_html) + '\n') else: expected_html_lines = expected_html.splitlines(True) actual_html_lines = actual_html.splitlines(True) for diffline in unified_diff(expected_html_lines, actual_html_lines, "expected HTML", "actual HTML"): out(diffline) out('\n') result_counts['fail'] += 1 else: print_test_header(test['section'], test['example'], test['start_line'], test['end_line']) out("program returned error code %d\n" % retcode) sys.stdout.buffer.write(err) result_counts['error'] += 1
def run_tests(tests, compilers, args): total_tests = 0 total_compilers = len(compilers) errors = [0] * total_compilers times = [0.0] * total_compilers tests = itertools.ifilter(lambda test: re.match(args.filter, test['section']), tests) for test in tests: total_tests += 1 single_test_errors = 0 for i, compiler in enumerate(compilers): start_time = time.time() if i != 0 and i % 5 == 0: stdout_flush(' ') if not args.number or total == args.number: fail = False try: if (normalize.normalize_html(compiler.to_html(test['markdown'])) != normalize.normalize_html(test['html'])): # Debugging #print repr(normalize.normalize_html(compiler.to_html(test['markdown']))) #print repr(normalize.normalize_html(test['html'])) fail = True except UnicodeDecodeError: fail = True if fail: errors[i] += 1 single_test_errors += 1 stdout_flush('F') else: stdout_flush('.') times[i] += time.time() - start_time stdout_flush(' | ') stdout_flush('{} {} {} {} {}\n'.format( test['example'], test['start_line'], test['end_line'], single_test_errors, test['section']) ) return total_tests, errors, times
elif l == ".": state = 2 elif state == 1: if start_line == 0: start_line = line_number - 1 markdown_lines.append(line) elif state == 2: html_lines.append(line) elif state == 0 and re.match(header_re, line): headertext = header_re.sub('', line).strip() return tests if __name__ == "__main__": if args.debug_normalization: out(normalize_html(sys.stdin.read())) exit(0) all_tests = get_tests(args.spec) if args.pattern: pattern_re = re.compile(args.pattern, re.IGNORECASE) else: pattern_re = re.compile('.') tests = [ test for test in all_tests if re.search(pattern_re, test['section']) and ( not args.number or test['example'] == args.number) ] if args.dump_tests: out(json.dumps(tests, ensure_ascii=False, indent=2)) exit(0)
pattern_re = re.compile('.') for test in tests: if re.search(pattern_re, test['section']): result = do_test(test, normalize) if result == 'pass': passed += 1 elif result == 'fail': failed += 1 else: errored += 1 else: skipped += 1 print "%d passed, %d failed, %d errored, %d skipped" % (passed, failed, errored, skipped) return (failed == 0 and errored == 0) if __name__ == "__main__": if args.debug_normalization: print normalize_html(sys.stdin.read()) exit(0) tests = get_tests(args.spec) if args.dump_tests: print json.dumps(tests, ensure_ascii=False, indent=2) exit(0) else: cmark = CMark(prog=args.program, library_dir=args.library_dir) if do_tests(cmark, tests, args.pattern, args.normalize): exit(0) else: exit(1)
if re.search(pattern_re, test['section']): result = do_test(test, normalize) if result == 'pass': passed += 1 elif result == 'fail': failed += 1 else: errored += 1 else: skipped += 1 print "%d passed, %d failed, %d errored, %d skipped" % (passed, failed, errored, skipped) return (failed == 0 and errored == 0) if __name__ == "__main__": if args.debug_normalization: print normalize_html(sys.stdin.read()) exit(0) tests = get_tests(args.spec) if args.dump_tests: print json.dumps(tests, ensure_ascii=False, indent=2) exit(0) else: cmark = CMark(prog=args.program, library_dir=args.library_dir) if do_tests(cmark, tests, args.pattern, args.normalize): exit(0) else: exit(1)
html_lines = [] elif l == ".": state = 2 elif state == 1: if start_line == 0: start_line = line_number - 1 markdown_lines.append(line) elif state == 2: html_lines.append(line) elif state == 0 and re.match(header_re, line): headertext = header_re.sub('', line).strip() return tests if __name__ == "__main__": if args.debug_normalization: out(normalize_html(sys.stdin.read())) exit(0) all_tests = get_tests(args.spec) if args.pattern: pattern_re = re.compile(args.pattern, re.IGNORECASE) else: pattern_re = re.compile('.') tests = [ test for test in all_tests if re.search(pattern_re, test['section']) and (not args.number or test['example'] == args.number) ] if args.dump_tests: out(json.dumps(tests, ensure_ascii=False, indent=2)) exit(0) else: skipped = len(all_tests) - len(tests) cmark = CMark(prog=args.program, library_dir=args.library_dir) result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': skipped}