|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | # test_commit.py |
2 | 3 | # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors |
3 | 4 | # |
@@ -108,6 +109,14 @@ def check_entries(d): |
108 | 109 | assert commit.committer_tz_offset == 14400, commit.committer_tz_offset |
109 | 110 | assert commit.message == "initial project\n" |
110 | 111 |
|
| 112 | + def test_unicode_actor(self): |
| 113 | + # assure we can parse unicode actors correctly |
| 114 | + name = "Üäöß ÄußÉ".decode("utf-8") |
| 115 | + assert len(name) == 9 |
| 116 | + special = Actor._from_string(u"%s <something@this.com>" % name) |
| 117 | + assert special.name == name |
| 118 | + assert isinstance(special.name, unicode) |
| 119 | + |
111 | 120 | def test_traversal(self): |
112 | 121 | start = self.rorepo.commit("a4d06724202afccd2b5c54f81bcf2bf26dea7fff") |
113 | 122 | first = self.rorepo.commit("33ebe7acec14b25c5f84f35a664803fcab2f7781") |
@@ -233,3 +242,32 @@ def test_serialization(self, rwrepo): |
233 | 242 | # create all commits of our repo |
234 | 243 | assert_commit_serialization(rwrepo, '0.1.6') |
235 | 244 |
|
| 245 | + def test_serialization_unicode_support(self): |
| 246 | + assert Commit.default_encoding.lower() == 'utf-8' |
| 247 | + |
| 248 | + # create a commit with unicode in the message, and the author's name |
| 249 | + # Verify its serialization and deserialization |
| 250 | + cmt = self.rorepo.commit('0.1.6') |
| 251 | + assert isinstance(cmt.message, unicode) # it automatically decodes it as such |
| 252 | + assert isinstance(cmt.author.name, unicode) # same here |
| 253 | + |
| 254 | + cmt.message = "üäêèß".decode("utf-8") |
| 255 | + assert len(cmt.message) == 5 |
| 256 | + |
| 257 | + cmt.author.name = "äüß".decode("utf-8") |
| 258 | + assert len(cmt.author.name) == 3 |
| 259 | + |
| 260 | + cstream = StringIO() |
| 261 | + cmt._serialize(cstream) |
| 262 | + cstream.seek(0) |
| 263 | + assert len(cstream.getvalue()) |
| 264 | + |
| 265 | + ncmt = Commit(self.rorepo, cmt.binsha) |
| 266 | + ncmt._deserialize(cstream) |
| 267 | + |
| 268 | + assert cmt.author.name == ncmt.author.name |
| 269 | + assert cmt.message == ncmt.message |
| 270 | + # actually, it can't be printed in a shell as repr wants to have ascii only |
| 271 | + # it appears |
| 272 | + cmt.author.__repr__() |
| 273 | + |
0 commit comments