Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_cgitb.py @ 79453:366c19bb5ca2
MERGE: Closes #16126: PyErr_Format format mismatch in _testcapimodule.c
| author | Jesus Cea <jcea@jcea.es> |
|---|---|
| date | Thu, 04 Oct 2012 16:07:03 +0200 |
| parents | f362f0053eab |
| children | 45764e4bb504 |
| 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 |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
2 import unittest |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
3 import sys |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
4 import subprocess |
|
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 |
|
71238
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
39 def test_hook(self): |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
40 proc = subprocess.Popen([sys.executable, '-c', |
|
71239
f362f0053eab
Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents:
71238
diff
changeset
|
41 ('import cgitb;' |
|
f362f0053eab
Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents:
71238
diff
changeset
|
42 'cgitb.enable();' |
|
71238
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
43 '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
|
44 stdout=subprocess.PIPE) |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
45 out = proc.stdout.read().decode(sys.getfilesystemencoding()) |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
46 self.addCleanup(proc.stdout.close) |
|
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("ValueError", out) |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
48 self.assertIn("Hello World", out) |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
49 |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
50 |
|
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
51 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
|
52 run_unittest(TestCgitb) |
|
71239
f362f0053eab
Normalize whitespace for #11512 fix.
Brian Curtin <brian@python.org>
parents:
71238
diff
changeset
|
53 |
|
71238
7e0102ec95d4
Fix #11512. Add an initial test suite for the cgitb, providing 75% coverage.
Brian Curtin <brian@python.org>
parents:
diff
changeset
|
54 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
|
55 test_main() |
