Skip to content

Commit

Permalink
Merge pull request #250 from cirosantilli/deal-invalid-unicode
Browse files Browse the repository at this point in the history
Don't raise exception on invalid UTF-8 output
  • Loading branch information
jgm committed Dec 23, 2014
2 parents b28c97c + 46633b1 commit 9d4174f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/spec_tests.py
Expand Up @@ -37,20 +37,30 @@ def do_test(test, normalize):
[retcode, actual_html, err] = cmark.to_html(test['markdown'])
if retcode == 0:
expected_html = test['html']
unicode_error = None
if normalize:
passed = normalize_html(actual_html) == normalize_html(expected_html)
try:
passed = normalize_html(actual_html) == normalize_html(expected_html)
except UnicodeDecodeError, e:
unicode_error = e
passed = False
else:
passed = actual_html == expected_html
if passed:
return 'pass'
else:
print_test_header(test['section'], test['example'], test['start_line'], test['end_line'])
sys.stdout.write(test['markdown'])
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)
if unicode_error:
print "Unicode error: " + str(unicode_error)
print repr(expected_html)
print 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')
return 'fail'
else:
Expand Down

0 comments on commit 9d4174f

Please sign in to comment.