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

  • Committer: Jelmer Vernooij
  • Date: 2018-08-08 02:14:32 UTC
  • mfrom: (7063 work)
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180808021432-nomib3je4cu2xqkm
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
        file_id = generate_ids.gen_file_id(filename)
34
34
        self.assertContainsRe(file_id, b'^'+regex+b'$')
35
35
        # It should be a utf8 file_id, not a unicode one
36
 
        self.assertIsInstance(file_id, str)
 
36
        self.assertIsInstance(file_id, bytes)
37
37
        # gen_file_id should always return ascii file ids.
38
38
        file_id.decode('ascii')
39
39
 
41
41
        gen_file_id = generate_ids.gen_file_id
42
42
 
43
43
        # We try to use the filename if possible
44
 
        self.assertStartsWith(gen_file_id(b'bar'), b'bar-')
 
44
        self.assertStartsWith(gen_file_id('bar'), b'bar-')
45
45
 
46
46
        # but we squash capitalization, and remove non word characters
47
 
        self.assertStartsWith(gen_file_id(b'Mwoo oof\t m'), b'mwoooofm-')
 
47
        self.assertStartsWith(gen_file_id('Mwoo oof\t m'), b'mwoooofm-')
48
48
 
49
49
        # We also remove leading '.' characters to prevent hidden file-ids
50
 
        self.assertStartsWith(gen_file_id(b'..gam.py'), b'gam.py-')
51
 
        self.assertStartsWith(gen_file_id(b'..Mwoo oof\t m'), b'mwoooofm-')
 
50
        self.assertStartsWith(gen_file_id('..gam.py'), b'gam.py-')
 
51
        self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), b'mwoooofm-')
52
52
 
53
53
        # we remove unicode characters, and still don't end up with a
54
54
        # hidden file id
61
61
 
62
62
        # Test both case squashing and length restriction
63
63
        fid = gen_file_id('A'*50 + '.txt')
64
 
        self.assertStartsWith(fid, 'a'*20 + '-')
 
64
        self.assertStartsWith(fid, b'a'*20 + b'-')
65
65
        self.assertTrue(len(fid) < 60)
66
66
 
67
67
        # restricting length happens after the other actions, so
68
68
        # we preserve as much as possible
69
69
        fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
70
 
        self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
 
70
        self.assertStartsWith(fid, b'abcdefghijklmnopqrst-')
71
71
        self.assertTrue(len(fid) < 60)
72
72
 
73
73
    def test_file_ids_are_ascii(self):
74
74
        tail = br'-\d{14}-[a-z0-9]{16}-\d+'
75
 
        self.assertGenFileId(b'foo' + tail, b'foo')
 
75
        self.assertGenFileId(b'foo' + tail, 'foo')
76
76
        self.assertGenFileId(b'foo' + tail, u'foo')
77
77
        self.assertGenFileId(b'bar' + tail, u'bar')
78
78
        self.assertGenFileId(b'br' + tail, u'b\xe5r')