test-ui-color.py
39 lines
| 1011 B
| text/x-python
|
PythonLexer
/ tests / test-ui-color.py
|
r28915 | from __future__ import absolute_import, print_function | ||
|
r19322 | import os | ||
|
r28915 | from mercurial import ( | ||
dispatch, | ||||
ui as uimod, | ||||
) | ||||
|
r43346 | from mercurial.utils import stringutil | ||
|
r11732 | |||
# ensure errors aren't buffered | ||||
|
r31095 | testui = uimod.ui() | ||
|
r11732 | testui.pushbuffer() | ||
|
r43346 | testui.write(b'buffered\n') | ||
testui.warn(b'warning\n') | ||||
|
r36354 | testui.write_err(b'error\n') | ||
|
r37961 | print(stringutil.pprint(testui.popbuffer(), bprefix=True).decode('ascii')) | ||
|
r14516 | |||
# test dispatch.dispatch with the same ui object | ||||
|
r36355 | hgrc = open(os.environ["HGRCPATH"], 'wb') | ||
|
r36354 | hgrc.write(b'[extensions]\n') | ||
hgrc.write(b'color=\n') | ||||
|
r14516 | hgrc.close() | ||
|
r30559 | ui_ = uimod.ui.load() | ||
|
r36354 | ui_.setconfig(b'ui', b'formatted', b'True') | ||
|
r14516 | |||
|
r14614 | # we're not interested in the output, so write that to devnull | ||
|
r36355 | ui_.fout = open(os.devnull, 'wb') | ||
|
r14614 | |||
|
r14516 | # call some arbitrary command just so we go through | ||
# color's wrapped _runcommand twice. | ||||
def runcmd(): | ||||
|
r36354 | dispatch.dispatch(dispatch.request([b'version', b'-q'], ui_)) | ||
|
r14516 | |||
|
r43346 | |||
|
r14516 | runcmd() | ||
|
r31095 | print("colored? %s" % (ui_._colormode is not None)) | ||
|
r14516 | runcmd() | ||
|
r31095 | print("colored? %s" % (ui_._colormode is not None)) | ||