Mercurial > hgsubversion
comparison tests/test_fetch_branches.py @ 1106:5cb6c95e0283 stable
Merge default and stable so I can do stable releases again.
| author | Augie Fackler <raf@durin42.com> |
|---|---|
| date | Tue, 11 Feb 2014 12:48:49 -0500 |
| parents | 6e1dbf6cbc92 |
| children | ba8485b9fee0 |
comparison
equal
deleted
inserted
replaced
| 1020:b5b1fce26f1f | 1106:5cb6c95e0283 |
|---|---|
| 1 import test_util | 1 import test_util |
| 2 | 2 |
| 3 import unittest | 3 import unittest |
| 4 | 4 |
| 5 from mercurial import error | |
| 5 from mercurial import hg | 6 from mercurial import hg |
| 6 from mercurial import node | 7 from mercurial import node |
| 7 from mercurial import util as hgutil | 8 |
| 9 from hgsubversion import compathacks | |
| 8 | 10 |
| 9 class TestFetchBranches(test_util.TestBase): | 11 class TestFetchBranches(test_util.TestBase): |
| 12 stupid_mode_tests = True | |
| 13 | |
| 10 def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): | 14 def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): |
| 11 repo_path = self.load_svndump(fixture_name) | 15 repo_path = self.load_svndump(fixture_name) |
| 12 source = '%s#%s' % (test_util.fileurl(repo_path), anchor) | 16 source = '%s#%s' % (test_util.fileurl(repo_path), anchor) |
| 13 test_util.hgclone(self.ui(), source, self.wc_path) | 17 test_util.hgclone(self.ui(), source, self.wc_path) |
| 14 return hg.repository(self.ui(), self.wc_path) | 18 return hg.repository(self.ui(), self.wc_path) |
| 22 return sorted(openbranches), sorted(closedbranches) | 26 return sorted(openbranches), sorted(closedbranches) |
| 23 | 27 |
| 24 def openbranches(self, repo): | 28 def openbranches(self, repo): |
| 25 return self.branches(repo)[0] | 29 return self.branches(repo)[0] |
| 26 | 30 |
| 27 def test_rename_branch_parent(self, stupid=False): | 31 def test_rename_branch_parent(self): |
| 28 repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump', | 32 repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump') |
| 29 stupid=stupid) | |
| 30 heads = [repo[n] for n in repo.heads()] | 33 heads = [repo[n] for n in repo.heads()] |
| 31 heads = dict([(ctx.branch(), ctx) for ctx in heads]) | 34 heads = dict([(ctx.branch(), ctx) for ctx in heads]) |
| 32 # Let these tests disabled yet as the fix is not obvious | 35 # Let these tests disabled yet as the fix is not obvious |
| 33 self.assertEqual(['dev_branch'], self.openbranches(repo)) | 36 self.assertEqual(['dev_branch'], self.openbranches(repo)) |
| 34 | 37 |
| 35 def test_rename_branch_parent_stupid(self): | 38 def test_unrelatedbranch(self): |
| 36 self.test_rename_branch_parent(stupid=True) | 39 repo = self._load_fixture_and_fetch('unrelatedbranch.svndump') |
| 37 | |
| 38 def test_unrelatedbranch(self, stupid=False): | |
| 39 repo = self._load_fixture_and_fetch('unrelatedbranch.svndump', | |
| 40 stupid=stupid) | |
| 41 heads = [repo[n] for n in repo.heads()] | 40 heads = [repo[n] for n in repo.heads()] |
| 42 heads = dict([(ctx.branch(), ctx) for ctx in heads]) | 41 heads = dict([(ctx.branch(), ctx) for ctx in heads]) |
| 43 # Let these tests disabled yet as the fix is not obvious | 42 # Let these tests disabled yet as the fix is not obvious |
| 44 self.assertEqual(heads['branch1'].manifest().keys(), ['b']) | 43 self.assertEqual(heads['branch1'].manifest().keys(), ['b']) |
| 45 self.assertEqual(heads['branch2'].manifest().keys(), ['a', 'b']) | 44 self.assertEqual(heads['branch2'].manifest().keys(), ['a', 'b']) |
| 46 | 45 |
| 47 def test_unrelatedbranch_stupid(self): | 46 def test_unorderedbranch(self): |
| 48 self.test_unrelatedbranch(True) | 47 repo = self._load_fixture_and_fetch('unorderedbranch.svndump') |
| 49 | |
| 50 def test_unorderedbranch(self, stupid=False): | |
| 51 repo = self._load_fixture_and_fetch('unorderedbranch.svndump', | |
| 52 stupid=stupid) | |
| 53 r = repo['branch'] | 48 r = repo['branch'] |
| 54 self.assertEqual(0, r.parents()[0].rev()) | 49 self.assertEqual(0, r.parents()[0].rev()) |
| 55 self.assertEqual(['a', 'c', 'z'], sorted(r.manifest())) | 50 self.assertEqual(['a', 'c', 'z'], sorted(r.manifest())) |
| 56 | 51 |
| 57 def test_unorderedbranch_stupid(self): | 52 def test_renamed_branch_to_trunk(self): |
| 58 self.test_unorderedbranch(True) | |
| 59 | |
| 60 def test_renamed_branch_to_trunk(self, stupid=False): | |
| 61 config = {'hgsubversion.failonmissing': 'true'} | 53 config = {'hgsubversion.failonmissing': 'true'} |
| 62 repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump', | 54 repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump', |
| 63 stupid=stupid, config=config) | 55 config=config) |
| 64 self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch') | 56 self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch') |
| 65 self.assert_('iota' in repo['default']) | 57 self.assert_('iota' in repo['default']) |
| 66 self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default') | 58 self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default') |
| 67 self.assert_('iota' not in repo['old_trunk']) | 59 self.assert_('iota' not in repo['old_trunk']) |
| 68 expected = ['default', 'old_trunk'] | 60 expected = ['default', 'old_trunk'] |
| 69 self.assertEqual(self.openbranches(repo), expected) | 61 self.assertEqual(self.openbranches(repo), expected) |
| 70 | 62 |
| 71 def test_renamed_branch_to_trunk_stupid(self): | 63 def test_replace_trunk_with_branch(self): |
| 72 self.test_renamed_branch_to_trunk(stupid=True) | 64 repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump') |
| 73 | |
| 74 def test_replace_trunk_with_branch(self, stupid=False): | |
| 75 repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump', | |
| 76 stupid=stupid) | |
| 77 self.assertEqual(repo['default'].parents()[0].branch(), 'test') | 65 self.assertEqual(repo['default'].parents()[0].branch(), 'test') |
| 78 self.assertEqual(repo['tip'].branch(), 'default') | 66 self.assertEqual(repo['tip'].branch(), 'default') |
| 79 self.assertEqual(repo['tip'].extra().get('close'), '1') | 67 self.assertEqual(repo['tip'].extra().get('close'), '1') |
| 80 self.assertEqual(self.openbranches(repo), ['default']) | 68 self.assertEqual(self.openbranches(repo), ['default']) |
| 81 | 69 |
| 82 def test_copybeforeclose(self, stupid=False): | 70 def test_copybeforeclose(self): |
| 83 repo = self._load_fixture_and_fetch('copybeforeclose.svndump', | 71 repo = self._load_fixture_and_fetch('copybeforeclose.svndump') |
| 84 stupid=stupid) | |
| 85 self.assertEqual(repo['tip'].branch(), 'test') | 72 self.assertEqual(repo['tip'].branch(), 'test') |
| 86 self.assertEqual(repo['test'].extra().get('close'), '1') | 73 self.assertEqual(repo['test'].extra().get('close'), '1') |
| 87 self.assertEqual(repo['test']['b'].data(), 'a\n') | 74 self.assertEqual(repo['test']['b'].data(), 'a\n') |
| 88 | 75 |
| 89 def test_copybeforeclose_stupid(self): | 76 def test_branch_create_with_dir_delete_works(self): |
| 90 self.test_copybeforeclose(True) | 77 repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump') |
| 91 | |
| 92 def test_replace_trunk_with_branch_stupid(self): | |
| 93 self.test_replace_trunk_with_branch(stupid=True) | |
| 94 | |
| 95 def test_branch_create_with_dir_delete_works(self, stupid=False): | |
| 96 repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump', | |
| 97 stupid=stupid) | |
| 98 self.assertEqual(repo['tip'].manifest().keys(), | 78 self.assertEqual(repo['tip'].manifest().keys(), |
| 99 ['alpha', 'beta', 'iota', 'gamma', ]) | 79 ['alpha', 'beta', 'iota', 'gamma', ]) |
| 100 | 80 |
| 101 def test_branch_tip_update_to_default(self, stupid=False): | 81 def test_branch_tip_update_to_default(self): |
| 102 repo = self._load_fixture_and_fetch('unorderedbranch.svndump', | 82 repo = self._load_fixture_and_fetch('unorderedbranch.svndump', |
| 103 stupid=stupid, noupdate=False) | 83 noupdate=False) |
| 104 self.assertEqual(repo[None].branch(), 'default') | 84 self.assertEqual(repo[None].branch(), 'default') |
| 105 self.assertTrue('tip' not in repo[None].tags()) | 85 self.assertTrue('tip' not in repo[None].tags()) |
| 106 | 86 |
| 107 def test_branch_tip_update_to_default_stupid(self): | |
| 108 self.test_branch_tip_update_to_default(True) | |
| 109 | |
| 110 def test_branch_pull_anchor(self): | 87 def test_branch_pull_anchor(self): |
| 111 self.assertRaises(hgutil.Abort, | 88 self.assertRaises(error.RepoLookupError, |
| 112 self._load_fixture_and_fetch_with_anchor, | 89 self._load_fixture_and_fetch_with_anchor, |
| 113 'unorderedbranch.svndump', 'NaN') | 90 'unorderedbranch.svndump', 'NaN') |
| 114 repo = self._load_fixture_and_fetch_with_anchor( | 91 repo = self._load_fixture_and_fetch_with_anchor( |
| 115 'unorderedbranch.svndump', '4') | 92 'unorderedbranch.svndump', '4') |
| 116 self.assertTrue('c' not in repo.branchtags()) | 93 self.assertTrue('c' not in compathacks.branchset(repo)) |
| 117 | 94 |
| 118 def test_branches_weird_moves(self, stupid=False): | 95 def test_branches_weird_moves(self): |
| 119 repo = self._load_fixture_and_fetch('renamedproject.svndump', | 96 repo = self._load_fixture_and_fetch('renamedproject.svndump', |
| 120 stupid=stupid, | |
| 121 subdir='project') | 97 subdir='project') |
| 122 heads = [repo[n] for n in repo.heads()] | 98 heads = [repo[n] for n in repo.heads()] |
| 123 heads = dict((ctx.branch(), ctx) for ctx in heads) | 99 heads = dict((ctx.branch(), ctx) for ctx in heads) |
| 124 mdefault = sorted(heads['default'].manifest().keys()) | 100 mdefault = sorted(heads['default'].manifest().keys()) |
| 125 mbranch = sorted(heads['branch'].manifest().keys()) | 101 mbranch = sorted(heads['branch'].manifest().keys()) |
| 126 self.assertEqual(mdefault, ['a', 'b', 'd/a']) | 102 self.assertEqual(mdefault, ['a', 'b', 'd/a']) |
| 127 self.assertEqual(mbranch, ['a']) | 103 self.assertEqual(mbranch, ['a']) |
| 128 | 104 |
| 129 def test_branches_weird_moves_stupid(self): | 105 def test_branch_delete_parent_dir(self): |
| 130 self.test_branches_weird_moves(True) | 106 repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump') |
| 131 | |
| 132 def test_branch_delete_parent_dir(self, stupid=False): | |
| 133 repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump', | |
| 134 stupid=stupid) | |
| 135 openb, closedb = self.branches(repo) | 107 openb, closedb = self.branches(repo) |
| 136 self.assertEqual(openb, []) | 108 self.assertEqual(openb, []) |
| 137 self.assertEqual(closedb, ['dev_branch']) | 109 self.assertEqual(closedb, ['dev_branch']) |
| 138 self.assertEqual(list(repo['dev_branch']), ['foo']) | 110 self.assertEqual(list(repo['dev_branch']), ['foo']) |
| 139 | 111 |
| 140 def test_replace_branch_with_branch(self, stupid=False): | 112 def test_replace_branch_with_branch(self): |
| 141 repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump', | 113 repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump') |
| 142 stupid=stupid) | 114 self.assertEqual(7, test_util.repolen(repo)) |
| 143 self.assertEqual(7, len(repo)) | |
| 144 # tip is former topological branch1 being closed | 115 # tip is former topological branch1 being closed |
| 145 ctx = repo['tip'] | 116 ctx = repo['tip'] |
| 146 self.assertEqual('1', ctx.extra().get('close', '0')) | 117 self.assertEqual('1', ctx.extra().get('close', '0')) |
| 147 self.assertEqual('branch1', ctx.branch()) | 118 self.assertEqual('branch1', ctx.branch()) |
| 148 # r5 is where the replacement takes place | 119 # r5 is where the replacement takes place |
| 157 self.assertEqual('f\n', ctx['f'].data()) | 128 self.assertEqual('f\n', ctx['f'].data()) |
| 158 self.assertEqual('g\n', ctx['g'].data()) | 129 self.assertEqual('g\n', ctx['g'].data()) |
| 159 for f in ctx: | 130 for f in ctx: |
| 160 self.assertTrue(not ctx[f].renamed()) | 131 self.assertTrue(not ctx[f].renamed()) |
| 161 | 132 |
| 162 def test_replace_branch_with_branch_stupid(self, stupid=False): | 133 def test_misspelled_branches_tags(self): |
| 163 self.test_replace_branch_with_branch(True) | 134 config = { |
| 135 'hgsubversion.branchdir': 'branchez', | |
| 136 'hgsubversion.tagpaths': 'tagz', | |
| 137 } | |
| 138 '''Tests using the tags dir for branches and the branches dir for tags''' | |
| 139 repo = self._load_fixture_and_fetch('misspelled_branches_tags.svndump', | |
| 140 layout='standard', | |
| 141 config=config) | |
| 142 | |
| 143 heads = set([repo[n].branch() for n in repo.heads()]) | |
| 144 expected_heads = set(['default', 'branch']) | |
| 145 | |
| 146 self.assertEqual(heads, expected_heads) | |
| 147 | |
| 148 tags = set(repo.tags()) | |
| 149 expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch']) | |
| 150 self.assertEqual(tags, expected_tags) | |
| 151 | |
| 152 def test_subdir_branches_tags(self): | |
| 153 '''Tests using the tags dir for branches and the branches dir for tags''' | |
| 154 config = { | |
| 155 'hgsubversion.branchdir': 'bran/ches', | |
| 156 'hgsubversion.tagpaths': 'ta/gs', | |
| 157 } | |
| 158 repo = self._load_fixture_and_fetch('subdir_branches_tags.svndump', | |
| 159 layout='standard', | |
| 160 config=config) | |
| 161 | |
| 162 heads = set([repo[n].branch() for n in repo.heads()]) | |
| 163 expected_heads = set(['default', 'branch']) | |
| 164 | |
| 165 self.assertEqual(heads, expected_heads) | |
| 166 | |
| 167 tags = set(repo.tags()) | |
| 168 expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch']) | |
| 169 self.assertEqual(tags, expected_tags) | |
| 170 | |
| 171 def test_subproject_fetch(self): | |
| 172 config = { | |
| 173 'hgsubversion.infix': 'project', | |
| 174 } | |
| 175 repo = self._load_fixture_and_fetch('subprojects.svndump', | |
| 176 layout='standard', | |
| 177 config=config) | |
| 178 | |
| 179 heads = set([repo[n].branch() for n in repo.heads()]) | |
| 180 expected_heads = set(['default', 'branch']) | |
| 181 self.assertEqual(heads, expected_heads) | |
| 182 | |
| 183 tags = set(repo.tags()) | |
| 184 expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch']) | |
| 185 self.assertEqual(tags, expected_tags) | |
| 186 | |
| 187 for head in repo.heads(): | |
| 188 ctx = repo[head] | |
| 189 self.assertFalse('project/file' in ctx, 'failed to strip infix') | |
| 190 self.assertTrue('file' in ctx, 'failed to track a simple file') | |
| 191 self.assertFalse('other/phile' in ctx, 'pulled in other project') | |
| 192 self.assertFalse('phile' in ctx, 'merged other project in repo') | |
| 193 | |
| 164 | 194 |
| 165 def suite(): | 195 def suite(): |
| 166 all_tests = [unittest.TestLoader().loadTestsFromTestCase(TestFetchBranches), | 196 all_tests = [unittest.TestLoader().loadTestsFromTestCase(TestFetchBranches), |
| 167 ] | 197 ] |
| 168 return unittest.TestSuite(all_tests) | 198 return unittest.TestSuite(all_tests) |
