~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Robert Collins
  • Date: 2009-03-18 03:47:30 UTC
  • mto: This revision was merged to the branch mainline in revision 4162.
  • Revision ID: robertc@robertcollins.net-20090318034730-xex5ks3t5ct7gin6
Add a BzrDir.pre_open hook for use by the smart server gaol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1306
1306
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1307
1307
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1308
1308
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
 
1309
 
 
1310
 
 
1311
class TestBzrDirHooks(TestCaseWithMemoryTransport):
 
1312
 
 
1313
    def test_pre_open_called(self):
 
1314
        calls = []
 
1315
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
 
1316
        transport = self.get_transport('foo')
 
1317
        url = transport.base
 
1318
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
 
1319
        self.assertEqual([transport.base], [t.base for t in calls])
 
1320
 
 
1321
    def test_pre_open_actual_exceptions_raised(self):
 
1322
        count = [0]
 
1323
        def fail_once(transport):
 
1324
            count[0] += 1
 
1325
            if count[0] == 1:
 
1326
                raise errors.BzrError("fail")
 
1327
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
 
1328
        transport = self.get_transport('foo')
 
1329
        url = transport.base
 
1330
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
 
1331
        self.assertEqual('fail', err._preformatted_string)