annotate test/test_misc.py @ 8408:e882a5d52ae5

refactor: move RateLimitExceeded to roundup.cgi.exceptions RateLimitExceeded is an HTTP exception that raises code 429. Move it to roundup.cgi.exceptions where all the other exceptions that result in http status codes are located. Also make it inherit from HTTPException since it is one. Also add docstrings for all HTTP exceptions and order HTTPExceptions by status code. BREAKING CHANGE: if somebody is importing RateLimitExceeded they will need to change their import. I consider it unlikely anybody is using RateLimitExceeded. Detectors and extensions are unlikely to raise RateLimitExceeded. So I am leaving it out of the upgrading doc. Just doc in change log.
author John Rouillard <rouilj@ieee.org>
date Sun, 10 Aug 2025 21:27:06 -0400
parents 70703d22c79a
children d54f4261cd87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
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
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
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
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
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
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
104 class VersionCheck(unittest.TestCase):
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
105 def test_Version_Check(self):
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
106
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
107 # test for valid versions
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
108 from roundup.version_check import VERSION_NEEDED
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
109 self.assertEqual((2, 7), VERSION_NEEDED)
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
110 del(sys.modules['roundup.version_check'])
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
111
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
112
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
113 # fake an invalid version
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
114 real_ver = sys.version_info
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
115 sys.version_info = (2, 1)
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
116
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
117 # exit is called on failure, but that breaks testing so
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
118 # just return and discard the exit code.
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
119 real_exit = sys.exit
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
120 sys.exit = lambda code: code
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
121
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
122 # error case uses print(), capture and check
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
123 capturedOutput = StringIO()
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
124 sys.stdout = capturedOutput
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
125 from roundup.version_check import VERSION_NEEDED
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
126 sys.stdout = sys.__stdout__
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
127 self.assertIn("Roundup requires Python 2.7", capturedOutput.getvalue())
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
128
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
129 # reset to valid values for future tests
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
130 sys.exit = real_exit
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
131 sys.version_info = real_ver
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
132
5986ddd0d2e7 Check version_check.
John Rouillard <rouilj@ieee.org>
parents: 6347
diff changeset
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>&lt;type 'exceptions.NameError'&gt;</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>&nbsp;</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>&lt;class 'NameError'&gt;</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>&nbsp;</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>&lt;class 'NameError'&gt;</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>&nbsp;</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>&nbsp;<br>
3129d73e8535 flake8 plus tests for cgitb.py
John Rouillard <rouilj@ieee.org>
parents: 6654
diff changeset
242 <font color="#ffffff" face="helvetica, arial">&nbsp;<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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__class__&nbsp;= &lt;type 'exceptions.NameError'&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__delattr__&nbsp;= &lt;method-wrapper '__delattr__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__dict__&nbsp;= {} <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__doc__&nbsp;= 'Name not found globally.' <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__format__&nbsp;= &lt;built-in method __format__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__getattribute__&nbsp;= &lt;method-wrapper '__getattribute__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__getitem__&nbsp;= &lt;method-wrapper '__getitem__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__getslice__&nbsp;= &lt;method-wrapper '__getslice__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__hash__&nbsp;= &lt;method-wrapper '__hash__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__init__&nbsp;= &lt;method-wrapper '__init__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__new__&nbsp;= &lt;built-in method __new__ of type object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__reduce__&nbsp;= &lt;built-in method __reduce__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__reduce_ex__&nbsp;= &lt;built-in method __reduce_ex__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__repr__&nbsp;= &lt;method-wrapper '__repr__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__setattr__&nbsp;= &lt;method-wrapper '__setattr__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__setstate__&nbsp;= &lt;built-in method __setstate__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__sizeof__&nbsp;= &lt;built-in method __sizeof__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__str__&nbsp;= &lt;method-wrapper '__str__' of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__subclasshook__&nbsp;= &lt;built-in method __subclasshook__ of type object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>__unicode__&nbsp;= &lt;built-in method __unicode__ of exceptions.NameError object&gt; <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>args&nbsp;= ("global name 'a' is not defined",) <br><tt><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt>message&nbsp;= "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=&lt;test.test_misc.CgiTbCheck testMethod=test_html&gt;)</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">&nbsp;&nbsp;XX</font></small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;=&nbsp;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">&nbsp;&nbsp;XX</font></small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;=&nbsp;a&nbsp;+&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;</tt><small><font color="#909090"><strong>d</strong>&nbsp;= <em>undefined</em>, <em>global</em> <strong>a</strong>&nbsp;= <em>undefined</em></font></small><br><p>&nbsp;</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&gt;"""
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'(&nbsp;)\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)

Roundup Issue Tracker: http://roundup-tracker.org/