ยปCore Development>Code coverage>Lib/test/test_cgitb.py

Python code coverage for Lib/test/test_cgitb.py

#countcontent
1n/afrom test.support import temp_dir
2n/afrom test.support.script_helper import assert_python_failure
3n/aimport unittest
4n/aimport sys
5n/aimport cgitb
6n/a
7n/aclass TestCgitb(unittest.TestCase):
8n/a
9n/a def test_fonts(self):
10n/a text = "Hello Robbie!"
11n/a self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
12n/a self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
13n/a self.assertEqual(cgitb.grey(text),
14n/a '<font color="#909090">{}</font>'.format(text))
15n/a
16n/a def test_blanks(self):
17n/a self.assertEqual(cgitb.small(""), "")
18n/a self.assertEqual(cgitb.strong(""), "")
19n/a self.assertEqual(cgitb.grey(""), "")
20n/a
21n/a def test_html(self):
22n/a try:
23n/a raise ValueError("Hello World")
24n/a except ValueError as err:
25n/a # If the html was templated we could do a bit more here.
26n/a # At least check that we get details on what we just raised.
27n/a html = cgitb.html(sys.exc_info())
28n/a self.assertIn("ValueError", html)
29n/a self.assertIn(str(err), html)
30n/a
31n/a def test_text(self):
32n/a try:
33n/a raise ValueError("Hello World")
34n/a except ValueError as err:
35n/a text = cgitb.text(sys.exc_info())
36n/a self.assertIn("ValueError", text)
37n/a self.assertIn("Hello World", text)
38n/a
39n/a def test_syshook_no_logdir_default_format(self):
40n/a with temp_dir() as tracedir:
41n/a rc, out, err = assert_python_failure(
42n/a '-c',
43n/a ('import cgitb; cgitb.enable(logdir=%s); '
44n/a 'raise ValueError("Hello World")') % repr(tracedir))
45n/a out = out.decode(sys.getfilesystemencoding())
46n/a self.assertIn("ValueError", out)
47n/a self.assertIn("Hello World", out)
48n/a # By default we emit HTML markup.
49n/a self.assertIn('<p>', out)
50n/a self.assertIn('</p>', out)
51n/a
52n/a def test_syshook_no_logdir_text_format(self):
53n/a # Issue 12890: we were emitting the <p> tag in text mode.
54n/a with temp_dir() as tracedir:
55n/a rc, out, err = assert_python_failure(
56n/a '-c',
57n/a ('import cgitb; cgitb.enable(format="text", logdir=%s); '
58n/a 'raise ValueError("Hello World")') % repr(tracedir))
59n/a out = out.decode(sys.getfilesystemencoding())
60n/a self.assertIn("ValueError", out)
61n/a self.assertIn("Hello World", out)
62n/a self.assertNotIn('<p>', out)
63n/a self.assertNotIn('</p>', out)
64n/a
65n/a
66n/aif __name__ == "__main__":
67n/a unittest.main()