annotate Lib/test/test_cgitb.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 7648b7ed6d91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
1 from test.support import run_unittest
79973
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
2 from test.script_helper import assert_python_failure, temp_dir
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
3 import unittest
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
4 import sys
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
5 import cgitb
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
6
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
7 class TestCgitb(unittest.TestCase):
71239
f362f0053eab Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents: 71238
diff changeset
8
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
9 def test_fonts(self):
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
10 text = "Hello Robbie!"
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
11 self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
12 self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
13 self.assertEqual(cgitb.grey(text),
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
14 '<font color="#909090">{}</font>'.format(text))
71239
f362f0053eab Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents: 71238
diff changeset
15
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
16 def test_blanks(self):
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
17 self.assertEqual(cgitb.small(""), "")
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
18 self.assertEqual(cgitb.strong(""), "")
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
19 self.assertEqual(cgitb.grey(""), "")
71239
f362f0053eab Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents: 71238
diff changeset
20
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
21 def test_html(self):
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
22 try:
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
23 raise ValueError("Hello World")
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
24 except ValueError as err:
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
25 # If the html was templated we could do a bit more here.
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
26 # At least check that we get details on what we just raised.
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
27 html = cgitb.html(sys.exc_info())
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
28 self.assertIn("ValueError", html)
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
29 self.assertIn(str(err), html)
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
30
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
31 def test_text(self):
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
32 try:
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
33 raise ValueError("Hello World")
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
34 except ValueError as err:
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
35 text = cgitb.text(sys.exc_info())
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
36 self.assertIn("ValueError", text)
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
37 self.assertIn("Hello World", text)
71239
f362f0053eab Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents: 71238
diff changeset
38
79973
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
39 def test_syshook_no_logdir_default_format(self):
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
40 with temp_dir() as tracedir:
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
41 rc, out, err = assert_python_failure(
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
42 '-c',
80070
7648b7ed6d91 #12890: fix test on windows
R David Murray <rdmurray@bitdance.com>
parents: 79992
diff changeset
43 ('import cgitb; cgitb.enable(logdir=%s); '
7648b7ed6d91 #12890: fix test on windows
R David Murray <rdmurray@bitdance.com>
parents: 79992
diff changeset
44 'raise ValueError("Hello World")') % repr(tracedir))
79973
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
45 out = out.decode(sys.getfilesystemencoding())
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
46 self.assertIn("ValueError", out)
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
47 self.assertIn("Hello World", out)
79973
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
48 # By default we emit HTML markup.
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
49 self.assertIn('<p>', out)
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
50 self.assertIn('</p>', out)
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
51
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
52 def test_syshook_no_logdir_text_format(self):
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
53 # Issue 12890: we were emitting the <p> tag in text mode.
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
54 with temp_dir() as tracedir:
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
55 rc, out, err = assert_python_failure(
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
56 '-c',
80070
7648b7ed6d91 #12890: fix test on windows
R David Murray <rdmurray@bitdance.com>
parents: 79992
diff changeset
57 ('import cgitb; cgitb.enable(format="text", logdir=%s); '
7648b7ed6d91 #12890: fix test on windows
R David Murray <rdmurray@bitdance.com>
parents: 79992
diff changeset
58 'raise ValueError("Hello World")') % repr(tracedir))
79973
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
59 out = out.decode(sys.getfilesystemencoding())
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
60 self.assertIn("ValueError", out)
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
61 self.assertIn("Hello World", out)
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
62 self.assertNotIn('<p>', out)
45764e4bb504 merge #12890: don't emit <p> tags in text mode when logdir specified.
R David Murray <rdmurray@bitdance.com>
parents: 71239
diff changeset
63 self.assertNotIn('</p>', out)
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
64
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
65
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
66 def test_main():
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
67 run_unittest(TestCgitb)
71239
f362f0053eab Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents: 71238
diff changeset
68
71238
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
69 if __name__ == "__main__":
7e0102ec95d4 Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff changeset
70 test_main()