changeset 34255:d6af8da4a3b8

py3: rewrite stdout hack of doctest by using ui.pushbuffer() We can't use pycompat.stdout here because the doctest runner replaces sys.stdout with a string buffer.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 17 Sep 2017 12:39:14 +0900
parents cd022a11ec83
children ebe3d0095c69
files mercurial/formatter.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/formatter.py	Sun Sep 17 12:26:42 2017 +0900
+++ b/mercurial/formatter.py	Sun Sep 17 12:39:14 2017 +0900
@@ -45,9 +45,12 @@
 ...     import sys
 ...     from . import ui as uimod
 ...     ui = uimod.ui()
-...     ui.fout = sys.stdout  # redirect to doctest
 ...     ui.verbose = verbose
-...     return fn(ui, ui.formatter(fn.__name__, opts))
+...     ui.pushbuffer()
+...     try:
+...         return fn(ui, ui.formatter(fn.__name__, opts))
+...     finally:
+...         print(pycompat.sysstr(ui.popbuffer()), end='')
 
 Basic example:
 
@@ -101,7 +104,7 @@
 baz: foo, bar
 """
 
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 
 import collections
 import contextlib