Merge lp:~gagern/bzr/encodingSafeTests into lp:bzr
Status: | Work in progress |
---|---|
Proposed branch: | lp:~gagern/bzr/encodingSafeTests |
Merge into: | lp:bzr |
Diff against target: |
142 lines (+79/-11) 2 files modified
bzrlib/tests/__init__.py (+29/-11) bzrlib/tests/test_selftest.py (+50/-0) |
To merge this branch: | bzr merge lp:~gagern/bzr/encodingSafeTests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman (community) | Abstain | ||
Andrew Bennetts | Needs Fixing | ||
Review via email: mp+23925@code.launchpad.net |
Description of the change
Ensure tests won't cause the whole selftest to abort even if UnicodeErrors occur when formatting some test result.
I had proposed this in 2008: http://
Back then, John Arbash Meinel and Martin Pool had approved it, but Martin Pool later voted resubmit, as the feature failed its own test cases.
I've updated it to current bzr.dev, and selftests work for me now. Do you want this patch?
Unmerged revisions
- 3530. By Martin von Gagern
-
Fix broken newline unescaping.
In order to show useful diffs, and readable output in general, newlines
should not be escaped. The unescaping done before was broken if r'\n'
appeared in the input, as Andrew Bennetts reviewed. In order to avoid using
regular expressions, we now split lines and join them after escaping. Added
a test case as well, and a new test class for toplevel functions in tests. - 3529. By Martin von Gagern
-
Merge from trunk, with lots of adjustments.
This branch has been lying around for quite a while, so there has been a
number of changes to incorporate. Therefore this merge has a large edit
component to it. - 3528. By Martin von Gagern
-
Added tests for tests._safe_string.
- 3527. By Martin von Gagern
-
More robust handling of encoding issues in tests.
Problems with encoding errors could lead to not only single tests
failing but the whole selftest process crashing. The introduction of
safe strings as a fallback in case of trouble avoids most of these
problems. The safe strings try to maintain as much information as
possible while using only ASCII characters. This is achieved by
formatting the strings using escape sequences.This modification only changes how certain test results are displayed
to the user. There is no change to the semantics of these tests, so a
test that used to fail before will still continue to fail. Hopefully if
it does fail it is more likely that the test suite will continue with
the next test and not abort due to some exception displaying the error.
+ return string_ or_unicode. encode( 'string_ escape' ).replace( r'\n', '\n')
This mangles the output:
>>> x = r'backslash n, not newline: \n' 'string_ escape' ).replace( r'\n', '\n') 'string_ escape' ).replace( r'\n', '\n')
>>> x.encode(
'backslash n, not newline: \\\n'
>>> '\n' in x
False
>>> '\n' in x.encode(
True
Otherwise this seems ok. When UnicodeErrors occur you _safe_str all variable that might be involved, which is perhaps too zealous. But it's undoubtedly better than allowing the UnicodeError to abort selftest.