1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Tests for _chk_map_*."""
23
from bzrlib.static_tuple import StaticTuple
25
from ..static_tuple import StaticTuple
24
26
stuple = StaticTuple
27
def load_tests(standard_tests, module, loader):
29
def load_tests(loader, standard_tests, pattern):
28
30
suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
29
'bzrlib._chk_map_py', 'bzrlib._chk_map_pyx')
31
'breezy.bzr._chk_map_py', 'breezy.bzr._chk_map_pyx')
62
64
for char_in in range(256):
63
65
search_key = self.module._search_key_255(stuple(chr(char_in),))
64
66
chars_used.update(search_key)
65
all_chars = set([chr(x) for x in range(256)])
67
all_chars = {chr(x) for x in range(256)}
66
68
unused_chars = all_chars.symmetric_difference(chars_used)
67
69
self.assertEqual(set('\n'), unused_chars)
236
238
self.assertEqual(("sha1:1234",), node.key())
237
239
self.assertEqual('pref\x00fo', node._search_prefix)
238
240
self.assertEqual({'pref\x00fo\x00': ('sha1:abcd',)}, node._items)
243
class Test_BytesToTextKey(tests.TestCase):
245
def assertBytesToTextKey(self, key, bytes):
246
self.assertEqual(key,
247
self.module._bytes_to_text_key(bytes))
249
def assertBytesToTextKeyRaises(self, bytes):
250
# These are invalid bytes, and we want to make sure the code under test
251
# raises an exception rather than segfaults, etc. We don't particularly
252
# care what exception.
253
self.assertRaises(Exception, self.module._bytes_to_text_key, bytes)
256
self.assertBytesToTextKey(('file-id', 'revision-id'),
257
'file: file-id\nparent-id\nname\nrevision-id\n'
258
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
260
def test_invalid_no_kind(self):
261
self.assertBytesToTextKeyRaises(
262
'file file-id\nparent-id\nname\nrevision-id\n'
263
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
265
def test_invalid_no_space(self):
266
self.assertBytesToTextKeyRaises(
267
'file:file-id\nparent-id\nname\nrevision-id\n'
268
'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
270
def test_invalid_too_short_file_id(self):
271
self.assertBytesToTextKeyRaises('file:file-id')
273
def test_invalid_too_short_parent_id(self):
274
self.assertBytesToTextKeyRaises('file:file-id\nparent-id')
276
def test_invalid_too_short_name(self):
277
self.assertBytesToTextKeyRaises('file:file-id\nparent-id\nname')
280
self.assertBytesToTextKey(('dir-id', 'revision-id'),
281
'dir: dir-id\nparent-id\nname\nrevision-id')