~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-01 23:48:08 UTC
  • mfrom: (2225.1.6 revert)
  • Revision ID: pqm@pqm.ubuntu.com-20070201234808-3b1302d73474bd8c
Display changes made by revert

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
                           BzrDir, BzrDirFormat)
33
33
from bzrlib.errors import (NotBranchError,
34
34
                           UnknownFormatError,
 
35
                           UnknownHook,
35
36
                           UnsupportedFormatError,
36
37
                           )
37
38
 
77
78
            branch.unlock()
78
79
 
79
80
 
80
 
class TestBranchEscaping(TestCaseWithTransport):
81
 
    """Test a branch can be correctly stored and used on a vfat-like transport
82
 
    
83
 
    Makes sure we have proper escaping of invalid characters, etc.
84
 
 
85
 
    It'd be better to test all operations on the FakeVFATTransportDecorator,
86
 
    but working trees go straight to the os not through the Transport layer.
87
 
    Therefore we build some history first in the regular way and then 
88
 
    check it's safe to access for vfat.
89
 
    """
90
 
 
91
 
    FOO_ID = 'foo<:>ID'
92
 
    REV_ID = 'revid-1'
93
 
 
94
 
    def setUp(self):
95
 
        super(TestBranchEscaping, self).setUp()
96
 
        from bzrlib.repository import RepositoryFormatKnit1
97
 
        bzrdir = BzrDirMetaFormat1().initialize(self.get_url())
98
 
        repo = RepositoryFormatKnit1().initialize(bzrdir)
99
 
        branch = bzrdir.create_branch()
100
 
        wt = bzrdir.create_workingtree()
101
 
        self.build_tree_contents([("foo", "contents of foo")])
102
 
        # add file with id containing wierd characters
103
 
        wt.add(['foo'], [self.FOO_ID])
104
 
        wt.commit('this is my new commit', rev_id=self.REV_ID)
105
 
 
106
 
    def test_branch_on_vfat(self):
107
 
        from bzrlib.transport.fakevfat import FakeVFATTransportDecorator
108
 
        # now access over vfat; should be safe
109
 
        transport = FakeVFATTransportDecorator('vfat+' + self.get_url())
110
 
        bzrdir, junk = BzrDir.open_containing_from_transport(transport)
111
 
        branch = bzrdir.open_branch()
112
 
        revtree = branch.repository.revision_tree(self.REV_ID)
113
 
        contents = revtree.get_file_text(self.FOO_ID)
114
 
        self.assertEqual(contents, 'contents of foo')
115
 
 
116
 
 
117
81
class SampleBranchFormat(bzrlib.branch.BranchFormat):
118
82
    """A sample format
119
83
 
128
92
    def initialize(self, a_bzrdir):
129
93
        """Format 4 branches cannot be created."""
130
94
        t = a_bzrdir.get_branch_transport(self)
131
 
        t.put('format', StringIO(self.get_format_string()))
 
95
        t.put_bytes('format', self.get_format_string())
132
96
        return 'A branch'
133
97
 
134
98
    def is_supported(self):
199
163
        self.assertEqual(made_branch.base, target_branch.base)
200
164
        opened_branch = branch_dir.open_branch()
201
165
        self.assertEqual(opened_branch.base, target_branch.base)
 
166
 
 
167
 
 
168
class TestHooks(TestCase):
 
169
 
 
170
    def test_constructor(self):
 
171
        """Check that creating a BranchHooks instance has the right defaults."""
 
172
        hooks = bzrlib.branch.BranchHooks()
 
173
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
 
174
 
 
175
    def test_installed_hooks_are_BranchHooks(self):
 
176
        """The installed hooks object should be a BranchHooks."""
 
177
        # the installed hooks are saved in self._preserved_hooks.
 
178
        self.assertIsInstance(self._preserved_hooks, bzrlib.branch.BranchHooks)
 
179
 
 
180
    def test_install_hook_raises_unknown_hook(self):
 
181
        """install_hook should raise UnknownHook if a hook is unknown."""
 
182
        hooks = bzrlib.branch.BranchHooks()
 
183
        self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
 
184
 
 
185
    def test_install_hook_appends_known_hook(self):
 
186
        """install_hook should append the callable for known hooks."""
 
187
        hooks = bzrlib.branch.BranchHooks()
 
188
        hooks.install_hook('set_rh', None)
 
189
        self.assertEqual(hooks['set_rh'], [None])