SciTools/iris — pull request #889 by dkillick (2013-12-17 15:07:45+00:00)
Title: Unicode tests improvements

A follow-on to #875, this is intended to fix the unicode encoding problems in the tests by avoiding encoding the `str()` representation of the given cube to `utf-8` then comparing this to a reference, ostensibly `utf-8` string.

Instead, to replicate how the `str()` representation of Iris cubes should accurately display a given cube in the current system default encoding, the system default encoding is forced to two different but common character sets, namely `utf-8` and `ascii`. The string representation of the given cube in each case is then compared to the relevant reference string.

Forcing the system default encoding suchlike requires access to the method `sys.setdefaultencoding()`, which by default is removed from the `sys` on load. The approach used here (of reloading `sys` within a context manager) emulates the approach as found in the core Python files `libpython.py` or `test_xmlrpc.py`, where this approach is used to overcome similar problems.

Note that this approach currently does not work with either `utf-16` or `utf-32` because [cube.py L1683](https://github.com/SciTools/iris/blob/master/lib/iris/cube.py#L1683) errors when either of these encodings is used.