Mercurial > p > roundup > code
annotate test/test_misc.py @ 7531:913a73b9fab5 2.3.0
Update for 2.3.0 release
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 12 Jul 2023 23:00:25 -0400 |
| parents | 6c7f03902e5a |
| children | 8ef97f7cfb6d |
| rev | line source |
|---|---|
|
5155
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 # misc tests |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
3 import re |
| 6654 | 4 import sys |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
5 import unittest |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
6 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
7 import roundup.anypy.cmp_ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
8 |
| 6654 | 9 from roundup.anypy.strings import StringIO # define StringIO |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
10 from roundup.cgi import cgitb |
|
5155
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 from roundup.cgi.accept_language import parse |
|
7016
6c7f03902e5a
Backed out changeset 050bcfc801c3
John Rouillard <rouilj@ieee.org>
parents:
7013
diff
changeset
|
12 |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
13 |
|
5155
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 class AcceptLanguageTest(unittest.TestCase): |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 def testParse(self): |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 self.assertEqual(parse("da, en-gb;q=0.8, en;q=0.7"), |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 ['da', 'en_gb', 'en']) |
|
6347
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
18 self.assertEqual(parse("da, en-gb;q=0.7, en;q=0.8"), |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
19 ['da', 'en', 'en_gb']) |
|
5155
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 self.assertEqual(parse("en;q=0.2, fr;q=1"), ['fr', 'en']) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
21 self.assertEqual(parse("zn; q = 0.2 ,pt-br;q =1"), ['pt_br', 'zn']) |
|
6347
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
22 self.assertEqual(parse("pt-br;q =1, zn; q = 0.2"), ['pt_br', 'zn']) |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
23 self.assertEqual(parse("pt-br,zn;q= 0.1, en-US;q=0.5"), |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
24 ['pt_br', 'en_US', 'zn']) |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
25 # verify that items with q=1.0 are in same output order as input |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
26 self.assertEqual(parse("pt-br,en-US; q=0.5, zn;q= 1.0" ), |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
27 ['pt_br', 'zn', 'en_US']) |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
28 self.assertEqual(parse("zn;q=1.0;q= 1.0,pt-br,en-US; q=0.5" ), |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
29 ['zn', 'pt_br', 'en_US']) |
|
5155
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
30 self.assertEqual(parse("es-AR"), ['es_AR']) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
31 self.assertEqual(parse("es-es-cat"), ['es_es_cat']) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
32 self.assertEqual(parse(""), []) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
33 self.assertEqual(parse(None),[]) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
34 self.assertEqual(parse(" "), []) |
|
e1e3531b4d9b
add tests for roundup/cgi/accept_language.py copied from embedded doctests already in file.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
35 self.assertEqual(parse("en,"), ['en']) |
|
5481
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
36 |
|
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
37 class CmpTest(unittest.TestCase): |
|
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
38 def testCmp(self): |
|
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
39 roundup.anypy.cmp_._test() |
| 6654 | 40 |
| 41 class VersionCheck(unittest.TestCase): | |
| 42 def test_Version_Check(self): | |
| 43 | |
| 44 # test for valid versions | |
| 45 from roundup.version_check import VERSION_NEEDED | |
| 46 self.assertEqual((2, 7), VERSION_NEEDED) | |
| 47 del(sys.modules['roundup.version_check']) | |
| 48 | |
| 49 | |
| 50 # fake an invalid version | |
| 51 real_ver = sys.version_info | |
| 52 sys.version_info = (2, 1) | |
| 53 | |
| 54 # exit is called on failure, but that breaks testing so | |
| 55 # just return and discard the exit code. | |
| 56 real_exit = sys.exit | |
| 57 sys.exit = lambda code: code | |
| 58 | |
| 59 # error case uses print(), capture and check | |
| 60 capturedOutput = StringIO() | |
| 61 sys.stdout = capturedOutput | |
| 62 from roundup.version_check import VERSION_NEEDED | |
| 63 sys.stdout = sys.__stdout__ | |
| 64 self.assertIn("Roundup requires Python 2.7", capturedOutput.getvalue()) | |
| 65 | |
| 66 # reset to valid values for future tests | |
| 67 sys.exit = real_exit | |
| 68 sys.version_info = real_ver | |
| 69 | |
| 70 | |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
71 class CgiTbCheck(unittest.TestCase): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
72 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
73 def test_NiceDict(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
74 d = cgitb.niceDict(" ", { "two": "three", "four": "five" }) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
75 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
76 expected = ( |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
77 "<tr><td><strong>four</strong></td><td>'five'</td></tr>\n" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
78 "<tr><td><strong>two</strong></td><td>'three'</td></tr>" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
79 ) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
80 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
81 self.assertEqual(expected, d) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
82 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
83 def test_breaker(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
84 b = cgitb.breaker() |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
85 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
86 expected = ('<body bgcolor="white"><font color="white" size="-5">' |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
87 ' > </font> </table></table></table></table></table>') |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
88 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
89 self.assertEqual(expected, b) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
90 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
91 def test_pt_html(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
92 """ templating error """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
93 try: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
94 f = 5 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
95 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
96 except Exception: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
97 p = cgitb.pt_html(context=2) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
98 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
99 expected2 = """<h1>Templating Error</h1> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
100 <p><b><type 'exceptions.NameError'></b>: global name 'a' is not defined</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
101 <p class="help">Debugging information follows</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
102 <ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
103 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
104 </ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
105 <table style="font-size: 80%; color: gray"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
106 <tr><th class="header" align="left">Full traceback:</th></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
107 <tr><td><pre>Traceback (most recent call last): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
108 File "XX/test/test_misc.py", line XX, in test_pt_html |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
109 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
110 NameError: global name 'a' is not defined |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
111 </pre></td></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
112 </table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
113 <p> </p>""" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
114 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
115 expected3 = """<h1>Templating Error</h1> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
116 <p><b><class 'NameError'></b>: name 'a' is not defined</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
117 <p class="help">Debugging information follows</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
118 <ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
119 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
120 </ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
121 <table style="font-size: 80%; color: gray"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
122 <tr><th class="header" align="left">Full traceback:</th></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
123 <tr><td><pre>Traceback (most recent call last): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
124 File "XX/test/test_misc.py", line XX, in test_pt_html |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
125 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
126 NameError: name 'a' is not defined |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
127 </pre></td></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
128 </table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
129 <p> </p>""" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
130 |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
131 expected3_11 = """<h1>Templating Error</h1> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
132 <p><b><class 'NameError'></b>: name 'a' is not defined</p> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
133 <p class="help">Debugging information follows</p> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
134 <ol> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
135 |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
136 </ol> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
137 <table style="font-size: 80%; color: gray"> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
138 <tr><th class="header" align="left">Full traceback:</th></tr> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
139 <tr><td><pre>Traceback (most recent call last): |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
140 File "XX/test/test_misc.py", line XX, in test_pt_html |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
141 d = a + 4 |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
142 ^ |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
143 NameError: name 'a' is not defined |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
144 </pre></td></tr> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
145 </table> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
146 <p> </p>""" |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
147 |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
148 # allow file directory prefix and line number to change |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
149 p = re.sub(r'(File ")/.*/(test/test_misc.py",)', r'\1XX/\2', p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
150 p = re.sub(r'(", line )\d*,', r'\1XX,', p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
151 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
152 print(p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
153 |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
154 if sys.version_info > (3, 11, 0): |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
155 self.assertEqual(expected3_11, p) |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
156 elif sys.version_info > (3, 0, 0): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
157 self.assertEqual(expected3, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
158 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
159 self.assertEqual(expected2, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
160 |
|
6987
51f9bd50f875
disable test_html - different output under 3.10 than other 3.x
John Rouillard <rouilj@ieee.org>
parents:
6985
diff
changeset
|
161 def notest_html(self): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
162 """ templating error """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
163 # enabiling this will cause the test to fail as the variable |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
164 # is included in the live output but not in expected. |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
165 # self.maxDiff = None |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
166 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
167 try: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
168 f = 5 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
169 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
170 except Exception: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
171 h = cgitb.html(context=2) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
172 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
173 expected2 = """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
174 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
175 <tr bgcolor="#777777"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
176 <td valign=bottom> <br> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
177 <font color="#ffffff" face="helvetica, arial"> <br><font size=+1><strong>NameError</strong>: global name 'a' is not defined</font></font></td |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
178 ><td align=right valign=bottom |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
179 ><font color="#ffffff" face="helvetica, arial">Python XX</font></td></tr></table> |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
180 <p>A problem occurred while running a Python script. Here is the sequence of function calls leading up to the error, with the most recent (innermost) call first. The exception attributes are:<br><tt><small> </small> </tt>__class__ = <type 'exceptions.NameError'> <br><tt><small> </small> </tt>__delattr__ = <method-wrapper '__delattr__' of exceptions.NameError object> <br><tt><small> </small> </tt>__dict__ = {} <br><tt><small> </small> </tt>__doc__ = 'Name not found globally.' <br><tt><small> </small> </tt>__format__ = <built-in method __format__ of exceptions.NameError object> <br><tt><small> </small> </tt>__getattribute__ = <method-wrapper '__getattribute__' of exceptions.NameError object> <br><tt><small> </small> </tt>__getitem__ = <method-wrapper '__getitem__' of exceptions.NameError object> <br><tt><small> </small> </tt>__getslice__ = <method-wrapper '__getslice__' of exceptions.NameError object> <br><tt><small> </small> </tt>__hash__ = <method-wrapper '__hash__' of exceptions.NameError object> <br><tt><small> </small> </tt>__init__ = <method-wrapper '__init__' of exceptions.NameError object> <br><tt><small> </small> </tt>__new__ = <built-in method __new__ of type object> <br><tt><small> </small> </tt>__reduce__ = <built-in method __reduce__ of exceptions.NameError object> <br><tt><small> </small> </tt>__reduce_ex__ = <built-in method __reduce_ex__ of exceptions.NameError object> <br><tt><small> </small> </tt>__repr__ = <method-wrapper '__repr__' of exceptions.NameError object> <br><tt><small> </small> </tt>__setattr__ = <method-wrapper '__setattr__' of exceptions.NameError object> <br><tt><small> </small> </tt>__setstate__ = <built-in method __setstate__ of exceptions.NameError object> <br><tt><small> </small> </tt>__sizeof__ = <built-in method __sizeof__ of exceptions.NameError object> <br><tt><small> </small> </tt>__str__ = <method-wrapper '__str__' of exceptions.NameError object> <br><tt><small> </small> </tt>__subclasshook__ = <built-in method __subclasshook__ of type object> <br><tt><small> </small> </tt>__unicode__ = <built-in method __unicode__ of exceptions.NameError object> <br><tt><small> </small> </tt>args = ("global name 'a' is not defined",) <br><tt><small> </small> </tt>message = "global name 'a' is not defined"<p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
181 <table width="100%" bgcolor="#dddddd" cellspacing=0 cellpadding=2 border=0> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
182 <tr><td><a href="file:XX/test/test_misc.py">XX/test/test_misc.py</a> in <strong>test_html</strong>(self=<test.test_misc.CgiTbCheck testMethod=test_html>)</td></tr></table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
183 <tt><small><font color="#909090"> XX</font></small> f = 5<br> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
184 </tt> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
185 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
186 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
187 <table width="100%" bgcolor="white" cellspacing=0 cellpadding=0 border=0> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
188 <tr><td><tt><small><font color="#909090"> XX</font></small> d = a + 4<br> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
189 </tt></td></tr></table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
190 <tt><small> </small> </tt><small><font color="#909090"><strong>d</strong> = <em>undefined</em>, <em>global</em> <strong>a</strong> = <em>undefined</em></font></small><br><p> </p>""" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
191 |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
192 expected3 = """\n<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">\n<tr bgcolor="#777777">\n<td valign=bottom> <br>\n<font color="#ffffff" face="helvetica, arial"> <br><font size=+1><strong>NameError</strong>: name \'a\' is not defined</font></font></td\n><td align=right valign=bottom\n><font color="#ffffff" face="helvetica, arial">Python XX</font></td></tr></table>\n <p>A problem occurred while running a Python script. Here is the sequence of function calls leading up to the error, with the most recent (innermost) call first. The exception attributes are:<br><tt><small> </small> </tt>__cause__ = None <br><tt><small> </small> </tt>__class__ = <class \'NameError\'> <br><tt><small> </small> </tt>__context__ = None <br><tt><small> </small> </tt>__delattr__ = <method-wrapper \'__delattr__\' of NameError object> <br><tt><small> </small> </tt>__dict__ = {} <br><tt><small> </small> </tt>__dir__ = <built-in method __dir__ of NameError object> <br><tt><small> </small> </tt>__doc__ = \'Name not found globally.\' <br><tt><small> </small> </tt>__eq__ = <method-wrapper \'__eq__\' of NameError object> <br><tt><small> </small> </tt>__format__ = <built-in method __format__ of NameError object> <br><tt><small> </small> </tt>__ge__ = <method-wrapper \'__ge__\' of NameError object> <br><tt><small> </small> </tt>__getattribute__ = <method-wrapper \'__getattribute__\' of NameError object> <br><tt><small> </small> </tt>__gt__ = <method-wrapper \'__gt__\' of NameError object> <br><tt><small> </small> </tt>__hash__ = <method-wrapper \'__hash__\' of NameError object> <br><tt><small> </small> </tt>__init__ = <method-wrapper \'__init__\' of NameError object> <br><tt><small> </small> </tt>__init_subclass__ = <built-in method __init_subclass__ of type object> <br><tt><small> </small> </tt>__le__ = <method-wrapper \'__le__\' of NameError object> <br><tt><small> </small> </tt>__lt__ = <method-wrapper \'__lt__\' of NameError object> <br><tt><small> </small> </tt>__ne__ = <method-wrapper \'__ne__\' of NameError object> <br><tt><small> </small> </tt>__new__ = <built-in method __new__ of type object> <br><tt><small> </small> </tt>__reduce__ = <built-in method __reduce__ of NameError object> <br><tt><small> </small> </tt>__reduce_ex__ = <built-in method __reduce_ex__ of NameError object> <br><tt><small> </small> </tt>__repr__ = <method-wrapper \'__repr__\' of NameError object> <br><tt><small> </small> </tt>__setattr__ = <method-wrapper \'__setattr__\' of NameError object> <br><tt><small> </small> </tt>__setstate__ = <built-in method __setstate__ of NameError object> <br><tt><small> </small> </tt>__sizeof__ = <built-in method __sizeof__ of NameError object> <br><tt><small> </small> </tt>__str__ = <method-wrapper \'__str__\' of NameError object> <br><tt><small> </small> </tt>__subclasshook__ = <built-in method __subclasshook__ of type object> <br><tt><small> </small> </tt>__suppress_context__ = False <br><tt><small> </small> </tt>__traceback__ = <traceback object> <br><tt><small> </small> </tt>args = ("name \'a\' is not defined",) <br><tt><small> </small> </tt>with_traceback = <built-in method with_traceback of NameError object><p>\n<table width="100%" bgcolor="#dddddd" cellspacing=0 cellpadding=2 border=0>\n<tr><td><a href="file:XX/test/test_misc.py">XX/test/test_misc.py</a> in <strong>test_html</strong>(self=<test.test_misc.CgiTbCheck testMethod=test_html>)</td></tr></table>\n<tt><small><font color="#909090"> XX</font></small> f = 5<br>\n</tt>\n\n\n<table width="100%" bgcolor="white" cellspacing=0 cellpadding=0 border=0>\n<tr><td><tt><small><font color="#909090"> XX</font></small> d = a + 4<br>\n</tt></td></tr></table>\n<tt><small> </small> </tt><small><font color="#909090"><strong>d</strong> = <em>undefined</em>, <em>global</em> <strong>a</strong> = <em>undefined</em></font></small><br><p> </p>""" |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
193 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
194 # strip file path prefix from href and text |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
195 # /home/user/develop/roundup/test/test_misc.py in test_html |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
196 h = re.sub(r'(file:)/.*/(test/test_misc.py")', r'\1XX/\2', h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
197 h = re.sub(r'(/test_misc.py">)/.*/(test/test_misc.py</a>)', |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
198 r'\1XX/\2', h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
199 # replace code line numbers with XX |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
200 h = re.sub(r'( )\d*(</font>)', r'\1XX\2', h) |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
201 # normalize out python version/path |
|
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
202 h = re.sub(r'(Python )[\d.]*<br>[^<]*(</font><)', r'\1XX\2', h) |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
203 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
204 print(h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
205 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
206 if sys.version_info > (3, 0, 0): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
207 self.assertEqual(expected3, h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
208 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
209 self.assertEqual(expected2, h) |
