~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/tests/test_safe_open.py

Merge safe-open branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.branch import (
24
24
    Branch,
25
25
    BzrBranchFormat7,
 
26
    BranchReferenceFormat,
26
27
    )
27
28
from bzrlib.bzrdir import (
 
29
    BzrDir,
28
30
    BzrDirMetaFormat1,
29
31
    )
30
32
from bzrlib.repofmt.pack_repo import RepositoryFormatKnitPack1
57
59
                self._reference_values[references[i]] = references[i+1]
58
60
            self.follow_reference_calls = []
59
61
 
60
 
        def followReference(self, url):
 
62
        def followReference(self, url, open_dir=None):
61
63
            self.follow_reference_calls.append(url)
62
64
            return self._reference_values[url]
63
65
 
232
234
        self.assertRaises(BranchLoopError, opener.open, a.base)
233
235
        self.assertRaises(BranchLoopError, opener.open, b.base)
234
236
 
 
237
    def testCustomOpener(self):
 
238
        # A custom function for opening a control dir can be specified.
 
239
        a = self.make_branch('a', format='2a')
 
240
        b = self.make_branch('b', format='2a')
 
241
        b.set_stacked_on_url(a.base)
 
242
        seen_urls = set()
 
243
        def open_dir(url):
 
244
            seen_urls.add(url)
 
245
            return BzrDir.open(url)
 
246
        opener = self.makeBranchOpener([a.base, b.base])
 
247
        opener.open(b.base, open_dir=open_dir)
 
248
        self.assertEquals(seen_urls, set([b.base, a.base]))
 
249
 
 
250
    def testCustomOpenerWithBranchReference(self):
 
251
        # A custom function for opening a control dir can be specified.
 
252
        a = self.make_branch('a', format='2a')
 
253
        b_dir = self.make_bzrdir('b')
 
254
        b = BranchReferenceFormat().initialize(b_dir, target_branch=a)
 
255
        seen_urls = set()
 
256
        def open_dir(url):
 
257
            seen_urls.add(url)
 
258
            return BzrDir.open(url)
 
259
        opener = self.makeBranchOpener([a.base, b.base])
 
260
        opener.open(b.base, open_dir=open_dir)
 
261
        self.assertEquals(seen_urls, set([b.base, a.base]))
 
262
 
235
263
 
236
264
class TestSafeOpen(TestCaseWithTransport):
237
265
    """Tests for `safe_open`."""