예제 #1
0
 def make_page(self, width, nentries, include_entry=None):
     if include_entry:
         assert len(include_entry) == width, (include_entry, width)
     entries = [make_page_entry(width) for _ in range(nentries)]
     if include_entry:
         entries += [include_entry]
     for entry in sorted(entries):
         print(entry)
     return SearchPage(b''.join(sorted(entries)),
                       *((18, 0) if width == 18 else (18, 20)))
예제 #2
0
 def test_setitem3(self):
     page = SearchPage(b'abcd', 1, 1)
     page[b'X'] = b'x'
     self.assertEqual(page.data, b'Xxabcd')
예제 #3
0
 def test_setitem21(self):
     page = SearchPage(b'abcdef', 1, 1)
     page[b'd'] = b'x'
     self.assertEqual(page.data, b'abcddxef')
예제 #4
0
 def test_getitem2(self):
     page = SearchPage(b'abcd', 1, 1)
     with self.assertRaises(KeyError):
         x = page[b'd']
     self.assertEqual(page[b'a'], b'b')
예제 #5
0
 def test_delitem5(self):
     page = SearchPage(b'x11y22z33', 1, 2)
     del page[b'z']
     self.assertEqual(page.data, b'x11y22')
예제 #6
0
 def test_delitem2(self):
     page = SearchPage(b'x11', 1, 2)
     del page[b'x']
     self.assertEqual(page.data, b'')
예제 #7
0
 def test_delitem1(self):
     page = SearchPage(b'', 1, 2)
     with self.assertRaises(KeyError):
         del page[b'x']
     self.assertEqual(page.data, b'')
예제 #8
0
 def test_setitem8(self):
     page = SearchPage(b'', 1, 0)
     page[b'X'] = b''
     self.assertEqual(page.data, b'X')
예제 #9
0
 def test_setitem6(self):
     page = SearchPage(b'abcd', 1, 0)
     page[b'e'] = b''
     self.assertEqual(page.data, b'abcde')