A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.1 KiB

  1. import re
  2. import difflib
  3. def strip_spaces_between_tags(value):
  4. """
  5. Stolen from `django.util.html`
  6. Returns the given HTML with spaces between tags removed.
  7. """
  8. return re.sub(r'>\s+<', '><', unicode(value))
  9. def assert_no_diff(expected, out):
  10. diff = [l for l in difflib.unified_diff(expected.splitlines(True),
  11. out.splitlines(True),
  12. n=3)]
  13. assert not diff, ''.join(diff)
  14. def assert_html_equals(expected, actual, sanitize=None):
  15. expected = strip_spaces_between_tags(expected.strip())
  16. actual = strip_spaces_between_tags(actual.strip())
  17. if sanitize:
  18. expected = sanitize(expected)
  19. actual = sanitize(actual)
  20. assert expected == actual
  21. def trap_exit_fail(f):
  22. def test_wrapper(*args):
  23. try:
  24. f(*args)
  25. except SystemExit:
  26. assert False
  27. test_wrapper.__name__ = f.__name__
  28. return test_wrapper
  29. def trap_exit_pass(f):
  30. def test_wrapper(*args):
  31. try:
  32. f(*args)
  33. except SystemExit:
  34. pass
  35. test_wrapper.__name__ = f.__name__
  36. return test_wrapper