~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

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
 
115
 
    def initialize(self, a_bzrdir, name=None, repository=None):
 
116
    def initialize(self, a_bzrdir, name=None, repository=None,
 
117
                   append_revisions_only=None):
116
118
        """Format 4 branches cannot be created."""
117
119
        t = a_bzrdir.get_branch_transport(self, name=name)
118
120
        t.put_bytes('format', self.get_format_string())
121
123
    def is_supported(self):
122
124
        return False
123
125
 
124
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
126
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
 
127
             possible_transports=None):
125
128
        return "opened branch."
126
129
 
127
130
 
130
133
SampleSupportedBranchFormatString = "Sample supported branch format."
131
134
 
132
135
# And the format class can then reference the constant to avoid skew.
133
 
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
 
136
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
134
137
    """A sample supported format."""
135
138
 
136
 
    def get_format_string(self):
 
139
    @classmethod
 
140
    def get_format_string(cls):
137
141
        """See BzrBranchFormat.get_format_string()."""
138
142
        return SampleSupportedBranchFormatString
139
143
 
140
 
    def initialize(self, a_bzrdir, name=None):
 
144
    def initialize(self, a_bzrdir, name=None, append_revisions_only=None):
141
145
        t = a_bzrdir.get_branch_transport(self, name=name)
142
146
        t.put_bytes('format', self.get_format_string())
143
147
        return 'A branch'
144
148
 
145
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
149
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
 
150
             possible_transports=None):
146
151
        return "opened supported branch."
147
152
 
148
153
 
160
165
    def initialize(self, a_bzrdir, name=None):
161
166
        raise NotImplementedError(self.initialize)
162
167
 
163
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
168
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
 
169
             possible_transports=None):
164
170
        raise NotImplementedError(self.open)
165
171
 
166
172
 
176
182
            dir = format._matchingbzrdir.initialize(url)
177
183
            dir.create_repository()
178
184
            format.initialize(dir)
179
 
            found_format = _mod_branch.BranchFormat.find_format(dir)
 
185
            found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
180
186
            self.assertIsInstance(found_format, format.__class__)
181
187
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
182
188
 
191
197
        b = _mod_branch.Branch.open(self.get_url())
192
198
        self.assertEqual(b, "opened supported branch.")
193
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
 
194
207
    def test_find_format_not_branch(self):
195
208
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
196
209
        self.assertRaises(errors.NotBranchError,
197
 
                          _mod_branch.BranchFormat.find_format,
 
210
                          _mod_branch.BranchFormatMetadir.find_format,
198
211
                          dir)
199
212
 
200
213
    def test_find_format_unknown_format(self):
201
214
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
202
215
        SampleBranchFormat().initialize(dir)
203
216
        self.assertRaises(errors.UnknownFormatError,
204
 
                          _mod_branch.BranchFormat.find_format,
 
217
                          _mod_branch.BranchFormatMetadir.find_format,
205
218
                          dir)
206
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
 
207
230
    def test_register_unregister_format(self):
208
231
        # Test the deprecated format registration functions
209
232
        format = SampleBranchFormat()
390
413
    def test_light_checkout_with_references(self):
391
414
        self.do_checkout_test(lightweight=True)
392
415
 
393
 
    def test_set_push(self):
394
 
        branch = self.make_branch('source', format=self.get_format_name())
395
 
        branch.get_config().set_user_option('push_location', 'old',
396
 
            store=config.STORE_LOCATION)
397
 
        warnings = []
398
 
        def warning(*args):
399
 
            warnings.append(args[0] % args[1:])
400
 
        _warning = trace.warning
401
 
        trace.warning = warning
402
 
        try:
403
 
            branch.set_push_location('new')
404
 
        finally:
405
 
            trace.warning = _warning
406
 
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
407
 
                         'locations.conf')
408
 
 
409
416
 
410
417
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
411
418
 
540
547
        self.assertEqual(('path3', 'location3'),
541
548
                         branch.get_reference_info('file-id'))
542
549
 
 
550
    def _recordParentMapCalls(self, repo):
 
551
        self._parent_map_calls = []
 
552
        orig_get_parent_map = repo.revisions.get_parent_map
 
553
        def get_parent_map(q):
 
554
            q = list(q)
 
555
            self._parent_map_calls.extend([e[0] for e in q])
 
556
            return orig_get_parent_map(q)
 
557
        repo.revisions.get_parent_map = get_parent_map
 
558
 
 
559
 
543
560
class TestBranchReference(tests.TestCaseWithTransport):
544
561
    """Tests for the branch reference facility."""
545
562
 
645
662
    def setUp(self):
646
663
        super(TestBranchOptions, self).setUp()
647
664
        self.branch = self.make_branch('.')
648
 
        self.config = self.branch.get_config()
 
665
        self.config_stack = self.branch.get_config_stack()
649
666
 
650
667
    def check_append_revisions_only(self, expected_value, value=None):
651
668
        """Set append_revisions_only in config and check its interpretation."""
652
669
        if value is not None:
653
 
            self.config.set_user_option('append_revisions_only', value)
 
670
            self.config_stack.set('append_revisions_only', value)
654
671
        self.assertEqual(expected_value,
655
 
                         self.branch._get_append_revisions_only())
 
672
                         self.branch.get_append_revisions_only())
656
673
 
657
674
    def test_valid_append_revisions_only(self):
658
675
        self.assertEquals(None,
659
 
                          self.config.get_user_option('append_revisions_only'))
 
676
                          self.config_stack.get('append_revisions_only'))
660
677
        self.check_append_revisions_only(None)
661
678
        self.check_append_revisions_only(False, 'False')
662
679
        self.check_append_revisions_only(True, 'True')
674
691
        self.check_append_revisions_only(None, 'not-a-bool')
675
692
        self.assertLength(1, self.warnings)
676
693
        self.assertEqual(
677
 
            'Value "not-a-bool" is not a boolean for "append_revisions_only"',
 
694
            'Value "not-a-bool" is not valid for "append_revisions_only"',
678
695
            self.warnings[0])
679
696
 
680
697
 
702
719
        f = StringIO()
703
720
        r.report(f)
704
721
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
722
        self.assertEqual("Now on revision 20.\n", f.getvalue())
705
723
 
706
724
    def test_report_unchanged(self):
707
725
        r = _mod_branch.PullResult()
709
727
        r.new_revid = "same-revid"
710
728
        f = StringIO()
711
729
        r.report(f)
712
 
        self.assertEqual("No revisions to pull.\n", f.getvalue())
713
 
 
 
730
        self.assertEqual("No revisions or tags to pull.\n", f.getvalue())