Merge lp:~frankban/testrepository/encoding-error into lp:~testrepository/testrepository/trunk
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Merged at revision: | 146 | ||||
| Proposed branch: | lp:~frankban/testrepository/encoding-error | ||||
| Merge into: | lp:~testrepository/testrepository/trunk | ||||
| Diff against target: |
62 lines (+17/-4) 2 files modified
testrepository/tests/ui/test_cli.py (+12/-1) testrepository/ui/cli.py (+5/-3) |
||||
| To merge this branch: | bzr merge lp:~frankban/testrepository/encoding-error | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Jonathan Lange | 2012-03-19 | Approve on 2012-04-02 | |
| Martin Packman (community) | 2012-03-21 | Approve on 2012-03-21 | |
|
Review via email:
|
|||
Description of the Change
== Changes ==
Updated CLITestResult.
== Tests ==
$ make check
./testr run --parallel
running=
running=
running=
running=
running=
running=
running=
running=
running=
Ran 264 tests in 1.591s (-0.220s)
PASSED (id=32)
- 148. By Francesco Banconi on 2012-03-19
-
New revision
- 149. By Francesco Banconi on 2012-03-20
-
New revision.
| Jonathan Lange (jml) wrote : | # |
| Martin Packman (gz) wrote : | # |
Two small suggestions for simplification:
* Rather than manually encoding in _format_error, you could wrap the stream instead. There's a helper in testtools.compat called unicode_
def __init__(self, ui, get_id, stream, previous_run=None):
- self.stream = stream
+ self.stream = unicode_
self.sep1 = u'=' * 70 + '\n'
self.sep2 = u'-' * 70 + '\n'
* The test looks more complicated than it really deserves. As the StringIO doesn't have an encoding attribute, it just expects the bytes replaced with question marks in the output, all you need to assert that is:
+ error = (ValueError, ValueError("\xa7"), None)
+ result.
+ self.assertThat(
+ stream.getvalue(),
+ DocTestMatches(
The only complication is how the bytes get decoded depends on the locale the test in run in, to avoid that you could use an exception class that defined __unicode__ and returns something consistent.
- 150. By Francesco Banconi on 2012-03-29
-
Changes suggested in review.
| Francesco Banconi (frankban) wrote : | # |
Thank you Jonathan and Martin for your suggestions.
I didn't know about the unicode_
I've added a revision following suggestions in Martin's review. However, I'm a bit confused about the locale issue.
As you said, we are using a cStringIO object as stream, and, so I'd expect the output to be just encoded using 'ascii' and 'replace', so maybe I am missing something.
| Jonathan Lange (jml) wrote : | # |
Presumably there exists a locale where \xa7 will be decoded correctly without needing to fall back to using the replacement character. In those locales, this test will fail.
Here's something that's a bit more robust:
=== modified file 'testrepository
--- testrepository/
+++ testrepository/
@@ -282,8 +282,11 @@ class TestCLITestResu
# characters.
stream = StringIO()
result = self.make_
- error = (ValueError, ValueError('\xa7'), None)
+ class MyError(
+ def __unicode__(self):
+ return u'\u201c'
+ error = (MyError, MyError(), None)
- DocTestMatches(
+ DocTestMatches(
I've applied this to your branch, and am about to merge it into trunk.
Thanks so much for your contribution.
jml

Hello Francesco,
Thanks for the patch!
I've asked mgz to sanity check the unicode side of this patch, since he understands the many subtle gotchas that can, umm, get you.
Code-wise, I'm not a huge fan of using the short-circuiting properties of 'or', so I'll tweak that before landing.
Also, for future reference, testrepository doesn't require you to use any particular template for submitting merge proposals. In general, we'd (well, I'd) prefer descriptive text that explains what you're changing, why and that highlights any interesting implementation details or areas for particularly close review.
jml