summaryrefslogtreecommitdiff
path: root/Lib/test/test_cgitb.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-03-07 18:16:47 -0500
committerR David Murray <rdmurray@bitdance.com>2013-03-07 18:16:47 -0500
commitd7fefe24a2289c2e077fc8d6703273d0dcb220bc (patch)
treef64cd20b6f37188146b27805dad42c7907a0a25e /Lib/test/test_cgitb.py
parentf0f272e28bdfa346c33bcacd4a78df4bbf837b67 (diff)
parentc2051f1fa112c1dc2b28d65e597eda85cb2e56ea (diff)
downloadcpython-d7fefe24a2289c2e077fc8d6703273d0dcb220bc.tar.gz
Merge: PEP8 fixup on previous patch, remove unused imports in test_email.
Diffstat (limited to 'Lib/test/test_cgitb.py')
-rw-r--r--Lib/test/test_cgitb.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py
new file mode 100644
index 0000000000..2e072a9f2a
--- /dev/null
+++ b/Lib/test/test_cgitb.py
@@ -0,0 +1,70 @@
+from test.support import run_unittest
+from test.script_helper import assert_python_failure, temp_dir
+import unittest
+import sys
+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_syshook_no_logdir_default_format(self):
+ with temp_dir() as tracedir:
+ rc, out, err = assert_python_failure(
+ '-c',
+ ('import cgitb; cgitb.enable(logdir=%s); '
+ 'raise ValueError("Hello World")') % repr(tracedir))
+ out = out.decode(sys.getfilesystemencoding())
+ self.assertIn("ValueError", out)
+ self.assertIn("Hello World", out)
+ # By default we emit HTML markup.
+ self.assertIn('<p>', out)
+ self.assertIn('</p>', out)
+
+ def test_syshook_no_logdir_text_format(self):
+ # Issue 12890: we were emitting the <p> tag in text mode.
+ with temp_dir() as tracedir:
+ rc, out, err = assert_python_failure(
+ '-c',
+ ('import cgitb; cgitb.enable(format="text", logdir=%s); '
+ 'raise ValueError("Hello World")') % repr(tracedir))
+ out = out.decode(sys.getfilesystemencoding())
+ self.assertIn("ValueError", out)
+ self.assertIn("Hello World", out)
+ self.assertNotIn('<p>', out)
+ self.assertNotIn('</p>', out)
+
+
+def test_main():
+ run_unittest(TestCgitb)
+
+if __name__ == "__main__":
+ test_main()