tests/test-ui-color.py
author Pulkit Goyal <pulkit@yandex-team.ru>
Fri, 28 Sep 2018 23:53:09 +0300
changeset 39965 06e75fbf9d6b
parent 37986 32bc3815efae
child 43076 2372284d9457
permissions -rw-r--r--
narrow: check for servers' narrow support before doing anything (BC) Recently we introduced narrow capabilities for the server. So we can check whether a server has narrow clone support or not before doing anything. This is BC because new clients won't be able to extend from old narrow-enabled servers. I *think* narrow is not used much (maybe just inside Google), also it's experimental so I think we can change this. We will need to this someday anyway. The "doesn't" in error is changed to "does not" because I think that's we do in core. I also changed one more instance of the error message to use 'does not' for consistency. Differential Revision: https://phab.mercurial-scm.org/D4789

from __future__ import absolute_import, print_function

import os
from mercurial import (
    dispatch,
    ui as uimod,
)
from mercurial.utils import (
    stringutil,
)

# ensure errors aren't buffered
testui = uimod.ui()
testui.pushbuffer()
testui.write((b'buffered\n'))
testui.warn((b'warning\n'))
testui.write_err(b'error\n')
print(stringutil.pprint(testui.popbuffer(), bprefix=True).decode('ascii'))

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

ui_ = uimod.ui.load()
ui_.setconfig(b'ui', b'formatted', b'True')

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

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

runcmd()
print("colored? %s" % (ui_._colormode is not None))
runcmd()
print("colored? %s" % (ui_._colormode is not None))