~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_generate_ids.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
class TestFileIds(tests.TestCase):
28
28
    """Test functions which generate file ids"""
29
 
 
30
 
    def assertGenFileId(self, regex, filename):
31
 
        """gen_file_id should create a file id matching the regex.
32
 
 
33
 
        The file id should be ascii, and should be an 8-bit string
34
 
        """
35
 
        file_id = generate_ids.gen_file_id(filename)
36
 
        self.assertContainsRe(file_id, '^'+regex+'$')
37
 
        # It should be a utf8 file_id, not a unicode one
38
 
        self.assertIsInstance(file_id, str)
39
 
        # gen_file_id should always return ascii file ids.
40
 
        file_id.decode('ascii')
41
 
 
 
29
    
42
30
    def test_gen_file_id(self):
43
31
        gen_file_id = generate_ids.gen_file_id
44
32
 
55
43
        # we remove unicode characters, and still don't end up with a 
56
44
        # hidden file id
57
45
        self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
58
 
 
 
46
        
59
47
        # Our current method of generating unique ids adds 33 characters
60
48
        # plus an serial number (log10(N) characters)
61
49
        # to the end of the filename. We now restrict the filename portion to
72
60
        self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
73
61
        self.failUnless(len(fid) < 60)
74
62
 
75
 
    def test_file_ids_are_ascii(self):
76
 
        tail = r'-\d{14}-[a-z0-9]{16}-\d+'
77
 
        self.assertGenFileId('foo' + tail, 'foo')
78
 
        self.assertGenFileId('foo' + tail, u'foo')
79
 
        self.assertGenFileId('bar' + tail, u'bar')
80
 
        self.assertGenFileId('br' + tail, u'b\xe5r')
81
 
 
82
63
    def test__next_id_suffix_sets_suffix(self):
83
64
        generate_ids._gen_file_id_suffix = None
84
65
        generate_ids._next_id_suffix()
112
93
class TestGenRevisionId(tests.TestCase):
113
94
    """Test generating revision ids"""
114
95
 
 
96
    def assertMatchesRe(self, regex, text):
 
97
        """Make sure text is matched by the regex given"""
 
98
        if re.match(regex, text) is None:
 
99
            self.fail('Pattern %s did not match text %s' % (regex, text))
 
100
 
115
101
    def assertGenRevisionId(self, regex, username, timestamp=None):
116
102
        """gen_revision_id should create a revision id matching the regex"""
117
103
        revision_id = generate_ids.gen_revision_id(username, timestamp)
118
 
        self.assertContainsRe(revision_id, '^'+regex+'$')
119
 
        # It should be a utf8 revision_id, not a unicode one
120
 
        self.assertIsInstance(revision_id, str)
121
 
        # gen_revision_id should always return ascii revision ids.
122
 
        revision_id.decode('ascii')
 
104
        self.assertMatchesRe(regex, revision_id)
123
105
 
124
106
    def test_timestamp(self):
125
107
        """passing a timestamp should cause it to be used"""
141
123
    def test_gen_revision_id_user(self):
142
124
        """If there is no email, fall back to the whole username"""
143
125
        tail = r'-\d{14}-[a-z0-9]{16}'
144
 
        self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
 
126
        self.assertGenRevisionId('joe_bar' + tail,'Joe Bar')
145
127
        self.assertGenRevisionId('joebar' + tail, 'joebar')
146
128
        self.assertGenRevisionId('joe_br' + tail, u'Joe B\xe5r')
147
129
        self.assertGenRevisionId(r'joe_br_user\+joe_bar_foo-bar.com' + tail,
148
130
                                 u'Joe B\xe5r <user+Joe_Bar_Foo-Bar.com>')
149
 
 
150
 
    def test_revision_ids_are_ascii(self):
151
 
        """gen_revision_id should always return an ascii revision id."""
152
 
        tail = r'-\d{14}-[a-z0-9]{16}'
153
 
        self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
154
 
        self.assertGenRevisionId('joe_bar' + tail, u'Joe Bar')
155
 
        self.assertGenRevisionId('joe@foo' + tail, u'Joe Bar <joe@foo>')
156
 
        # We cheat a little with this one, because email-addresses shouldn't
157
 
        # contain non-ascii characters, but generate_ids should strip them
158
 
        # anyway.
159
 
        self.assertGenRevisionId('joe@f' + tail, u'Joe Bar <joe@f\xb6>')