Mercurial > p > roundup > code
annotate test/test_misc.py @ 8265:35beff316883
fix(api): issue2551384. Verify REST authorization earlier
To reduce the ability of bad actors to spam (DOS) the REST endpoint
with bad data and generate logs meant for debugging, modify the flow
in client.py's REST handler to verify authorization earlier.
If the anonymous user is allowed to use REST, this won't make a
difference for a DOS attempt. The templates don't enable REST for the
anonymous user by default. Most admins don't change this.
The validation order for REST requests has been changed.
CORS identfied an handled
User authorization to use REST (return 403 on failure)
REST request validated (Origin header valid etc.) (return 400 for
bad request)
Incorrectly formatted CORS preflight requests (e.g. missing Origin
header) that are not recogized as a CORS request can now return HTTP
status 403 as well as status 400 (when anonymous is allowed
access). Note all CORS preflights are sent without authentication so
appear as anonymous requests.
The tests were updated to compensate, but it is not obvious to me from
specs what the proper evaulation order/return codes should be for this
case. Both 403/400 are failures and cause CORS to fail so there should
be no difference but...
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 09 Jan 2025 09:30:08 -0500 |
| parents | 70703d22c79a |
| children | d54f4261cd87 |
| 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 |
|
7846
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
3 import pytest |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
4 import re |
| 6654 | 5 import sys |
|
7846
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
6 import time |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
7 import unittest |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
8 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
9 import roundup.anypy.cmp_ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
10 |
| 6654 | 11 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
|
12 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
|
13 from roundup.cgi.accept_language import parse |
|
7016
6c7f03902e5a
Backed out changeset 050bcfc801c3
John Rouillard <rouilj@ieee.org>
parents:
7013
diff
changeset
|
14 |
|
7846
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
15 from roundup.support import PrioList, Progress, TruthDict |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
16 |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
17 |
|
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
|
18 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
|
19 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
|
20 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
|
21 ['da', 'en_gb', 'en']) |
|
6347
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
22 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
|
23 ['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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 ['pt_br', 'en_US', 'zn']) |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
29 # 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
|
30 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
|
31 ['pt_br', 'zn', 'en_US']) |
|
3b945aee0919
accept_language parse; fix priority order; preserve insertion order
John Rouillard <rouilj@ieee.org>
parents:
5481
diff
changeset
|
32 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
|
33 ['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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
|
7846
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
41 |
|
5481
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
42 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
|
43 def testCmp(self): |
|
9a09719b0d8e
helper to allow comparing dicts and None values in Python 3
Christof Meerwald <cmeerw@cmeerw.org>
parents:
5155
diff
changeset
|
44 roundup.anypy.cmp_._test() |
| 6654 | 45 |
|
7846
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
46 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
47 class PrioListTest(unittest.TestCase): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
48 def testPL(self): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
49 start_data = [(3, 33), (1, -2), (2, 10)] |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
50 pl = PrioList(key=lambda x: x[1]) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
51 for i in start_data: |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
52 pl.append(i) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
53 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
54 l = [x for x in pl] |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
55 self.assertEqual(l, [(1, -2), (2, 10), (3, 33)]) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
56 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
57 pl = PrioList() |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
58 for i in start_data: |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
59 pl.append(i) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
60 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
61 l = [x for x in pl] |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
62 self.assertEqual(l, [(1, -2), (2, 10), (3, 33)]) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
63 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
64 class ProgressTest(unittest.TestCase): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
65 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
66 @pytest.fixture(autouse=True) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
67 def inject_fixtures(self, capsys): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
68 self._capsys = capsys |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
69 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
70 def testProgress(self): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
71 for x in Progress("5 Items@2 sec:", [1,2,3,4,5]): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
72 time.sleep(2) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
73 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
74 captured = self._capsys.readouterr() |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
75 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
76 split_capture = captured.out.split('\r') |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
77 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
78 # lines padded to 75 characters test should be long enough to |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
79 # get an ETA printed at 100%, 80% and 60% hopefully this |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
80 # doesn't become a flakey test on different hardware. |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
81 self.assertIn("5 Items@2 sec: 0%".ljust(75), |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
82 split_capture) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
83 self.assertIn("5 Items@2 sec: 60% (ETA 00:00:02)".ljust(75), |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
84 split_capture) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
85 self.assertIn("5 Items@2 sec: 100% (ETA 00:00:00)".ljust(75), |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
86 split_capture) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
87 print(captured.err) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
88 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
89 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
90 class TruthDictTest(unittest.TestCase): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
91 def testTD(self): |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
92 td = TruthDict([]) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
93 # empty TruthDict always returns True. |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
94 self.assertTrue(td['a']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
95 self.assertTrue(td['z']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
96 self.assertTrue(td['']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
97 self.assertTrue(td[None]) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
98 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
99 td = TruthDict(['a', 'b', 'c']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
100 self.assertTrue(td['a']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
101 self.assertFalse(td['z']) |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
102 |
|
8ef97f7cfb6d
test: add tests for support.py: PrioList, Progress, TruthDict
John Rouillard <rouilj@ieee.org>
parents:
7016
diff
changeset
|
103 |
| 6654 | 104 class VersionCheck(unittest.TestCase): |
| 105 def test_Version_Check(self): | |
| 106 | |
| 107 # test for valid versions | |
| 108 from roundup.version_check import VERSION_NEEDED | |
| 109 self.assertEqual((2, 7), VERSION_NEEDED) | |
| 110 del(sys.modules['roundup.version_check']) | |
| 111 | |
| 112 | |
| 113 # fake an invalid version | |
| 114 real_ver = sys.version_info | |
| 115 sys.version_info = (2, 1) | |
| 116 | |
| 117 # exit is called on failure, but that breaks testing so | |
| 118 # just return and discard the exit code. | |
| 119 real_exit = sys.exit | |
| 120 sys.exit = lambda code: code | |
| 121 | |
| 122 # error case uses print(), capture and check | |
| 123 capturedOutput = StringIO() | |
| 124 sys.stdout = capturedOutput | |
| 125 from roundup.version_check import VERSION_NEEDED | |
| 126 sys.stdout = sys.__stdout__ | |
| 127 self.assertIn("Roundup requires Python 2.7", capturedOutput.getvalue()) | |
| 128 | |
| 129 # reset to valid values for future tests | |
| 130 sys.exit = real_exit | |
| 131 sys.version_info = real_ver | |
| 132 | |
| 133 | |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
134 class CgiTbCheck(unittest.TestCase): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
135 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
136 def test_NiceDict(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
137 d = cgitb.niceDict(" ", { "two": "three", "four": "five" }) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
138 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
139 expected = ( |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
140 "<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
|
141 "<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
|
142 ) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
143 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
144 self.assertEqual(expected, d) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
145 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
146 def test_breaker(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
147 b = cgitb.breaker() |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
148 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
149 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
|
150 ' > </font> </table></table></table></table></table>') |
|
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 self.assertEqual(expected, b) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
153 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
154 def test_pt_html(self): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
155 """ templating error """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
156 try: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
157 f = 5 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
158 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
159 except Exception: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
160 p = cgitb.pt_html(context=2) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
161 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
162 expected2 = """<h1>Templating Error</h1> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
163 <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
|
164 <p class="help">Debugging information follows</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
165 <ol> |
|
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 </ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
168 <table style="font-size: 80%; color: gray"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
169 <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
|
170 <tr><td><pre>Traceback (most recent call last): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
171 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
|
172 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
173 NameError: global name 'a' is not defined |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
174 </pre></td></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
175 </table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
176 <p> </p>""" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
177 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
178 expected3 = """<h1>Templating Error</h1> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
179 <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
|
180 <p class="help">Debugging information follows</p> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
181 <ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
182 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
183 </ol> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
184 <table style="font-size: 80%; color: gray"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
185 <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
|
186 <tr><td><pre>Traceback (most recent call last): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
187 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
|
188 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
189 NameError: name 'a' is not defined |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
190 </pre></td></tr> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
191 </table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
192 <p> </p>""" |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
193 |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
194 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
|
195 <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
|
196 <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
|
197 <ol> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
198 |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
199 </ol> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
200 <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
|
201 <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
|
202 <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
|
203 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
|
204 d = a + 4 |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
205 ^ |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
206 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
|
207 </pre></td></tr> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
208 </table> |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
209 <p> </p>""" |
|
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
210 |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
211 # allow file directory prefix and line number to change |
|
7911
cbcd6253ebaa
issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents:
7846
diff
changeset
|
212 p = re.sub(r'\\',r'/', p) # support windows \ => / |
|
cbcd6253ebaa
issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents:
7846
diff
changeset
|
213 # [A-Z]?:? optional drive spec on windows |
|
cbcd6253ebaa
issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents:
7846
diff
changeset
|
214 p = re.sub(r'(File ")[A-Z]?:?/.*/(test/test_misc.py",)', r'\1XX/\2', p) |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
215 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
|
216 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
217 print(p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
218 |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
219 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
|
220 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
|
221 elif sys.version_info > (3, 0, 0): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
222 self.assertEqual(expected3, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
223 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
224 self.assertEqual(expected2, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
225 |
|
7965
6763813d9d34
issue2551350 - Python changes for 3.12 with roundup 2.3.0 cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
7911
diff
changeset
|
226 def test_html(self): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
227 """ templating error """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
228 # 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
|
229 # 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
|
230 # self.maxDiff = None |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
231 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
232 try: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
233 f = 5 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
234 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
235 except Exception: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
236 h = cgitb.html(context=2) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
237 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
238 expected2 = """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
239 <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
|
240 <tr bgcolor="#777777"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
241 <td valign=bottom> <br> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
242 <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
|
243 ><td align=right valign=bottom |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
244 ><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
|
245 <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
|
246 <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
|
247 <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
|
248 <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
|
249 </tt> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
250 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
251 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
252 <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
|
253 <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
|
254 </tt></td></tr></table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
255 <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
|
256 |
|
7967
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
257 expected1_3 ="""NameError""" |
|
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
258 expected2_3 =""": name \'a\' is not defined""" |
|
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
259 expected3_3 ="""built-in method __dir__ of NameError object>""" |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
260 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
261 # strip file path prefix from href and text |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
262 # /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
|
263 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
|
264 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
|
265 r'\1XX/\2', h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
266 # replace code line numbers with XX |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
267 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
|
268 # normalize out python version/path |
|
7967
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
269 h = re.sub(r'(Python )[\d.]*<br>[^<]*/python[23]?', r'\1XX', h) |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
270 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
271 print(h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
272 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
273 if sys.version_info > (3, 0, 0): |
|
7967
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
274 self.assertIn(expected1_3, h) |
|
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
275 self.assertIn(expected2_3, h) |
|
70703d22c79a
test: fix test_html for different html structure for extra info.
John Rouillard <rouilj@ieee.org>
parents:
7965
diff
changeset
|
276 self.assertIn(expected3_3, h) |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
277 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
278 self.assertEqual(expected2, h) |
