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