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.
 
 
 

49 lines
1.2 KiB

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