/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_branch/test_stacking.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        stacked_repo.lock_read()
42
42
        try:
43
43
            list(stacked_repo.inventories.iter_lines_added_or_present_in_keys(
44
 
                    [(revid,)]))
 
44
                [(revid,)]))
45
45
        finally:
46
46
            stacked_repo.unlock()
47
47
 
56
56
            branch.set_stacked_on_url(target.base)
57
57
        except unstackable_format_errors:
58
58
            # if the set failed, so must the get
59
 
            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
 
59
            self.assertRaises(unstackable_format_errors,
 
60
                              branch.get_stacked_on_url)
60
61
            self.assertFalse(branch._format.supports_stacking())
61
62
            return
62
63
        self.assertTrue(branch._format.supports_stacking())
73
74
            branch.set_stacked_on_url('../target')
74
75
        except unstackable_format_errors:
75
76
            # if the set failed, so must the get
76
 
            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
 
77
            self.assertRaises(unstackable_format_errors,
 
78
                              branch.get_stacked_on_url)
77
79
            return
78
80
        self.assertEqual('../target', branch.get_stacked_on_url())
79
81
 
83
85
        branch = self.make_branch('branch')
84
86
        try:
85
87
            self.assertRaises(errors.UnstackableLocationError,
86
 
                branch.set_stacked_on_url, '../branch')
 
88
                              branch.set_stacked_on_url, '../branch')
87
89
        except unstackable_format_errors:
88
90
            # if the set failed, so must the get
89
 
            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
 
91
            self.assertRaises(unstackable_format_errors,
 
92
                              branch.get_stacked_on_url)
90
93
            return
91
94
        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
92
95
 
99
102
            branch.set_stacked_on_url('../target')
100
103
        except unstackable_format_errors:
101
104
            # if the set failed, so must the get
102
 
            self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
 
105
            self.assertRaises(unstackable_format_errors,
 
106
                              branch.get_stacked_on_url)
103
107
            return
104
108
        self.assertRaises(errors.UnstackableLocationError,
105
 
            branch.set_stacked_on_url, '../branch')
 
109
                          branch.set_stacked_on_url, '../branch')
106
110
        self.assertEqual('../target', branch.get_stacked_on_url())
107
111
 
108
112
    def assertRevisionInRepository(self, repo_path, revid):
133
137
        new_repo.lock_read()
134
138
        try:
135
139
            self.assertEqual(new_repo.get_parent_map([trunk_revid]),
136
 
                {trunk_revid: (NULL_REVISION, )})
 
140
                             {trunk_revid: (NULL_REVISION, )})
137
141
        finally:
138
142
            new_repo.unlock()
139
143
 
165
169
            raise TestNotApplicable(e)
166
170
        # Now serve the original mainline from a smart server
167
171
        remote_transport = self.make_smart_server('mainline')
168
 
        remote_bzrdir = controldir.ControlDir.open_from_transport(remote_transport)
 
172
        remote_bzrdir = controldir.ControlDir.open_from_transport(
 
173
            remote_transport)
169
174
        # and make branch from the smart server which is stacked
170
175
        new_dir = remote_bzrdir.sprout('newbranch', stacked=True)
171
176
        # stacked repository
173
178
        tree = new_dir.open_branch().create_checkout('local')
174
179
        new_branch_revid = tree.commit('something local')
175
180
        self.assertRevisionNotInRepository(trunk_tree.branch.user_url,
176
 
            new_branch_revid)
 
181
                                           new_branch_revid)
177
182
        self.assertRevisionInRepository('newbranch', new_branch_revid)
178
183
 
179
184
    def test_unstack_fetches(self):
183
188
        except errors.UninitializableFormat:
184
189
            raise TestNotApplicable('uninitializeable format')
185
190
        # We have a mainline
186
 
        trunk, mainline_revid, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
191
        trunk, mainline_revid, rev2 = fixtures.build_branch_with_non_ancestral_rev(
 
192
            builder)
187
193
        # and make branch from it which is stacked (with no tags)
188
194
        try:
189
 
            new_dir = trunk.controldir.sprout(self.get_url('newbranch'), stacked=True)
 
195
            new_dir = trunk.controldir.sprout(
 
196
                self.get_url('newbranch'), stacked=True)
190
197
        except unstackable_format_errors as e:
191
198
            raise TestNotApplicable(e)
192
199
        # stacked repository
194
201
        # TODO: we'd like to commit in the stacked repository; that requires
195
202
        # some care (maybe a BranchBuilder) if it's remote and has no
196
203
        # workingtree
197
 
        ##newbranch_revid = new_dir.open_workingtree().commit('revision in '
198
 
            ##'newbranch')
 
204
        # newbranch_revid = new_dir.open_workingtree().commit('revision in '
 
205
        # 'newbranch')
199
206
        # now when we unstack that should implicitly fetch, to make sure that
200
207
        # the branch will still work
201
208
        new_branch = new_dir.open_branch()
306
313
            # not a testable combination.
307
314
            raise TestNotApplicable(e)
308
315
        cloned_unstacked_bzrdir = stacked_bzrdir.clone('cloned-unstacked',
309
 
            preserve_stacking=False)
 
316
                                                       preserve_stacking=False)
310
317
        unstacked_branch = cloned_unstacked_bzrdir.open_branch()
311
318
        self.assertRaises((errors.NotStacked, _mod_branch.UnstackableBranchFormat),
312
319
                          unstacked_branch.get_stacked_on_url)
314
321
    def test_no_op_preserve_stacking(self):
315
322
        """With no stacking, preserve_stacking should be a no-op."""
316
323
        branch = self.make_branch('source')
317
 
        cloned_bzrdir = branch.controldir.clone('cloned', preserve_stacking=True)
 
324
        cloned_bzrdir = branch.controldir.clone(
 
325
            'cloned', preserve_stacking=True)
318
326
        self.assertRaises((errors.NotStacked, _mod_branch.UnstackableBranchFormat),
319
327
                          cloned_bzrdir.open_branch().get_stacked_on_url)
320
328
 
414
422
        stack_on = self.make_branch_and_tree('stack-on')
415
423
        if not stack_on.branch._format.supports_stacking():
416
424
            raise TestNotApplicable("%r does not support stacking"
417
 
                % self.branch_format)
 
425
                                    % self.branch_format)
418
426
        text_lines = [b'line %d blah blah blah\n' % i for i in range(20)]
419
427
        self.build_tree_contents([('stack-on/a', b''.join(text_lines))])
420
428
        stack_on.add('a')
433
441
    def test_pull_delta_when_stacked(self):
434
442
        if not self.branch_format.supports_stacking():
435
443
            raise TestNotApplicable("%r does not support stacking"
436
 
                % self.branch_format)
 
444
                                    % self.branch_format)
437
445
        stack_on = self.make_branch_and_tree('stack-on')
438
446
        text_lines = [b'line %d blah blah blah\n' % i for i in range(20)]
439
447
        self.build_tree_contents([('stack-on/a', b''.join(text_lines))])
497
505
            raise TestNotApplicable('Format does not support stacking.')
498
506
        self.get_transport().rename('stack-on', 'new-stack-on')
499
507
        hook_calls = []
 
508
 
500
509
        def hook(stacked_branch, url):
501
510
            hook_calls.append(url)
502
511
            return '../new-stack-on'