tests/test-ui-color.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 01 Feb 2016 22:14:06 +0900
branchstable
changeset 27960 0ec12435b78b
parent 19322 ff1586a3adc5
child 28682 2e5be704bc96
permissions -rw-r--r--
doc: itemize text blocks to increase readability in HTML format Before this patch, text blocks changed in this patch are shown as just continuous text blocks like below in HTML format. Global configuration like the username setting is typically put into: %USERPROFILE%\mercurial.ini $HOME/.hgrc This patch itemizes these text blocks to increase readability in HTML format. Global configuration like the username setting is typically put into: - %USERPROFILE%\mercurial.ini (on Windows) - $HOME/.hgrc (on Unix, Plan9) Like as other platform sensitive container-ed text blocks, this patch also adds explicit "on PLATFORM" information to each items for readability in HTML format, even though output of "hg help config" on command line seems a little redundant. For example, on Unix: Global configuration like the username setting is typically put into: - "$HOME/.hgrc" (on Unix, Plan9)

import os
from hgext import color
from mercurial import dispatch, ui

# ensure errors aren't buffered
testui = color.colorui()
testui.pushbuffer()
testui.write(('buffered\n'))
testui.warn(('warning\n'))
testui.write_err('error\n')
print repr(testui.popbuffer())

# test dispatch.dispatch with the same ui object
hgrc = open(os.environ["HGRCPATH"], 'w')
hgrc.write('[extensions]\n')
hgrc.write('color=\n')
hgrc.close()

ui_ = ui.ui()
ui_.setconfig('ui', 'formatted', 'True')

# we're not interested in the output, so write that to devnull
ui_.fout = open(os.devnull, 'w')

# call some arbitrary command just so we go through
# color's wrapped _runcommand twice.
def runcmd():
    dispatch.dispatch(dispatch.request(['version', '-q'], ui_))

runcmd()
print "colored? " + str(issubclass(ui_.__class__, color.colorui))
runcmd()
print "colored? " + str(issubclass(ui_.__class__, color.colorui))