comparison tests/test_fetch_branches.py @ 865:04729f3a3d17

test_util: merge load_fixture_and_fetch() into TestBase method The middle-term goal is to make TestBase repo_path and wc_path private, so they can be changed for every load call. This is not required to use nosetests multiprocess facility as the fixtures create temporary directories but it makes things much clearer and avoid weird cases where a repository was loaded several times at the same location in a single test (cf test_startrev). That way we will be more confident the tests can be parallelized. The long term goal is to make hgsubversion compatible with nosetests --processes option.
author Patrick Mezard <patrick@mezard.eu>
date Thu, 19 Apr 2012 18:29:25 +0200
parents 312b37bc5e20
children 20e73b5ab6f7
comparison
equal deleted inserted replaced
864:39d45f2190ee 865:04729f3a3d17
5 from mercurial import hg 5 from mercurial import hg
6 from mercurial import node 6 from mercurial import node
7 from mercurial import util as hgutil 7 from mercurial import util as hgutil
8 8
9 class TestFetchBranches(test_util.TestBase): 9 class TestFetchBranches(test_util.TestBase):
10 def _load_fixture_and_fetch(self, fixture_name, stupid, noupdate=True,
11 subdir=''):
12 return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
13 self.wc_path, stupid=stupid,
14 noupdate=noupdate, subdir=subdir)
15
16 def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): 10 def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor):
17 test_util.load_svndump_fixture(self.repo_path, fixture_name) 11 test_util.load_svndump_fixture(self.repo_path, fixture_name)
18 source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor) 12 source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor)
19 test_util.hgclone(self.ui(), source, self.wc_path) 13 test_util.hgclone(self.ui(), source, self.wc_path)
20 return hg.repository(self.ui(), self.wc_path) 14 return hg.repository(self.ui(), self.wc_path)
29 23
30 def openbranches(self, repo): 24 def openbranches(self, repo):
31 return self.branches(repo)[0] 25 return self.branches(repo)[0]
32 26
33 def test_rename_branch_parent(self, stupid=False): 27 def test_rename_branch_parent(self, stupid=False):
34 repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump', stupid) 28 repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump',
29 stupid=stupid)
35 heads = [repo[n] for n in repo.heads()] 30 heads = [repo[n] for n in repo.heads()]
36 heads = dict([(ctx.branch(), ctx) for ctx in heads]) 31 heads = dict([(ctx.branch(), ctx) for ctx in heads])
37 # Let these tests disabled yet as the fix is not obvious 32 # Let these tests disabled yet as the fix is not obvious
38 self.assertEqual(['dev_branch'], self.openbranches(repo)) 33 self.assertEqual(['dev_branch'], self.openbranches(repo))
39 34
40 def test_rename_branch_parent_stupid(self): 35 def test_rename_branch_parent_stupid(self):
41 self.test_rename_branch_parent(stupid=True) 36 self.test_rename_branch_parent(stupid=True)
42 37
43 def test_unrelatedbranch(self, stupid=False): 38 def test_unrelatedbranch(self, stupid=False):
44 repo = self._load_fixture_and_fetch('unrelatedbranch.svndump', stupid) 39 repo = self._load_fixture_and_fetch('unrelatedbranch.svndump',
40 stupid=stupid)
45 heads = [repo[n] for n in repo.heads()] 41 heads = [repo[n] for n in repo.heads()]
46 heads = dict([(ctx.branch(), ctx) for ctx in heads]) 42 heads = dict([(ctx.branch(), ctx) for ctx in heads])
47 # Let these tests disabled yet as the fix is not obvious 43 # Let these tests disabled yet as the fix is not obvious
48 self.assertEqual(heads['branch1'].manifest().keys(), ['b']) 44 self.assertEqual(heads['branch1'].manifest().keys(), ['b'])
49 self.assertEqual(heads['branch2'].manifest().keys(), ['a', 'b']) 45 self.assertEqual(heads['branch2'].manifest().keys(), ['a', 'b'])
50 46
51 def test_unrelatedbranch_stupid(self): 47 def test_unrelatedbranch_stupid(self):
52 self.test_unrelatedbranch(True) 48 self.test_unrelatedbranch(True)
53 49
54 def test_unorderedbranch(self, stupid=False): 50 def test_unorderedbranch(self, stupid=False):
55 repo = self._load_fixture_and_fetch('unorderedbranch.svndump', stupid) 51 repo = self._load_fixture_and_fetch('unorderedbranch.svndump',
52 stupid=stupid)
56 r = repo['branch'] 53 r = repo['branch']
57 self.assertEqual(0, r.parents()[0].rev()) 54 self.assertEqual(0, r.parents()[0].rev())
58 self.assertEqual(['a', 'c', 'z'], sorted(r.manifest())) 55 self.assertEqual(['a', 'c', 'z'], sorted(r.manifest()))
59 56
60 def test_unorderedbranch_stupid(self): 57 def test_unorderedbranch_stupid(self):
61 self.test_unorderedbranch(True) 58 self.test_unorderedbranch(True)
62 59
63 def test_renamed_branch_to_trunk(self, stupid=False): 60 def test_renamed_branch_to_trunk(self, stupid=False):
64 repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump', 61 repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump',
65 stupid) 62 stupid=stupid)
66 self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch') 63 self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch')
67 self.assert_('iota' in repo['default']) 64 self.assert_('iota' in repo['default'])
68 self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default') 65 self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default')
69 self.assert_('iota' not in repo['old_trunk']) 66 self.assert_('iota' not in repo['old_trunk'])
70 expected = ['default', 'old_trunk'] 67 expected = ['default', 'old_trunk']
73 def test_renamed_branch_to_trunk_stupid(self): 70 def test_renamed_branch_to_trunk_stupid(self):
74 self.test_renamed_branch_to_trunk(stupid=True) 71 self.test_renamed_branch_to_trunk(stupid=True)
75 72
76 def test_replace_trunk_with_branch(self, stupid=False): 73 def test_replace_trunk_with_branch(self, stupid=False):
77 repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump', 74 repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump',
78 stupid) 75 stupid=stupid)
79 self.assertEqual(repo['default'].parents()[0].branch(), 'test') 76 self.assertEqual(repo['default'].parents()[0].branch(), 'test')
80 self.assertEqual(repo['tip'].branch(), 'default') 77 self.assertEqual(repo['tip'].branch(), 'default')
81 self.assertEqual(repo['tip'].extra().get('close'), '1') 78 self.assertEqual(repo['tip'].extra().get('close'), '1')
82 self.assertEqual(self.openbranches(repo), ['default']) 79 self.assertEqual(self.openbranches(repo), ['default'])
83 80
84 def test_copybeforeclose(self, stupid=False): 81 def test_copybeforeclose(self, stupid=False):
85 repo = self._load_fixture_and_fetch('copybeforeclose.svndump', stupid) 82 repo = self._load_fixture_and_fetch('copybeforeclose.svndump',
83 stupid=stupid)
86 self.assertEqual(repo['tip'].branch(), 'test') 84 self.assertEqual(repo['tip'].branch(), 'test')
87 self.assertEqual(repo['test'].extra().get('close'), '1') 85 self.assertEqual(repo['test'].extra().get('close'), '1')
88 self.assertEqual(repo['test']['b'].data(), 'a\n') 86 self.assertEqual(repo['test']['b'].data(), 'a\n')
89 87
90 def test_copybeforeclose_stupid(self): 88 def test_copybeforeclose_stupid(self):
93 def test_replace_trunk_with_branch_stupid(self): 91 def test_replace_trunk_with_branch_stupid(self):
94 self.test_replace_trunk_with_branch(stupid=True) 92 self.test_replace_trunk_with_branch(stupid=True)
95 93
96 def test_branch_create_with_dir_delete_works(self, stupid=False): 94 def test_branch_create_with_dir_delete_works(self, stupid=False):
97 repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump', 95 repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump',
98 stupid) 96 stupid=stupid)
99 self.assertEqual(repo['tip'].manifest().keys(), 97 self.assertEqual(repo['tip'].manifest().keys(),
100 ['alpha', 'beta', 'iota', 'gamma', ]) 98 ['alpha', 'beta', 'iota', 'gamma', ])
101 99
102 def test_branch_tip_update_to_default(self, stupid=False): 100 def test_branch_tip_update_to_default(self, stupid=False):
103 repo = self._load_fixture_and_fetch('unorderedbranch.svndump', 101 repo = self._load_fixture_and_fetch('unorderedbranch.svndump',
104 stupid, noupdate=False) 102 stupid=stupid, noupdate=False)
105 self.assertEqual(repo[None].branch(), 'default') 103 self.assertEqual(repo[None].branch(), 'default')
106 self.assertTrue('tip' not in repo[None].tags()) 104 self.assertTrue('tip' not in repo[None].tags())
107 105
108 def test_branch_tip_update_to_default_stupid(self): 106 def test_branch_tip_update_to_default_stupid(self):
109 self.test_branch_tip_update_to_default(True) 107 self.test_branch_tip_update_to_default(True)
115 repo = self._load_fixture_and_fetch_with_anchor( 113 repo = self._load_fixture_and_fetch_with_anchor(
116 'unorderedbranch.svndump', '4') 114 'unorderedbranch.svndump', '4')
117 self.assertTrue('c' not in repo.branchtags()) 115 self.assertTrue('c' not in repo.branchtags())
118 116
119 def test_branches_weird_moves(self, stupid=False): 117 def test_branches_weird_moves(self, stupid=False):
120 repo = self._load_fixture_and_fetch('renamedproject.svndump', stupid, 118 repo = self._load_fixture_and_fetch('renamedproject.svndump',
119 stupid=stupid,
121 subdir='project') 120 subdir='project')
122 heads = [repo[n] for n in repo.heads()] 121 heads = [repo[n] for n in repo.heads()]
123 heads = dict((ctx.branch(), ctx) for ctx in heads) 122 heads = dict((ctx.branch(), ctx) for ctx in heads)
124 mdefault = sorted(heads['default'].manifest().keys()) 123 mdefault = sorted(heads['default'].manifest().keys())
125 mbranch = sorted(heads['branch'].manifest().keys()) 124 mbranch = sorted(heads['branch'].manifest().keys())
129 def test_branches_weird_moves_stupid(self): 128 def test_branches_weird_moves_stupid(self):
130 self.test_branches_weird_moves(True) 129 self.test_branches_weird_moves(True)
131 130
132 def test_branch_delete_parent_dir(self, stupid=False): 131 def test_branch_delete_parent_dir(self, stupid=False):
133 repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump', 132 repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump',
134 stupid) 133 stupid=stupid)
135 openb, closedb = self.branches(repo) 134 openb, closedb = self.branches(repo)
136 self.assertEqual(openb, []) 135 self.assertEqual(openb, [])
137 self.assertEqual(closedb, ['dev_branch']) 136 self.assertEqual(closedb, ['dev_branch'])
138 self.assertEqual(list(repo['dev_branch']), ['foo']) 137 self.assertEqual(list(repo['dev_branch']), ['foo'])
139 138
140 def test_replace_branch_with_branch(self, stupid=False): 139 def test_replace_branch_with_branch(self, stupid=False):
141 repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump', 140 repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump',
142 stupid) 141 stupid=stupid)
143 self.assertEqual(7, len(repo)) 142 self.assertEqual(7, len(repo))
144 # tip is former topological branch1 being closed 143 # tip is former topological branch1 being closed
145 ctx = repo['tip'] 144 ctx = repo['tip']
146 self.assertEqual('1', ctx.extra().get('close', '0')) 145 self.assertEqual('1', ctx.extra().get('close', '0'))
147 self.assertEqual('branch1', ctx.branch()) 146 self.assertEqual('branch1', ctx.branch())