edx/diff-cover — pull request #83 by wedaly (2014-05-18 17:38:09+00:00)
Title: Unicode Fixes (Python 2.7)

Recent efforts to make diff-cover work in Python 3 have introduced stricter unicode checks. This has revealed a few places were diff-cover was not properly converting byte-string inputs to unicode, causing runtime exceptions.

This PR is an attempt to fix the runtime errors in Python 2.7. The basic approach is:

1) Decode input (from git diff and loaded source files) immediately to unicode, then assume unicode internally. If characters cannot be decoded, use 'replace' error handling rather than throwing an exception.
2) Encode outputs to byte-strings when generating reports.

Some limitations of this approach:

* No attempt to infer the encoding of source files or git diff -- always assume UTF-8. This could lead to (a) not being able to find source files reported by git diff, or (b) mangled source file snippets. If this gets merged, I'll open GitHub issues to track these.

* Some ugly conditionals for checking whether we're in Python 2 or Python 3. Python 3 doesn't support `decode` for the `str` type, and I'm not familiar enough with Python 3 to know the correct way to handle this.

Although not perfect, this approach will at least prevent some of the runtime errors in Python 2.7 introduced in the last release.

@nedbat Does this seem like a reasonable short-term fix?