diff options
author | Brian Curtin <brian@python.org> | 2011-07-06 00:14:16 (GMT) |
---|---|---|
committer | Brian Curtin <brian@python.org> | 2011-07-06 00:14:16 (GMT) |
commit | 6a4ffd7295e4c6a1da4f0ef4e381ebfbc1bff398 (patch) | |
tree | 7f73a8df5d3370d410f00ba110c2fb2f6d0bf946 /Lib/test/test_cgitb.py | |
parent | 7f53a5027d9e290dc288ed2d931ea4c383c416af (diff) | |
download | cpython-6a4ffd7295e4c6a1da4f0ef4e381ebfbc1bff398.zip cpython-6a4ffd7295e4c6a1da4f0ef4e381ebfbc1bff398.tar.gz cpython-6a4ffd7295e4c6a1da4f0ef4e381ebfbc1bff398.tar.bz2 |
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Patch by Robbie Clemons (robquad), produced at the PyCon 2011 sprints.
Diffstat (limited to 'Lib/test/test_cgitb.py')
-rw-r--r-- | Lib/test/test_cgitb.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py new file mode 100644 index 0000000..f7e851a --- /dev/null +++ b/Lib/test/test_cgitb.py @@ -0,0 +1,55 @@ +from test.support import run_unittest +import unittest +import sys +import subprocess +import cgitb + +class TestCgitb(unittest.TestCase): + + def test_fonts(self): + text = "Hello Robbie!" + self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text)) + self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text)) + self.assertEqual(cgitb.grey(text), + '<font color="#909090">{}</font>'.format(text)) + + def test_blanks(self): + self.assertEqual(cgitb.small(""), "") + self.assertEqual(cgitb.strong(""), "") + self.assertEqual(cgitb.grey(""), "") + + def test_html(self): + try: + raise ValueError("Hello World") + except ValueError as err: + # If the html was templated we could do a bit more here. + # At least check that we get details on what we just raised. + html = cgitb.html(sys.exc_info()) + self.assertIn("ValueError", html) + self.assertIn(str(err), html) + + def test_text(self): + try: + raise ValueError("Hello World") + except ValueError as err: + text = cgitb.text(sys.exc_info()) + self.assertIn("ValueError", text) + self.assertIn("Hello World", text) + + def test_hook(self): + proc = subprocess.Popen([sys.executable, '-c', + ('import cgitb;' + 'cgitb.enable();' + 'raise ValueError("Hello World")')], + stdout=subprocess.PIPE) + out = proc.stdout.read().decode(sys.getfilesystemencoding()) + self.addCleanup(proc.stdout.close) + self.assertIn("ValueError", out) + self.assertIn("Hello World", out) + + +def test_main(): + run_unittest(TestCgitb) + +if __name__ == "__main__": + test_main() |