Show More
@@ -47,7 +47,8 b' class testatomictempfile(unittest.TestCa' | |||
|
47 | 47 | # if a programmer screws up and passes bad args to atomictempfile, they |
|
48 | 48 | # get a plain ordinary TypeError, not infinite recursion |
|
49 | 49 | def testoops(self): |
|
50 |
self.assertRaises(TypeError |
|
|
50 | with self.assertRaises(TypeError): | |
|
51 | atomictempfile() | |
|
51 | 52 | |
|
52 | 53 | # checkambig=True avoids ambiguity of timestamp |
|
53 | 54 | def testcheckambig(self): |
@@ -55,23 +55,21 b' class test_ctxmanager(unittest.TestCase)' | |||
|
55 | 55 | def test_raise_on_enter(self): |
|
56 | 56 | trace = [] |
|
57 | 57 | addtrace = trace.append |
|
58 | def go(): | |
|
58 | with self.assertRaises(ctxerror): | |
|
59 | 59 | with util.ctxmanager(ctxmgr('a', addtrace), |
|
60 | 60 | lambda: raise_on_enter('b', addtrace)) as c: |
|
61 | 61 | c.enter() |
|
62 | 62 | addtrace('unreachable') |
|
63 | self.assertRaises(ctxerror, go) | |
|
64 | 63 | self.assertEqual(trace, [('enter', 'a'), ('raise', 'b'), ('exit', 'a')]) |
|
65 | 64 | |
|
66 | 65 | def test_raise_on_exit(self): |
|
67 | 66 | trace = [] |
|
68 | 67 | addtrace = trace.append |
|
69 | def go(): | |
|
68 | with self.assertRaises(ctxerror): | |
|
70 | 69 | with util.ctxmanager(ctxmgr('a', addtrace), |
|
71 | 70 | lambda: raise_on_exit('b', addtrace)) as c: |
|
72 | 71 | c.enter() |
|
73 | 72 | addtrace('running') |
|
74 | self.assertRaises(ctxerror, go) | |
|
75 | 73 | self.assertEqual(trace, [('enter', 'a'), ('enter', 'b'), 'running', |
|
76 | 74 | ('raise', 'b'), ('exit', 'a')]) |
|
77 | 75 |
@@ -260,12 +260,10 b' class testlock(unittest.TestCase):' | |||
|
260 | 260 | lock = state.makelock(inheritchecker=check) |
|
261 | 261 | state.assertacquirecalled(True) |
|
262 | 262 | |
|
263 | def tryinherit(): | |
|
263 | with self.assertRaises(error.LockInheritanceContractViolation): | |
|
264 | 264 | with lock.inherit(): |
|
265 | 265 | pass |
|
266 | 266 | |
|
267 | self.assertRaises(error.LockInheritanceContractViolation, tryinherit) | |
|
268 | ||
|
269 | 267 | lock.release() |
|
270 | 268 | |
|
271 | 269 | def testfrequentlockunlock(self): |
@@ -128,7 +128,8 b' class basemanifesttests(object):' | |||
|
128 | 128 | self.assertEqual('l', m.flags('bar/baz/qux.py')) |
|
129 | 129 | self.assertEqual(BIN_HASH_1, m['foo']) |
|
130 | 130 | self.assertEqual('', m.flags('foo')) |
|
131 |
self.assertRaises(KeyError |
|
|
131 | with self.assertRaises(KeyError): | |
|
132 | m['wat'] | |
|
132 | 133 | |
|
133 | 134 | def testParseManifestV2(self): |
|
134 | 135 | m1 = self.parsemanifest(A_SHORT_MANIFEST) |
@@ -213,7 +214,8 b' class basemanifesttests(object):' | |||
|
213 | 214 | self.assertEqual('', m.flags('alpha')) |
|
214 | 215 | self.assertEqual('l', m.flags('bar/baz/qux.py')) |
|
215 | 216 | self.assertEqual('', m.flags('beta')) |
|
216 |
self.assertRaises(KeyError |
|
|
217 | with self.assertRaises(KeyError): | |
|
218 | m['foo'] | |
|
217 | 219 | |
|
218 | 220 | def testSetGetNodeSuffix(self): |
|
219 | 221 | clean = self.parsemanifest(A_SHORT_MANIFEST) |
@@ -255,12 +257,14 b' class basemanifesttests(object):' | |||
|
255 | 257 | assert False |
|
256 | 258 | return True |
|
257 | 259 | match.matchfn = filt |
|
258 |
self.assertRaises(AssertionError |
|
|
260 | with self.assertRaises(AssertionError): | |
|
261 | m.matches(match) | |
|
259 | 262 | |
|
260 | 263 | def testRemoveItem(self): |
|
261 | 264 | m = self.parsemanifest(A_SHORT_MANIFEST) |
|
262 | 265 | del m['foo'] |
|
263 |
self.assertRaises(KeyError |
|
|
266 | with self.assertRaises(KeyError): | |
|
267 | m['foo'] | |
|
264 | 268 | self.assertEqual(1, len(m)) |
|
265 | 269 | self.assertEqual(1, len(list(m))) |
|
266 | 270 | # now restore and make sure everything works right |
@@ -53,24 +53,24 b' class testsimplekeyvaluefile(unittest.Te' | |||
|
53 | 53 | |
|
54 | 54 | def testinvalidkeys(self): |
|
55 | 55 | d = {'0key1': 'value1', 'Key2': 'value2'} |
|
56 | self.assertRaises(error.ProgrammingError, | |
|
57 | scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write, | |
|
58 | d) | |
|
56 | with self.assertRaisesRegexp(error.ProgrammingError, | |
|
57 | 'keys must start with a letter.*'): | |
|
58 | scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d) | |
|
59 | ||
|
59 | 60 | d = {'key1@': 'value1', 'Key2': 'value2'} |
|
60 | self.assertRaises(error.ProgrammingError, | |
|
61 |
|
|
|
62 | d) | |
|
61 | with self.assertRaisesRegexp(error.ProgrammingError, 'invalid key.*'): | |
|
62 | scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d) | |
|
63 | 63 | |
|
64 | 64 | def testinvalidvalues(self): |
|
65 | 65 | d = {'key1': 'value1', 'Key2': 'value2\n'} |
|
66 | self.assertRaises(error.ProgrammingError, | |
|
67 |
|
|
|
68 | d) | |
|
66 | with self.assertRaisesRegexp(error.ProgrammingError, 'invalid val.*'): | |
|
67 | scmutil.simplekeyvaluefile(self.vfs, 'kvfile').write(d) | |
|
69 | 68 | |
|
70 | 69 | def testcorruptedfile(self): |
|
71 | 70 | self.vfs.contents['badfile'] = 'ababagalamaga\n' |
|
72 | self.assertRaises(error.CorruptedState, | |
|
73 | scmutil.simplekeyvaluefile(self.vfs, 'badfile').read) | |
|
71 | with self.assertRaisesRegexp(error.CorruptedState, | |
|
72 | 'dictionary.*element.*'): | |
|
73 | scmutil.simplekeyvaluefile(self.vfs, 'badfile').read() | |
|
74 | 74 | |
|
75 | 75 | def testfirstline(self): |
|
76 | 76 | dw = {'key1': 'value1'} |
@@ -326,7 +326,8 b' bbb' | |||
|
326 | 326 | self.assertEquals(ml, MERGED_RESULT) |
|
327 | 327 | |
|
328 | 328 | def test_binary(self): |
|
329 |
self.assertRaises(error.Abort |
|
|
329 | with self.assertRaises(error.Abort): | |
|
330 | Merge3(['\x00'], ['a'], ['b']) | |
|
330 | 331 | |
|
331 | 332 | def test_dos_text(self): |
|
332 | 333 | base_text = 'a\r\n' |
General Comments 0
You need to be logged in to leave comments.
Login now