Mercurial > hg
comparison mercurial/formatter.py @ 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 | 0fa781320203 |
children | ebe3d0095c69 |
comparison
equal
deleted
inserted
replaced
34254:cd022a11ec83 | 34255:d6af8da4a3b8 |
---|---|
43 | 43 |
44 >>> def show(fn, verbose=False, **opts): | 44 >>> def show(fn, verbose=False, **opts): |
45 ... import sys | 45 ... import sys |
46 ... from . import ui as uimod | 46 ... from . import ui as uimod |
47 ... ui = uimod.ui() | 47 ... ui = uimod.ui() |
48 ... ui.fout = sys.stdout # redirect to doctest | |
49 ... ui.verbose = verbose | 48 ... ui.verbose = verbose |
50 ... return fn(ui, ui.formatter(fn.__name__, opts)) | 49 ... ui.pushbuffer() |
50 ... try: | |
51 ... return fn(ui, ui.formatter(fn.__name__, opts)) | |
52 ... finally: | |
53 ... print(pycompat.sysstr(ui.popbuffer()), end='') | |
51 | 54 |
52 Basic example: | 55 Basic example: |
53 | 56 |
54 >>> def files(ui, fm): | 57 >>> def files(ui, fm): |
55 ... files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))] | 58 ... files = [(b'foo', 123, (0, 0)), (b'bar', 456, (1, 0))] |
99 bar | 102 bar |
100 >>> show(subrepos, template=b'{repo}: {join(files % "{path}", ", ")}\\n') | 103 >>> show(subrepos, template=b'{repo}: {join(files % "{path}", ", ")}\\n') |
101 baz: foo, bar | 104 baz: foo, bar |
102 """ | 105 """ |
103 | 106 |
104 from __future__ import absolute_import | 107 from __future__ import absolute_import, print_function |
105 | 108 |
106 import collections | 109 import collections |
107 import contextlib | 110 import contextlib |
108 import itertools | 111 import itertools |
109 import os | 112 import os |