comparison tests/test_pull_fallback.py @ 932:dfb3afa6c619

stupid: Fail over to full revision when a PatchError is thrown (issue294) Also give an enhanced exception message when an AssertionError is thrown out of subvertpy. Can't test this as throwing an exception from the appropriate place leaves file handles open in the SVN repository, resulting in a failure to clean up in tearDown().
author Tim Delaney <timothy.c.delaney@gmail.com>
date Tue, 18 Sep 2012 13:18:22 +1000
parents
children d741f536f23a
comparison
equal deleted inserted replaced
931:e1dbd9646d6a 932:dfb3afa6c619
1 import test_util
2
3 import re
4 import mercurial
5 from mercurial import commands
6 from hgsubversion import stupid
7 from hgsubversion import svnwrap
8 from hgsubversion import wrappers
9
10 class TestPullFallback(test_util.TestBase):
11 def setUp(self):
12 super(TestPullFallback, self).setUp()
13
14 def _loadupdate(self, fixture_name, *args, **kwargs):
15 kwargs = kwargs.copy()
16 kwargs.update(noupdate=False)
17 repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs)
18 return repo, repo_path
19
20 def test_stupid_fallback_to_stupid_fullrevs(self):
21 return
22 to_patch = {
23 'mercurial.patch.patchbackend': _patchbackend_raise,
24 'stupid.diff_branchrev': stupid.diff_branchrev,
25 'stupid.fetch_branchrev': stupid.fetch_branchrev,
26 }
27
28 expected_calls = {
29 'mercurial.patch.patchbackend': 1,
30 'stupid.diff_branchrev': 1,
31 'stupid.fetch_branchrev': 1,
32 }
33
34 repo, repo_path = self._loadupdate(
35 'single_rev.svndump', stupid=True)
36
37 # Passing stupid=True doesn't seem to be working - force it
38 repo.ui.setconfig('hgsubversion', 'stupid', "true")
39 state = repo.parents()
40
41 calls, replaced = _monkey_patch(to_patch)
42
43 try:
44 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
45 commands.pull(self.repo.ui, repo, update=True)
46 self.failIfEqual(state, repo.parents())
47 self.assertTrue('tip' in repo[None].tags())
48 self.assertEqual(expected_calls, calls)
49
50 finally:
51 _monkey_unpatch(replaced)
52
53 def _monkey_patch(to_patch, start=None):
54 if start is None:
55 import sys
56 start = sys.modules[__name__]
57
58 calls = {}
59 replaced = {}
60
61 for path, replacement in to_patch.iteritems():
62 obj = start
63 owner, attr = path.rsplit('.', 1)
64
65 for a in owner.split('.', -1):
66 obj = getattr(obj, a)
67
68 replaced[path] = getattr(obj, attr)
69 calls[path] = 0
70
71 def outer(path=path, calls=calls, replacement=replacement):
72 def wrapper(*p, **kw):
73 calls[path] += 1
74 return replacement(*p, **kw)
75
76 return wrapper
77
78 setattr(obj, attr, outer())
79
80 return calls, replaced
81
82 def _monkey_unpatch(to_patch, start=None):
83 if start is None:
84 import sys
85 start = sys.modules[__name__]
86
87 replaced = {}
88
89 for path, replacement in to_patch.iteritems():
90 obj = start
91 owner, attr = path.rsplit('.', 1)
92
93 for a in owner.split('.', -1):
94 obj = getattr(obj, a)
95
96 replaced[path] = getattr(obj, attr)
97 setattr(obj, attr, replacement)
98
99 return replaced
100
101 def _patchbackend_raise(*p, **kw):
102 raise mercurial.patch.PatchError("patch failed")
103
104 def suite():
105 import unittest, sys
106 return unittest.findTestCases(sys.modules[__name__])