/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-11-16 19:47:19 UTC
  • mfrom: (7178 work)
  • mto: This revision was merged to the branch mainline in revision 7179.
  • Revision ID: jelmer@jelmer.uk-20181116194719-m5ut2wfuze5x9s1p
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        The file id should be ascii, and should be an 8-bit string
32
32
        """
33
33
        file_id = generate_ids.gen_file_id(filename)
34
 
        self.assertContainsRe(file_id, b'^'+regex+b'$')
 
34
        self.assertContainsRe(file_id, b'^' + regex + b'$')
35
35
        # It should be a utf8 file_id, not a unicode one
36
36
        self.assertIsInstance(file_id, bytes)
37
37
        # gen_file_id should always return ascii file ids.
60
60
        # be <= 20 characters, so the maximum length should now be approx < 60
61
61
 
62
62
        # Test both case squashing and length restriction
63
 
        fid = gen_file_id('A'*50 + '.txt')
64
 
        self.assertStartsWith(fid, b'a'*20 + b'-')
 
63
        fid = gen_file_id('A' * 50 + '.txt')
 
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
113
113
    def assertGenRevisionId(self, regex, username, timestamp=None):
114
114
        """gen_revision_id should create a revision id matching the regex"""
115
115
        revision_id = generate_ids.gen_revision_id(username, timestamp)
116
 
        self.assertContainsRe(revision_id, b'^'+regex+b'$')
 
116
        self.assertContainsRe(revision_id, b'^' + regex + b'$')
117
117
        # It should be a utf8 revision_id, not a unicode one
118
118
        self.assertIsInstance(revision_id, bytes)
119
119
        # gen_revision_id should always return ascii revision ids.
121
121
 
122
122
    def test_timestamp(self):
123
123
        """passing a timestamp should cause it to be used"""
124
 
        self.assertGenRevisionId(br'user@host-\d{14}-[a-z0-9]{16}', 'user@host')
 
124
        self.assertGenRevisionId(
 
125
            br'user@host-\d{14}-[a-z0-9]{16}', 'user@host')
125
126
        self.assertGenRevisionId(b'user@host-20061102205056-[a-z0-9]{16}',
126
127
                                 'user@host', 1162500656.688)
127
128
        self.assertGenRevisionId(br'user@host-20061102205024-[a-z0-9]{16}',
134
135
        self.assertGenRevisionId(regex, '<user+joe_bar@foo-bar.com>')
135
136
        self.assertGenRevisionId(regex, 'Joe Bar <user+joe_bar@foo-bar.com>')
136
137
        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>')
 
138
        self.assertGenRevisionId(
 
139
            regex, u'Joe B\xe5r <user+Joe_Bar@Foo-Bar.com>')
138
140
 
139
141
    def test_gen_revision_id_user(self):
140
142
        """If there is no email, fall back to the whole username"""