~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-23 19:08:05 UTC
  • mfrom: (6437.3.20 2.5)
  • mto: This revision was merged to the branch mainline in revision 6450.
  • Revision ID: jelmer@samba.org-20120123190805-hlcuihkt2dep44cw
merge bzr 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
    # recursive section - that is, it appends the branch name.
102
102
 
103
103
 
104
 
class SampleBranchFormat(_mod_branch.BranchFormat):
 
104
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
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
 
    def get_format_string(self):
 
111
    @classmethod
 
112
    def get_format_string(cls):
112
113
        """See BzrBranchFormat.get_format_string()."""
113
114
        return "Sample branch format."
114
115
 
132
133
SampleSupportedBranchFormatString = "Sample supported branch format."
133
134
 
134
135
# And the format class can then reference the constant to avoid skew.
135
 
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
 
136
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
136
137
    """A sample supported format."""
137
138
 
138
 
    def get_format_string(self):
 
139
    @classmethod
 
140
    def get_format_string(cls):
139
141
        """See BzrBranchFormat.get_format_string()."""
140
142
        return SampleSupportedBranchFormatString
141
143
 
180
182
            dir = format._matchingbzrdir.initialize(url)
181
183
            dir.create_repository()
182
184
            format.initialize(dir)
183
 
            found_format = _mod_branch.BranchFormat.find_format(dir)
 
185
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
184
186
            self.assertIsInstance(found_format, format.__class__)
185
187
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
186
188
 
195
197
        b = _mod_branch.Branch.open(self.get_url())
196
198
        self.assertEqual(b, "opened supported branch.")
197
199
 
 
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
 
198
207
    def test_find_format_not_branch(self):
199
208
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
200
209
        self.assertRaises(errors.NotBranchError,
201
 
                          _mod_branch.BranchFormat.find_format,
 
210
                          _mod_branch.BranchFormatMetadir.find_format,
202
211
                          dir)
203
212
 
204
213
    def test_find_format_unknown_format(self):
205
214
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
206
215
        SampleBranchFormat().initialize(dir)
207
216
        self.assertRaises(errors.UnknownFormatError,
208
 
                          _mod_branch.BranchFormat.find_format,
 
217
                          _mod_branch.BranchFormatMetadir.find_format,
209
218
                          dir)
210
219
 
 
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
 
211
230
    def test_register_unregister_format(self):
212
231
        # Test the deprecated format registration functions
213
232
        format = SampleBranchFormat()
337
356
        self.assertPathDoesNotExist('a/.bzr/branch/parent')
338
357
        self.assertEqual('http://example.com', branch.get_parent())
339
358
        branch.set_push_location('sftp://example.com')
340
 
        config = branch.get_config()._get_branch_data_config()
341
 
        self.assertEqual('sftp://example.com',
342
 
                         config.get_user_option('push_location'))
 
359
        config = branch.get_config_stack()
 
360
        self.assertEqual('sftp://example.com', config.get('push_location'))
343
361
        branch.set_bound_location('ftp://example.com')
344
362
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
345
363
        self.assertEqual('ftp://example.com', branch.get_bound_location())
394
412
    def test_light_checkout_with_references(self):
395
413
        self.do_checkout_test(lightweight=True)
396
414
 
397
 
    def test_set_push(self):
398
 
        branch = self.make_branch('source', format=self.get_format_name())
399
 
        branch.get_config().set_user_option('push_location', 'old',
400
 
            store=config.STORE_LOCATION)
401
 
        warnings = []
402
 
        def warning(*args):
403
 
            warnings.append(args[0] % args[1:])
404
 
        _warning = trace.warning
405
 
        trace.warning = warning
406
 
        try:
407
 
            branch.set_push_location('new')
408
 
        finally:
409
 
            trace.warning = _warning
410
 
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
411
 
                         'locations.conf')
412
 
 
413
415
 
414
416
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
415
417
 
573
575
        self.assertEqual(opened_branch.base, target_branch.base)
574
576
 
575
577
    def test_get_reference(self):
576
 
        """For a BranchReference, get_reference should reutrn the location."""
 
578
        """For a BranchReference, get_reference should return the location."""
577
579
        branch = self.make_branch('target')
578
580
        checkout = branch.create_checkout('checkout', lightweight=True)
579
581
        reference_url = branch.bzrdir.root_transport.abspath('') + '/'
659
661
    def setUp(self):
660
662
        super(TestBranchOptions, self).setUp()
661
663
        self.branch = self.make_branch('.')
662
 
        self.config = self.branch.get_config()
 
664
        self.config_stack = self.branch.get_config_stack()
663
665
 
664
666
    def check_append_revisions_only(self, expected_value, value=None):
665
667
        """Set append_revisions_only in config and check its interpretation."""
666
668
        if value is not None:
667
 
            self.config.set_user_option('append_revisions_only', value)
 
669
            self.config_stack.set('append_revisions_only', value)
668
670
        self.assertEqual(expected_value,
669
671
                         self.branch.get_append_revisions_only())
670
672
 
671
673
    def test_valid_append_revisions_only(self):
672
674
        self.assertEquals(None,
673
 
                          self.config.get_user_option('append_revisions_only'))
 
675
                          self.config_stack.get('append_revisions_only'))
674
676
        self.check_append_revisions_only(None)
675
677
        self.check_append_revisions_only(False, 'False')
676
678
        self.check_append_revisions_only(True, 'True')
688
690
        self.check_append_revisions_only(None, 'not-a-bool')
689
691
        self.assertLength(1, self.warnings)
690
692
        self.assertEqual(
691
 
            'Value "not-a-bool" is not a boolean for "append_revisions_only"',
 
693
            'Value "not-a-bool" is not valid for "append_revisions_only"',
692
694
            self.warnings[0])
693
695
 
694
696
 
716
718
        f = StringIO()
717
719
        r.report(f)
718
720
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
721
        self.assertEqual("Now on revision 20.\n", f.getvalue())
719
722
 
720
723
    def test_report_unchanged(self):
721
724
        r = _mod_branch.PullResult()
724
727
        f = StringIO()
725
728
        r.report(f)
726
729
        self.assertEqual("No revisions or tags to pull.\n", f.getvalue())
727