##// END OF EJS Templates
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp...
Augie Fackler -
r37733:1859b9a7 default
parent child Browse files
Show More
@@ -51,24 +51,30 b' class testsimplekeyvaluefile(unittest.Te'
51 51 dr = scmutil.simplekeyvaluefile(self.vfs, 'kvfile').read()
52 52 self.assertEqual(dr, dw)
53 53
54 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
55 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
56 # the regex version.
57 assertRaisesRegex = (# camelcase-required
58 unittest.TestCase.assertRaisesRegexp)
59
54 60 def testinvalidkeys(self):
55 61 d = {'0key1': 'value1', 'Key2': 'value2'}
56 with self.assertRaisesRegexp(error.ProgrammingError,
62 with self.assertRaisesRegex(error.ProgrammingError,
57 63 'keys must start with a letter.*'):
58 64 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
59 65
60 66 d = {'key1@': 'value1', 'Key2': 'value2'}
61 with self.assertRaisesRegexp(error.ProgrammingError, 'invalid key.*'):
67 with self.assertRaisesRegex(error.ProgrammingError, 'invalid key.*'):
62 68 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
63 69
64 70 def testinvalidvalues(self):
65 71 d = {'key1': 'value1', 'Key2': 'value2\n'}
66 with self.assertRaisesRegexp(error.ProgrammingError, 'invalid val.*'):
72 with self.assertRaisesRegex(error.ProgrammingError, 'invalid val.*'):
67 73 scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d)
68 74
69 75 def testcorruptedfile(self):
70 76 self.vfs.contents['badfile'] = 'ababagalamaga\n'
71 with self.assertRaisesRegexp(error.CorruptedState,
77 with self.assertRaisesRegex(error.CorruptedState,
72 78 'dictionary.*element.*'):
73 79 scmutil.simplekeyvaluefile(self.vfs, 'badfile').read()
74 80
@@ -24,6 +24,13 b' def sendframe(reactor, frame):'
24 24
25 25 class SingleSendTests(unittest.TestCase):
26 26 """A reactor that can only send once rejects subsequent sends."""
27
28 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
29 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
30 # the regex version.
31 assertRaisesRegex = (# camelcase-required
32 unittest.TestCase.assertRaisesRegexp)
33
27 34 def testbasic(self):
28 35 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True)
29 36
@@ -39,11 +46,11 b' class SingleSendTests(unittest.TestCase)'
39 46
40 47 self.assertEqual(request.state, b'sent')
41 48
42 with self.assertRaisesRegexp(error.ProgrammingError,
49 with self.assertRaisesRegex(error.ProgrammingError,
43 50 'cannot issue new commands'):
44 51 reactor.callcommand(b'foo', {})
45 52
46 with self.assertRaisesRegexp(error.ProgrammingError,
53 with self.assertRaisesRegex(error.ProgrammingError,
47 54 'cannot issue new commands'):
48 55 reactor.callcommand(b'foo', {})
49 56
@@ -77,6 +84,12 b' class NoBufferTests(unittest.TestCase):'
77 84 self.assertEqual(request.state, b'sent')
78 85
79 86 class BadFrameRecvTests(unittest.TestCase):
87 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
88 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
89 # the regex version.
90 assertRaisesRegex = (# camelcase-required
91 unittest.TestCase.assertRaisesRegexp)
92
80 93 def testoddstream(self):
81 94 reactor = framing.clientreactor()
82 95
@@ -101,7 +114,7 b' class BadFrameRecvTests(unittest.TestCas'
101 114 for frame in meta[b'framegen']:
102 115 pass
103 116
104 with self.assertRaisesRegexp(error.ProgrammingError,
117 with self.assertRaisesRegex(error.ProgrammingError,
105 118 'unhandled frame type'):
106 119 sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo'))
107 120
@@ -103,19 +103,25 b' class FrameTests(unittest.TestCase):'
103 103 ffs(b'1 1 0 command-data eos %s' % data.getvalue()),
104 104 ])
105 105
106 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
107 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
108 # the regex version.
109 assertRaisesRegex = (# camelcase-required
110 unittest.TestCase.assertRaisesRegexp)
111
106 112 def testtextoutputformattingstringtype(self):
107 113 """Formatting string must be bytes."""
108 with self.assertRaisesRegexp(ValueError, 'must use bytes formatting '):
114 with self.assertRaisesRegex(ValueError, 'must use bytes formatting '):
109 115 list(framing.createtextoutputframe(None, 1, [
110 116 (b'foo'.decode('ascii'), [], [])]))
111 117
112 118 def testtextoutputargumentbytes(self):
113 with self.assertRaisesRegexp(ValueError, 'must use bytes for argument'):
119 with self.assertRaisesRegex(ValueError, 'must use bytes for argument'):
114 120 list(framing.createtextoutputframe(None, 1, [
115 121 (b'foo', [b'foo'.decode('ascii')], [])]))
116 122
117 123 def testtextoutputlabelbytes(self):
118 with self.assertRaisesRegexp(ValueError, 'must use bytes for labels'):
124 with self.assertRaisesRegex(ValueError, 'must use bytes for labels'):
119 125 list(framing.createtextoutputframe(None, 1, [
120 126 (b'foo', [], [b'foo'.decode('ascii')])]))
121 127
@@ -196,21 +196,27 b' class ParseRequestTests(unittest.TestCas'
196 196 self.assertEqual(r.dispatchparts, [b'pathinfo'])
197 197 self.assertEqual(r.dispatchpath, b'pathinfo')
198 198
199 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
200 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
201 # the regex version.
202 assertRaisesRegex = (# camelcase-required
203 unittest.TestCase.assertRaisesRegexp)
204
199 205 def testreponame(self):
200 206 """repository path components get stripped from URL."""
201 207
202 with self.assertRaisesRegexp(error.ProgrammingError,
208 with self.assertRaisesRegex(error.ProgrammingError,
203 209 b'reponame requires PATH_INFO'):
204 210 parse(DEFAULT_ENV, reponame=b'repo')
205 211
206 with self.assertRaisesRegexp(error.ProgrammingError,
212 with self.assertRaisesRegex(error.ProgrammingError,
207 213 b'PATH_INFO does not begin with repo '
208 214 b'name'):
209 215 parse(DEFAULT_ENV, reponame=b'repo', extra={
210 216 r'PATH_INFO': r'/pathinfo',
211 217 })
212 218
213 with self.assertRaisesRegexp(error.ProgrammingError,
219 with self.assertRaisesRegex(error.ProgrammingError,
214 220 b'reponame prefix of PATH_INFO'):
215 221 parse(DEFAULT_ENV, reponame=b'repo', extra={
216 222 r'PATH_INFO': r'/repoextra/path',
General Comments 0
You need to be logged in to leave comments. Login now