~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

(jelmer) Add a common base class BzrDirMetaComponentFormat for all formats
 living in bzr meta directories. (Jelmer Vernooij)

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(ValueError,
 
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
 
211
220
    def test_register_unregister_format(self):
716
725
        f = StringIO()
717
726
        r.report(f)
718
727
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
728
        self.assertEqual("Now on revision 20.\n", f.getvalue())
719
729
 
720
730
    def test_report_unchanged(self):
721
731
        r = _mod_branch.PullResult()