67
69
self.assertEqual(expected, actual, 'actual: %r' % (actual,))
69
71
def test_simple_16(self):
70
self.assertSearchKey16('8C736521', ('foo',))
71
self.assertSearchKey16('8C736521\x008C736521', ('foo', 'foo'))
72
self.assertSearchKey16('8C736521\x0076FF8CAA', ('foo', 'bar'))
73
self.assertSearchKey16('ED82CD11', ('abcd',))
72
self.assertSearchKey16('8C736521', stuple('foo',))
73
self.assertSearchKey16('8C736521\x008C736521', stuple('foo', 'foo'))
74
self.assertSearchKey16('8C736521\x0076FF8CAA', stuple('foo', 'bar'))
75
self.assertSearchKey16('ED82CD11', stuple('abcd',))
75
77
def test_simple_255(self):
76
self.assertSearchKey255('\x8cse!', ('foo',))
77
self.assertSearchKey255('\x8cse!\x00\x8cse!', ('foo', 'foo'))
78
self.assertSearchKey255('\x8cse!\x00v\xff\x8c\xaa', ('foo', 'bar'))
78
self.assertSearchKey255('\x8cse!', stuple('foo',))
79
self.assertSearchKey255('\x8cse!\x00\x8cse!', stuple('foo', 'foo'))
80
self.assertSearchKey255('\x8cse!\x00v\xff\x8c\xaa', stuple('foo', 'bar'))
79
81
# The standard mapping for these would include '\n', so it should be
81
self.assertSearchKey255('\xfdm\x93_\x00P_\x1bL', ('<', 'V'))
83
self.assertSearchKey255('\xfdm\x93_\x00P_\x1bL', stuple('<', 'V'))
83
85
def test_255_does_not_include_newline(self):
84
86
# When mapping via _search_key_255, we should never have the '\n'
85
87
# character, but all other 255 values should be present
87
89
for char_in in range(256):
88
search_key = self.module._search_key_255((chr(char_in),))
90
search_key = self.module._search_key_255(stuple(chr(char_in),))
89
91
chars_used.update(search_key)
90
92
all_chars = set([chr(x) for x in range(256)])
91
93
unused_chars = all_chars.symmetric_difference(chars_used)
114
116
def test_deserialise_empty(self):
115
117
node = self.module._deserialise_leaf_node(
116
"chkleaf:\n10\n1\n0\n\n", ("sha1:1234",))
118
"chkleaf:\n10\n1\n0\n\n", stuple("sha1:1234",))
117
119
self.assertEqual(0, len(node))
118
120
self.assertEqual(10, node.maximum_size)
119
121
self.assertEqual(("sha1:1234",), node.key())
122
self.assertIsInstance(node.key(), StaticTuple)
120
123
self.assertIs(None, node._search_prefix)
121
124
self.assertIs(None, node._common_serialised_prefix)
195
198
def assertDeserialiseErrors(self, text):
196
199
self.assertRaises((ValueError, IndexError),
197
self.module._deserialise_internal_node, text, 'not-a-real-sha')
200
self.module._deserialise_internal_node, text,
201
stuple('not-a-real-sha',))
199
203
def test_raises_on_non_internal(self):
200
204
self.assertDeserialiseErrors('')
212
216
def test_deserialise_one(self):
213
217
node = self.module._deserialise_internal_node(
214
"chknode:\n10\n1\n1\n\na\x00sha1:abcd\n", ('sha1:1234',))
218
"chknode:\n10\n1\n1\n\na\x00sha1:abcd\n", stuple('sha1:1234',))
215
219
self.assertIsInstance(node, chk_map.InternalNode)
216
220
self.assertEqual(1, len(node))
217
221
self.assertEqual(10, node.maximum_size)
222
226
def test_deserialise_with_prefix(self):
223
227
node = self.module._deserialise_internal_node(
224
"chknode:\n10\n1\n1\npref\na\x00sha1:abcd\n", ('sha1:1234',))
228
"chknode:\n10\n1\n1\npref\na\x00sha1:abcd\n", stuple('sha1:1234',))
225
229
self.assertIsInstance(node, chk_map.InternalNode)
226
230
self.assertEqual(1, len(node))
227
231
self.assertEqual(10, node.maximum_size)
230
234
self.assertEqual({'prefa': ('sha1:abcd',)}, node._items)
232
236
node = self.module._deserialise_internal_node(
233
"chknode:\n10\n1\n1\npref\n\x00sha1:abcd\n", ('sha1:1234',))
237
"chknode:\n10\n1\n1\npref\n\x00sha1:abcd\n", stuple('sha1:1234',))
234
238
self.assertIsInstance(node, chk_map.InternalNode)
235
239
self.assertEqual(1, len(node))
236
240
self.assertEqual(10, node.maximum_size)
241
245
def test_deserialise_pref_with_null(self):
242
246
node = self.module._deserialise_internal_node(
243
"chknode:\n10\n1\n1\npref\x00fo\n\x00sha1:abcd\n", ('sha1:1234',))
247
"chknode:\n10\n1\n1\npref\x00fo\n\x00sha1:abcd\n",
248
stuple('sha1:1234',))
244
249
self.assertIsInstance(node, chk_map.InternalNode)
245
250
self.assertEqual(1, len(node))
246
251
self.assertEqual(10, node.maximum_size)
251
256
def test_deserialise_with_null_pref(self):
252
257
node = self.module._deserialise_internal_node(
253
"chknode:\n10\n1\n1\npref\x00fo\n\x00\x00sha1:abcd\n", ('sha1:1234',))
258
"chknode:\n10\n1\n1\npref\x00fo\n\x00\x00sha1:abcd\n",
259
stuple('sha1:1234',))
254
260
self.assertIsInstance(node, chk_map.InternalNode)
255
261
self.assertEqual(1, len(node))
256
262
self.assertEqual(10, node.maximum_size)