/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: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for breezy/generate_ids.py"""
18
18
 
19
19
from .. import (
 
20
    tests,
 
21
    )
 
22
from ..bzr import (
20
23
    generate_ids,
21
 
    tests,
22
24
    )
23
25
 
24
26
 
31
33
        The file id should be ascii, and should be an 8-bit string
32
34
        """
33
35
        file_id = generate_ids.gen_file_id(filename)
34
 
        self.assertContainsRe(file_id, b'^'+regex+b'$')
 
36
        self.assertContainsRe(file_id, b'^' + regex + b'$')
35
37
        # It should be a utf8 file_id, not a unicode one
36
38
        self.assertIsInstance(file_id, bytes)
37
39
        # gen_file_id should always return ascii file ids.
60
62
        # be <= 20 characters, so the maximum length should now be approx < 60
61
63
 
62
64
        # Test both case squashing and length restriction
63
 
        fid = gen_file_id('A'*50 + '.txt')
64
 
        self.assertStartsWith(fid, b'a'*20 + b'-')
 
65
        fid = gen_file_id('A' * 50 + '.txt')
 
66
        self.assertStartsWith(fid, b'a' * 20 + b'-')
65
67
        self.assertTrue(len(fid) < 60)
66
68
 
67
69
        # restricting length happens after the other actions, so
113
115
    def assertGenRevisionId(self, regex, username, timestamp=None):
114
116
        """gen_revision_id should create a revision id matching the regex"""
115
117
        revision_id = generate_ids.gen_revision_id(username, timestamp)
116
 
        self.assertContainsRe(revision_id, b'^'+regex+b'$')
 
118
        self.assertContainsRe(revision_id, b'^' + regex + b'$')
117
119
        # It should be a utf8 revision_id, not a unicode one
118
120
        self.assertIsInstance(revision_id, bytes)
119
121
        # gen_revision_id should always return ascii revision ids.
121
123
 
122
124
    def test_timestamp(self):
123
125
        """passing a timestamp should cause it to be used"""
124
 
        self.assertGenRevisionId(br'user@host-\d{14}-[a-z0-9]{16}', 'user@host')
 
126
        self.assertGenRevisionId(
 
127
            br'user@host-\d{14}-[a-z0-9]{16}', 'user@host')
125
128
        self.assertGenRevisionId(b'user@host-20061102205056-[a-z0-9]{16}',
126
129
                                 'user@host', 1162500656.688)
127
130
        self.assertGenRevisionId(br'user@host-20061102205024-[a-z0-9]{16}',
134
137
        self.assertGenRevisionId(regex, '<user+joe_bar@foo-bar.com>')
135
138
        self.assertGenRevisionId(regex, 'Joe Bar <user+joe_bar@foo-bar.com>')
136
139
        self.assertGenRevisionId(regex, 'Joe Bar <user+Joe_Bar@Foo-Bar.com>')
137
 
        self.assertGenRevisionId(regex, u'Joe B\xe5r <user+Joe_Bar@Foo-Bar.com>')
 
140
        self.assertGenRevisionId(
 
141
            regex, u'Joe B\xe5r <user+Joe_Bar@Foo-Bar.com>')
138
142
 
139
143
    def test_gen_revision_id_user(self):
140
144
        """If there is no email, fall back to the whole username"""