~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_generate_ids.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-10 17:02:18 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070210170218-6qxxiywltp0uawzw
Add some tests that generate_ids.get_revision_id() generates ascii revision ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
        """gen_revision_id should create a revision id matching the regex"""
103
103
        revision_id = generate_ids.gen_revision_id(username, timestamp)
104
104
        self.assertMatchesRe(regex, revision_id)
 
105
        # It should be a utf8 revision_id, not a unicode one
 
106
        self.assertIsInstance(revision_id, str)
 
107
        # gen_revision_id should always return ascii revision ids.
 
108
        revision_id.decode('ascii')
105
109
 
106
110
    def test_timestamp(self):
107
111
        """passing a timestamp should cause it to be used"""
123
127
    def test_gen_revision_id_user(self):
124
128
        """If there is no email, fall back to the whole username"""
125
129
        tail = r'-\d{14}-[a-z0-9]{16}'
126
 
        self.assertGenRevisionId('joe_bar' + tail,'Joe Bar')
 
130
        self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
127
131
        self.assertGenRevisionId('joebar' + tail, 'joebar')
128
132
        self.assertGenRevisionId('joe_br' + tail, u'Joe B\xe5r')
129
133
        self.assertGenRevisionId(r'joe_br_user\+joe_bar_foo-bar.com' + tail,
130
134
                                 u'Joe B\xe5r <user+Joe_Bar_Foo-Bar.com>')
 
135
 
 
136
    def test_revision_ids_are_ascii(self):
 
137
        """gen_revision_id should always return an ascii revision id."""
 
138
        tail = r'-\d{14}-[a-z0-9]{16}'
 
139
        self.assertGenRevisionId('joe_bar' + tail, 'Joe Bar')
 
140
        self.assertGenRevisionId('joe_bar' + tail, u'Joe Bar')
 
141
        self.assertGenRevisionId('joe@foo' + tail, u'Joe Bar <joe@foo>')
 
142
        # We cheat a little with this one, because email-addresses shouldn't
 
143
        # contain non-ascii characters, but generate_ids should strip them
 
144
        # anyway.
 
145
        self.assertGenRevisionId('joe@f' + tail, u'Joe Bar <joe@f\xb6>')