/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 breezy/tests/test__chk_map.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 12:50:32 UTC
  • mfrom: (6679 work)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610125032-xb5rd5fjskjallos
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
2
2
#
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
16
16
 
17
17
"""Tests for _chk_map_*."""
18
18
 
19
 
from bzrlib import (
 
19
from .. import (
 
20
    tests,
 
21
    )
 
22
from ..bzr import (
20
23
    chk_map,
21
 
    tests,
22
24
    )
23
 
from bzrlib.static_tuple import StaticTuple
 
25
from ..static_tuple import StaticTuple
24
26
stuple = StaticTuple
25
27
 
26
28
 
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')
30
32
    return suite
31
33
 
32
34
 
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)
68
70
 
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)
 
241
 
 
242
 
 
243
class Test_BytesToTextKey(tests.TestCase):
 
244
 
 
245
    def assertBytesToTextKey(self, key, bytes):
 
246
        self.assertEqual(key,
 
247
                         self.module._bytes_to_text_key(bytes))
 
248
 
 
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)
 
254
 
 
255
    def test_file(self):
 
256
        self.assertBytesToTextKey(('file-id', 'revision-id'),
 
257
                 'file: file-id\nparent-id\nname\nrevision-id\n'
 
258
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
259
 
 
260
    def test_invalid_no_kind(self):
 
261
        self.assertBytesToTextKeyRaises(
 
262
                 'file  file-id\nparent-id\nname\nrevision-id\n'
 
263
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
264
 
 
265
    def test_invalid_no_space(self):
 
266
        self.assertBytesToTextKeyRaises(
 
267
                 'file:file-id\nparent-id\nname\nrevision-id\n'
 
268
                 'da39a3ee5e6b4b0d3255bfef95601890afd80709\n100\nN')
 
269
 
 
270
    def test_invalid_too_short_file_id(self):
 
271
        self.assertBytesToTextKeyRaises('file:file-id')
 
272
 
 
273
    def test_invalid_too_short_parent_id(self):
 
274
        self.assertBytesToTextKeyRaises('file:file-id\nparent-id')
 
275
 
 
276
    def test_invalid_too_short_name(self):
 
277
        self.assertBytesToTextKeyRaises('file:file-id\nparent-id\nname')
 
278
 
 
279
    def test_dir(self):
 
280
        self.assertBytesToTextKey(('dir-id', 'revision-id'),
 
281
                 'dir: dir-id\nparent-id\nname\nrevision-id')