Index: doctest.py =================================================================== --- doctest.py (revision 61049) +++ doctest.py (working copy) @@ -1079,7 +1079,8 @@ # separate sections of the summary. DIVIDER = "*" * 70 - def __init__(self, checker=None, verbose=None, optionflags=0): + def __init__(self, checker=None, verbose=None, optionflags=0, + encoding=None): """ Create a new test runner. @@ -1102,6 +1103,7 @@ self._verbose = verbose self.optionflags = optionflags self.original_optionflags = optionflags + self._encoding = encoding # Keep track of the examples we've run. self.tries = 0 @@ -1121,11 +1123,17 @@ example. (Only displays a message if verbose=True) """ if self._verbose: - if example.want: - out('Trying:\n' + _indent(example.source) + - 'Expecting:\n' + _indent(example.want)) + source = example.source + want = example.want + if self._encoding: + source = example.source.encode(self._encoding) + if example.want: + want = example.want.encode(self._encoding) + if want: + out('Trying:\n' + _indent(source) + + 'Expecting:\n' + _indent(want)) else: - out('Trying:\n' + _indent(example.source) + + out('Trying:\n' + _indent(source) + 'Expecting nothing\n') def report_success(self, out, test, example, got): @@ -1162,7 +1170,10 @@ else: out.append('Line %s, in %s' % (example.lineno+1, test.name)) out.append('Failed example:') - source = example.source + if self._encoding: + source = example.source.encode(self._encoding) + else: + source = example.source out.append(_indent(source)) return '\n'.join(out) @@ -1929,9 +1940,11 @@ globs.update(extraglobs) if raise_on_error: - runner = DebugRunner(verbose=verbose, optionflags=optionflags) + runner = DebugRunner(verbose=verbose, optionflags=optionflags, + encoding=encoding) else: - runner = DocTestRunner(verbose=verbose, optionflags=optionflags) + runner = DocTestRunner(verbose=verbose, optionflags=optionflags, + encoding=encoding) if encoding is not None: text = text.decode(encoding)