80
class TestBranchEscaping(TestCaseWithTransport):
81
"""Test a branch can be correctly stored and used on a vfat-like transport
83
Makes sure we have proper escaping of invalid characters, etc.
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.
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)
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')
117
81
class SampleBranchFormat(bzrlib.branch.BranchFormat):
118
82
"""A sample format
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())
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)
168
class TestHooks(TestCase):
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)
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)
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)
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])