/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 bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-03 02:53:10 UTC
  • mfrom: (5404.2.1 2.3-test-loader)
  • Revision ID: pqm@pqm.ubuntu.com-20100903025310-t8mj1bjq4fsyxk7p
(jameinel) Restore TestSuite and TestLoader as attributes of bzrlib.tests
 (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        self.assertIsDirectory('.bzr/branch/lock/held', t)
87
87
 
88
88
    def test_set_push_location(self):
89
 
        from bzrlib.config import (locations_config_filename,
90
 
                                   ensure_config_dir_exists)
91
 
        ensure_config_dir_exists()
92
 
        fn = locations_config_filename()
93
 
        # write correct newlines to locations.conf
94
 
        # by default ConfigObj uses native line-endings for new files
95
 
        # but uses already existing line-endings if file is not empty
96
 
        f = open(fn, 'wb')
97
 
        try:
98
 
            f.write('# comment\n')
99
 
        finally:
100
 
            f.close()
 
89
        conf = config.LocationConfig.from_string('# comment\n', '.', save=True)
101
90
 
102
91
        branch = self.make_branch('.', format='knit')
103
92
        branch.set_push_location('foo')
106
95
                             "[%s]\n"
107
96
                             "push_location = foo\n"
108
97
                             "push_location:policy = norecurse\n" % local_path,
109
 
                             fn)
 
98
                             config.locations_config_filename())
110
99
 
111
100
    # TODO RBC 20051029 test getting a push location from a branch in a
112
101
    # recursive section - that is, it appends the branch name.
136
125
        return "opened branch."
137
126
 
138
127
 
 
128
# Demonstrating how lazy loading is often implemented:
 
129
# A constant string is created.
 
130
SampleSupportedBranchFormatString = "Sample supported branch format."
 
131
 
 
132
# And the format class can then reference the constant to avoid skew.
 
133
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
 
134
    """A sample supported format."""
 
135
 
 
136
    def get_format_string(self):
 
137
        """See BzrBranchFormat.get_format_string()."""
 
138
        return SampleSupportedBranchFormatString
 
139
 
 
140
    def initialize(self, a_bzrdir, name=None):
 
141
        t = a_bzrdir.get_branch_transport(self, name=name)
 
142
        t.put_bytes('format', self.get_format_string())
 
143
        return 'A branch'
 
144
 
 
145
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
146
        return "opened supported branch."
 
147
 
 
148
 
139
149
class TestBzrBranchFormat(tests.TestCaseWithTransport):
140
150
    """Tests for the BzrBranchFormat facility."""
141
151
 
152
162
            self.failUnless(isinstance(found_format, format.__class__))
153
163
        check_format(_mod_branch.BzrBranchFormat5(), "bar")
154
164
 
 
165
    def test_find_format_factory(self):
 
166
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
167
        SampleSupportedBranchFormat().initialize(dir)
 
168
        factory = _mod_branch.MetaDirBranchFormatFactory(
 
169
            SampleSupportedBranchFormatString,
 
170
            "bzrlib.tests.test_branch", "SampleSupportedBranchFormat")
 
171
        _mod_branch.BranchFormat.register_format(factory)
 
172
        self.addCleanup(_mod_branch.BranchFormat.unregister_format, factory)
 
173
        b = _mod_branch.Branch.open(self.get_url())
 
174
        self.assertEqual(b, "opened supported branch.")
 
175
 
155
176
    def test_find_format_not_branch(self):
156
177
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
157
178
        self.assertRaises(errors.NotBranchError,
186
207
        self.make_branch_and_tree('bar')
187
208
 
188
209
 
 
210
#Used by TestMetaDirBranchFormatFactory 
 
211
FakeLazyFormat = None
 
212
 
 
213
 
 
214
class TestMetaDirBranchFormatFactory(tests.TestCase):
 
215
 
 
216
    def test_get_format_string_does_not_load(self):
 
217
        """Formats have a static format string."""
 
218
        factory = _mod_branch.MetaDirBranchFormatFactory("yo", None, None)
 
219
        self.assertEqual("yo", factory.get_format_string())
 
220
 
 
221
    def test_call_loads(self):
 
222
        # __call__ is used by the network_format_registry interface to get a
 
223
        # Format.
 
224
        global FakeLazyFormat
 
225
        del FakeLazyFormat
 
226
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
 
227
            "bzrlib.tests.test_branch", "FakeLazyFormat")
 
228
        self.assertRaises(AttributeError, factory)
 
229
 
 
230
    def test_call_returns_call_of_referenced_object(self):
 
231
        global FakeLazyFormat
 
232
        FakeLazyFormat = lambda:'called'
 
233
        factory = _mod_branch.MetaDirBranchFormatFactory(None,
 
234
            "bzrlib.tests.test_branch", "FakeLazyFormat")
 
235
        self.assertEqual('called', factory())
 
236
 
 
237
 
189
238
class TestBranch67(object):
190
239
    """Common tests for both branch 6 and 7 which are mostly the same."""
191
240
 
492
541
        self.assertTrue(hasattr(params, 'bzrdir'))
493
542
        self.assertTrue(hasattr(params, 'branch'))
494
543
 
 
544
    def test_post_branch_init_hook_repr(self):
 
545
        param_reprs = []
 
546
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
 
547
            lambda params: param_reprs.append(repr(params)), None)
 
548
        branch = self.make_branch('a')
 
549
        self.assertLength(1, param_reprs)
 
550
        param_repr = param_reprs[0]
 
551
        self.assertStartsWith(param_repr, '<BranchInitHookParams of ')
 
552
 
495
553
    def test_post_switch_hook(self):
496
554
        from bzrlib import switch
497
555
        calls = []