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