~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-29 15:50:58 UTC
  • mfrom: (6177 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6178.
  • Revision ID: v.ladeuil+lp@free.fr-20110929155058-zgbecmx1huzktegm
Merge trunk and resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
101
101
    # recursive section - that is, it appends the branch name.
102
102
 
103
103
 
104
 
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
 
104
class SampleBranchFormat(_mod_branch.BranchFormat):
105
105
    """A sample format
106
106
 
107
107
    this format is initializable, unsupported to aid in testing the
108
108
    open and open_downlevel routines.
109
109
    """
110
110
 
111
 
    @classmethod
112
 
    def get_format_string(cls):
 
111
    def get_format_string(self):
113
112
        """See BzrBranchFormat.get_format_string()."""
114
113
        return "Sample branch format."
115
114
 
123
122
    def is_supported(self):
124
123
        return False
125
124
 
126
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
127
 
             possible_transports=None):
 
125
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
128
126
        return "opened branch."
129
127
 
130
128
 
133
131
SampleSupportedBranchFormatString = "Sample supported branch format."
134
132
 
135
133
# And the format class can then reference the constant to avoid skew.
136
 
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
 
134
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
137
135
    """A sample supported format."""
138
136
 
139
 
    @classmethod
140
 
    def get_format_string(cls):
 
137
    def get_format_string(self):
141
138
        """See BzrBranchFormat.get_format_string()."""
142
139
        return SampleSupportedBranchFormatString
143
140
 
146
143
        t.put_bytes('format', self.get_format_string())
147
144
        return 'A branch'
148
145
 
149
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
150
 
             possible_transports=None):
 
146
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
151
147
        return "opened supported branch."
152
148
 
153
149
 
165
161
    def initialize(self, a_bzrdir, name=None):
166
162
        raise NotImplementedError(self.initialize)
167
163
 
168
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
169
 
             possible_transports=None):
 
164
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
170
165
        raise NotImplementedError(self.open)
171
166
 
172
167
 
182
177
            dir = format._matchingbzrdir.initialize(url)
183
178
            dir.create_repository()
184
179
            format.initialize(dir)
185
 
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
 
180
            found_format = _mod_branch.BranchFormat.find_format(dir)
186
181
            self.assertIsInstance(found_format, format.__class__)
187
182
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
188
183
 
197
192
        b = _mod_branch.Branch.open(self.get_url())
198
193
        self.assertEqual(b, "opened supported branch.")
199
194
 
200
 
    def test_from_string(self):
201
 
        self.assertIsInstance(
202
 
            SampleBranchFormat.from_string("Sample branch format."),
203
 
            SampleBranchFormat)
204
 
        self.assertRaises(AssertionError,
205
 
            SampleBranchFormat.from_string, "Different branch format.")
206
 
 
207
195
    def test_find_format_not_branch(self):
208
196
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
209
197
        self.assertRaises(errors.NotBranchError,
210
 
                          _mod_branch.BranchFormatMetadir.find_format,
 
198
                          _mod_branch.BranchFormat.find_format,
211
199
                          dir)
212
200
 
213
201
    def test_find_format_unknown_format(self):
214
202
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
215
203
        SampleBranchFormat().initialize(dir)
216
204
        self.assertRaises(errors.UnknownFormatError,
217
 
                          _mod_branch.BranchFormatMetadir.find_format,
 
205
                          _mod_branch.BranchFormat.find_format,
218
206
                          dir)
219
207
 
220
 
    def test_find_format_with_features(self):
221
 
        tree = self.make_branch_and_tree('.', format='2a')
222
 
        tree.branch.update_feature_flags({"name": "optional"})
223
 
        found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
224
 
        self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
225
 
        self.assertEquals(found_format.features.get("name"), "optional")
226
 
        tree.branch.update_feature_flags({"name": None})
227
 
        branch = _mod_branch.Branch.open('.')
228
 
        self.assertEquals(branch._format.features, {})
229
 
 
230
208
    def test_register_unregister_format(self):
231
209
        # Test the deprecated format registration functions
232
210
        format = SampleBranchFormat()
356
334
        self.assertPathDoesNotExist('a/.bzr/branch/parent')
357
335
        self.assertEqual('http://example.com', branch.get_parent())
358
336
        branch.set_push_location('sftp://example.com')
359
 
        conf = branch.get_config_stack()
360
 
        self.assertEqual('sftp://example.com', conf.get('push_location'))
 
337
        config = branch.get_config()._get_branch_data_config()
 
338
        self.assertEqual('sftp://example.com',
 
339
                         config.get_user_option('push_location'))
361
340
        branch.set_bound_location('ftp://example.com')
362
341
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
363
342
        self.assertEqual('ftp://example.com', branch.get_bound_location())
412
391
    def test_light_checkout_with_references(self):
413
392
        self.do_checkout_test(lightweight=True)
414
393
 
 
394
    def test_set_push(self):
 
395
        branch = self.make_branch('source', format=self.get_format_name())
 
396
        branch.get_config().set_user_option('push_location', 'old',
 
397
            store=config.STORE_LOCATION)
 
398
        warnings = []
 
399
        def warning(*args):
 
400
            warnings.append(args[0] % args[1:])
 
401
        _warning = trace.warning
 
402
        trace.warning = warning
 
403
        try:
 
404
            branch.set_push_location('new')
 
405
        finally:
 
406
            trace.warning = _warning
 
407
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
 
408
                         'locations.conf')
 
409
 
415
410
 
416
411
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
417
412
 
546
541
        self.assertEqual(('path3', 'location3'),
547
542
                         branch.get_reference_info('file-id'))
548
543
 
549
 
    def _recordParentMapCalls(self, repo):
550
 
        self._parent_map_calls = []
551
 
        orig_get_parent_map = repo.revisions.get_parent_map
552
 
        def get_parent_map(q):
553
 
            q = list(q)
554
 
            self._parent_map_calls.extend([e[0] for e in q])
555
 
            return orig_get_parent_map(q)
556
 
        repo.revisions.get_parent_map = get_parent_map
557
 
 
558
 
 
559
544
class TestBranchReference(tests.TestCaseWithTransport):
560
545
    """Tests for the branch reference facility."""
561
546
 
575
560
        self.assertEqual(opened_branch.base, target_branch.base)
576
561
 
577
562
    def test_get_reference(self):
578
 
        """For a BranchReference, get_reference should return the location."""
 
563
        """For a BranchReference, get_reference should reutrn the location."""
579
564
        branch = self.make_branch('target')
580
565
        checkout = branch.create_checkout('checkout', lightweight=True)
581
566
        reference_url = branch.bzrdir.root_transport.abspath('') + '/'
661
646
    def setUp(self):
662
647
        super(TestBranchOptions, self).setUp()
663
648
        self.branch = self.make_branch('.')
664
 
        self.config_stack = self.branch.get_config_stack()
 
649
        self.config = self.branch.get_config()
665
650
 
666
651
    def check_append_revisions_only(self, expected_value, value=None):
667
652
        """Set append_revisions_only in config and check its interpretation."""
668
653
        if value is not None:
669
 
            self.config_stack.set('append_revisions_only', value)
 
654
            self.config.set_user_option('append_revisions_only', value)
670
655
        self.assertEqual(expected_value,
671
656
                         self.branch.get_append_revisions_only())
672
657
 
673
658
    def test_valid_append_revisions_only(self):
674
659
        self.assertEquals(None,
675
 
                          self.config_stack.get('append_revisions_only'))
 
660
                          self.config.get_user_option('append_revisions_only'))
676
661
        self.check_append_revisions_only(None)
677
662
        self.check_append_revisions_only(False, 'False')
678
663
        self.check_append_revisions_only(True, 'True')
690
675
        self.check_append_revisions_only(None, 'not-a-bool')
691
676
        self.assertLength(1, self.warnings)
692
677
        self.assertEqual(
693
 
            'Value "not-a-bool" is not valid for "append_revisions_only"',
 
678
            'Value "not-a-bool" is not a boolean for "append_revisions_only"',
694
679
            self.warnings[0])
695
680
 
696
681
 
718
703
        f = StringIO()
719
704
        r.report(f)
720
705
        self.assertEqual("Now on revision 20.\n", f.getvalue())
721
 
        self.assertEqual("Now on revision 20.\n", f.getvalue())
722
706
 
723
707
    def test_report_unchanged(self):
724
708
        r = _mod_branch.PullResult()
727
711
        f = StringIO()
728
712
        r.report(f)
729
713
        self.assertEqual("No revisions or tags to pull.\n", f.getvalue())
 
714