cpython: 7e0102ec95d4 (original) (raw)
Mercurial > cpython
changeset 71238:7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage. Patch by Robbie Clemons (robquad), produced at the PyCon 2011 sprints. [#11512]
Brian Curtin brian@python.org | |
---|---|
date | Tue, 05 Jul 2011 19:14:16 -0500 |
parents | 0e5485634817 |
children | f362f0053eab |
files | Lib/test/test_cgitb.py Misc/ACKS Misc/NEWS |
diffstat | 3 files changed, 58 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_cgitb.py 55 Misc/ACKS 1 Misc/NEWS 2 |
line wrap: on
line diff
new file mode 100644 --- /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!"[](#l1.14)
self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))[](#l1.15)
self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))[](#l1.16)
self.assertEqual(cgitb.grey(text),[](#l1.17)
'<font color="#909090">{}</font>'.format(text))[](#l1.18)
- def test_blanks(self):
self.assertEqual(cgitb.small(""), "")[](#l1.21)
self.assertEqual(cgitb.strong(""), "")[](#l1.22)
self.assertEqual(cgitb.grey(""), "")[](#l1.23)
[](#l1.24)
- def test_html(self):
try:[](#l1.26)
raise ValueError("Hello World")[](#l1.27)
except ValueError as err:[](#l1.28)
# If the html was templated we could do a bit more here.[](#l1.29)
# At least check that we get details on what we just raised.[](#l1.30)
html = cgitb.html(sys.exc_info())[](#l1.31)
self.assertIn("ValueError", html)[](#l1.32)
self.assertIn(str(err), html)[](#l1.33)
- def test_text(self):
try:[](#l1.36)
raise ValueError("Hello World")[](#l1.37)
except ValueError as err:[](#l1.38)
text = cgitb.text(sys.exc_info())[](#l1.39)
self.assertIn("ValueError", text)[](#l1.40)
self.assertIn("Hello World", text)[](#l1.41)
[](#l1.42)
- def test_hook(self):
proc = subprocess.Popen([sys.executable, '-c',[](#l1.44)
('import cgitb;' [](#l1.45)
'cgitb.enable();' [](#l1.46)
'raise ValueError("Hello World")')],[](#l1.47)
stdout=subprocess.PIPE)[](#l1.48)
out = proc.stdout.read().decode(sys.getfilesystemencoding())[](#l1.49)
self.addCleanup(proc.stdout.close)[](#l1.50)
self.assertIn("ValueError", out)[](#l1.51)
self.assertIn("Hello World", out)[](#l1.52)
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -175,6 +175,7 @@ David Cinege Mike Clarkson Andrew Clegg Brad Clements +Robbie Clemons Steve Clift Nick Coghlan Josh Cogliati
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -994,6 +994,8 @@ Extension Modules Tests ----- +- Issue #11512: Add a test suite for the cgitb module. Patch by Robbie Clemons. +