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