Mercurial > p > roundup > code
annotate test/test_misc.py @ 7872:163d2c60fdf3
test: benchmark no progress when INCI defined; set path; signal handling
The progress reports on issue creation in the db breaks up the table
in CI as each is reported on a new line. If the environment variable
INCI is set to any value, don't generate progress output. Change
GitHub action to define INCI
Insert roundup root directory in sys.path so import from test directory
will be found.
Also set up signal handler to delete the database if ^C is pressed
during creation. The interrupted db is incomplete (required data
missing), but it is used as is for a subsequent run. This causes the
benchmark to crash.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 10 Apr 2024 12:54:18 -0400 |
| parents | 8ef97f7cfb6d |
| children | cbcd6253ebaa |
| 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 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
212 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
|
213 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
|
214 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
215 print(p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
216 |
|
6993
570bdfad078d
fix test_pt_html handle new error pointer in output.
John Rouillard <rouilj@ieee.org>
parents:
6987
diff
changeset
|
217 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
|
218 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
|
219 elif sys.version_info > (3, 0, 0): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
220 self.assertEqual(expected3, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
221 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
222 self.assertEqual(expected2, p) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
223 |
|
6987
51f9bd50f875
disable test_html - different output under 3.10 than other 3.x
John Rouillard <rouilj@ieee.org>
parents:
6985
diff
changeset
|
224 def notest_html(self): |
|
6983
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
225 """ templating error """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
226 # 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
|
227 # 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
|
228 # self.maxDiff = None |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
229 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
230 try: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
231 f = 5 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
232 d = a + 4 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
233 except Exception: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
234 h = cgitb.html(context=2) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
235 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
236 expected2 = """ |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
237 <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
|
238 <tr bgcolor="#777777"> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
239 <td valign=bottom> <br> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
240 <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
|
241 ><td align=right valign=bottom |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
242 ><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
|
243 <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
|
244 <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
|
245 <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
|
246 <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
|
247 </tt> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
248 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
249 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
250 <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
|
251 <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
|
252 </tt></td></tr></table> |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
253 <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
|
254 |
|
6985
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
255 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
|
256 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
257 # strip file path prefix from href and text |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
258 # /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
|
259 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
|
260 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
|
261 r'\1XX/\2', h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
262 # replace code line numbers with XX |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
263 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
|
264 # normalize out python version/path |
|
fb7056f2dcda
normalize out python version and path.
John Rouillard <rouilj@ieee.org>
parents:
6984
diff
changeset
|
265 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
|
266 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
267 print(h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
268 |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
269 if sys.version_info > (3, 0, 0): |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
270 self.assertEqual(expected3, h) |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
271 else: |
|
3129d73e8535
flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents:
6654
diff
changeset
|
272 self.assertEqual(expected2, h) |
