test_htmlizer.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.python.htmlizer}.
  5. """
  6. from io import BytesIO
  7. from twisted.trial.unittest import TestCase
  8. from twisted.python.htmlizer import filter
  9. class FilterTests(TestCase):
  10. """
  11. Tests for L{twisted.python.htmlizer.filter}.
  12. """
  13. def test_empty(self):
  14. """
  15. If passed an empty input file, L{filter} writes a I{pre} tag containing
  16. only an end marker to the output file.
  17. """
  18. input = BytesIO(b"")
  19. output = BytesIO()
  20. filter(input, output)
  21. self.assertEqual(
  22. output.getvalue(),
  23. b'<pre><span class="py-src-endmarker"></span></pre>\n')
  24. def test_variable(self):
  25. """
  26. If passed an input file containing a variable access, L{filter} writes
  27. a I{pre} tag containing a I{py-src-variable} span containing the
  28. variable.
  29. """
  30. input = BytesIO(b"foo\n")
  31. output = BytesIO()
  32. filter(input, output)
  33. self.assertEqual(
  34. output.getvalue(),
  35. b'<pre><span class="py-src-variable">foo</span>'
  36. b'<span class="py-src-newline">\n'
  37. b'</span><span class="py-src-endmarker"></span></pre>\n')