/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__chk_map.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from bzrlib import (
20
20
    chk_map,
 
21
    inventory,
21
22
    tests,
22
23
    )
23
24
from bzrlib.static_tuple import StaticTuple
236
237
        self.assertEqual(("sha1:1234",), node.key())
237
238
        self.assertEqual('pref\x00fo', node._search_prefix)
238
239
        self.assertEqual({'pref\x00fo\x00': ('sha1:abcd',)}, node._items)
 
240
 
 
241
 
 
242
class Test_BytesToTextKey(tests.TestCase):
 
243
 
 
244
    def assertBytesToTextKey(self, key, bytes):
 
245
        self.assertEqual(key,
 
246
                         self.module._bytes_to_text_key(bytes))
 
247
 
 
248
    def assertBytesToTextKeyRaises(self, bytes):
 
249
        # These are invalid bytes, and we want to make sure the code under test
 
250
        # raises an exception rather than segfaults, etc. We don't particularly
 
251
        # care what exception.
 
252
        self.assertRaises(Exception, self.module._bytes_to_text_key, bytes)
 
253
 
 
254
    def test_file(self):
 
255
        self.assertBytesToTextKey(('file-id', 'revision-id'),
 
256
                 'file: file-id\nparent-id\nname\nrevision-id\n'
 
257
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
258
 
 
259
    def test_invalid_no_kind(self):
 
260
        self.assertBytesToTextKeyRaises(
 
261
                 'file  file-id\nparent-id\nname\nrevision-id\n'
 
262
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
263
 
 
264
    def test_invalid_no_space(self):
 
265
        self.assertBytesToTextKeyRaises(
 
266
                 'file:file-id\nparent-id\nname\nrevision-id\n'
 
267
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
268
 
 
269
    def test_invalid_too_short_file_id(self):
 
270
        self.assertBytesToTextKeyRaises('file:file-id')
 
271
 
 
272
    def test_invalid_too_short_parent_id(self):
 
273
        self.assertBytesToTextKeyRaises('file:file-id\nparent-id')
 
274
 
 
275
    def test_invalid_too_short_name(self):
 
276
        self.assertBytesToTextKeyRaises('file:file-id\nparent-id\nname')
 
277
 
 
278
    def test_dir(self):
 
279
        self.assertBytesToTextKey(('dir-id', 'revision-id'),
 
280
                 'dir: dir-id\nparent-id\nname\nrevision-id')