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