Debian Codegraph @

tests/test-ui-color.py

raw
1 import os
2 from mercurial import (
3 dispatch,
4 main_script,
5 ui as uimod,
6 )
7 from mercurial.utils import stringutil
8
9 # ensure errors aren't buffered
10 testui = uimod.ui()
11 testui.pushbuffer()
12 testui.writenoi18n(b'buffered\n')
13 testui.warnnoi18n(b'warning\n')
14 testui.write_err(b'error\n')
15 print(stringutil.pprint(testui.popbuffer(), bprefix=True).decode('ascii'))
16
17 # test dispatch.dispatch with the same ui object
18 hgrc = open(os.environ["HGRCPATH"], 'wb')
19 hgrc.write(b'[extensions]\n')
20 hgrc.write(b'color=\n')
21 hgrc.close()
22
23 ui_ = uimod.ui.load()
24 ui_.setconfig(b'ui', b'formatted', b'True')
25
26 # we're not interested in the output, so write that to devnull
27 ui_.fout = open(os.devnull, 'wb')
28
29
30 # call some arbitrary command just so we go through
31 # color's wrapped _runcommand twice.
32 def runcmd():
33 dispatch.dispatch(main_script.request([b'version', b'-q'], ui_))
34
35
36 runcmd()
37 print("colored? %s" % (ui_._colormode is not None))
38 runcmd()
39 print("colored? %s" % (ui_._colormode is not None))