~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_generate_ids.py

  • Committer: Martin Packman
  • Date: 2011-12-23 19:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6405.
  • Revision ID: martin.packman@canonical.com-20111223193822-hesheea4o8aqwexv
Accept and document passing the medium rather than transport for smart connections

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for bzrlib/generate_ids.py"""
18
18
 
19
 
import re
20
 
 
21
19
from bzrlib import (
22
20
    generate_ids,
23
21
    tests,
52
50
        self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
53
51
        self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
54
52
 
55
 
        # we remove unicode characters, and still don't end up with a 
 
53
        # we remove unicode characters, and still don't end up with a
56
54
        # hidden file id
57
55
        self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
58
56
 
64
62
        # Test both case squashing and length restriction
65
63
        fid = gen_file_id('A'*50 + '.txt')
66
64
        self.assertStartsWith(fid, 'a'*20 + '-')
67
 
        self.failUnless(len(fid) < 60)
 
65
        self.assertTrue(len(fid) < 60)
68
66
 
69
67
        # restricting length happens after the other actions, so
70
68
        # we preserve as much as possible
71
69
        fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
72
70
        self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
73
 
        self.failUnless(len(fid) < 60)
 
71
        self.assertTrue(len(fid) < 60)
74
72
 
75
73
    def test_file_ids_are_ascii(self):
76
74
        tail = r'-\d{14}-[a-z0-9]{16}-\d+'
112
110
class TestGenRevisionId(tests.TestCase):
113
111
    """Test generating revision ids"""
114
112
 
115
 
    def assertMatchesRe(self, regex, text):
116
 
        """Make sure text is matched by the regex given"""
117
 
        if re.match(regex, text) is None:
118
 
            self.fail('Pattern %s did not match text %s' % (regex, text))
119
 
 
120
113
    def assertGenRevisionId(self, regex, username, timestamp=None):
121
114
        """gen_revision_id should create a revision id matching the regex"""
122
115
        revision_id = generate_ids.gen_revision_id(username, timestamp)
123
 
        self.assertMatchesRe(regex, revision_id)
 
116
        self.assertContainsRe(revision_id, '^'+regex+'$')
124
117
        # It should be a utf8 revision_id, not a unicode one
125
118
        self.assertIsInstance(revision_id, str)
126
119
        # gen_revision_id should always return ascii revision ids.