]> granicus.if.org Git - python/commitdiff
merge #12890: don't emit <p> tags in text mode when logdir specified.
authorR David Murray <rdmurray@bitdance.com>
Sat, 27 Oct 2012 18:55:25 +0000 (14:55 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 27 Oct 2012 18:55:25 +0000 (14:55 -0400)
Patch by Jeff McNeil.

1  2 
Lib/cgitb.py
Lib/test/test_cgitb.py
Misc/ACKS
Misc/NEWS

diff --cc Lib/cgitb.py
Simple merge
index 16a4b1a0347289cc9a34b6da18ec171a84f72b34,0000000000000000000000000000000000000000..4017772d033bdcfec9345b14c43aa78469f1918d
mode 100644,000000..100644
--- /dev/null
@@@ -1,55 -1,0 +1,72 @@@
-     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)
 +from test.support import run_unittest
++from test.script_helper import assert_python_failure, temp_dir
 +import unittest
 +import sys
 +import subprocess
++import tempfile
 +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")') % 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")') % 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()
diff --cc Misc/ACKS
index ac44ae81263965ecac3ebf46b6e55c6ac629af32,2b97f51a3777999e216f83df206f283398ee1f5e..3966ba67cc1f911c31fbe9910b3cc357ae04d400
+++ b/Misc/ACKS
@@@ -767,8 -697,9 +767,9 @@@ Alan McIntyr
  Michael McLay
  Mark Mc Mahon
  Gordon McMillan
 -Caolan McNamara
  Andrew McNamara
 +Caolan McNamara
+ Jeff McNeil
  Craig McPheeters
  Lambert Meertens
  Bill van Melle
diff --cc Misc/NEWS
index 9766633f7cdc6c4395e8702c8899cc8078899a0f,5010f70bd5304451b98e8b9f64b25de1e2e5e65a..ba555bb5ff93fea1e359e9c3b078985f017f2514
+++ b/Misc/NEWS
@@@ -49,15 -132,13 +49,18 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #12890: cgitb no longer prints spurious <p> tags in text
+   mode when the logdir option is specified.
 +- Issue #16307: Fix multiprocessing.Pool.map_async not calling its callbacks.
 +  Patch by Janne Karila.
 +
  - Issue #16250: Fix URLError invocation with proper args.
  
 -- Issue #16305: Fix a segmentation fault occurring when interrupting
 -  math.factorial.
 +- Issue #16116: Fix include and library paths to be correct when building C
 +  extensions in venvs.
 +
 +- Issue #16245: Fix the value of a few entities in html.entities.html5.
  
  - Issue #14398: Fix size truncation and overflow bugs in the bz2 module.