(original) (raw)

changeset: 71238:7e0102ec95d4 parent: 71236:0e5485634817 user: Brian Curtin brian@python.org date: Tue Jul 05 19:14:16 2011 -0500 files: Lib/test/test_cgitb.py Misc/ACKS Misc/NEWS description: Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage. Patch by Robbie Clemons (robquad), produced at the PyCon 2011 sprints. diff -r 0e5485634817 -r 7e0102ec95d4 Lib/test/test_cgitb.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_cgitb.py Tue Jul 05 19:14:16 2011 -0500 @@ -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), "{}".format(text)) + self.assertEqual(cgitb.strong(text), "{}".format(text)) + self.assertEqual(cgitb.grey(text), + '{}'.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() diff -r 0e5485634817 -r 7e0102ec95d4 Misc/ACKS --- a/Misc/ACKS Tue Jul 05 22:00:25 2011 +0200 +++ b/Misc/ACKS Tue Jul 05 19:14:16 2011 -0500 @@ -175,6 +175,7 @@ Mike Clarkson Andrew Clegg Brad Clements +Robbie Clemons Steve Clift Nick Coghlan Josh Cogliati diff -r 0e5485634817 -r 7e0102ec95d4 Misc/NEWS --- a/Misc/NEWS Tue Jul 05 22:00:25 2011 +0200 +++ b/Misc/NEWS Tue Jul 05 19:14:16 2011 -0500 @@ -994,6 +994,8 @@ Tests ----- +- Issue #11512: Add a test suite for the cgitb module. Patch by Robbie Clemons. + - Issue #12497: Install test/data to prevent failures of the various codecmaps tests. /brian@python.org