tests/test-ui-color.py
changeset 14516 842a9179132c
parent 12865 4c50552fc9bc
child 14614 afccc64eea73
equal deleted inserted replaced
14515:76f295eaed86 14516:842a9179132c
       
     1 import os, sys
     1 from hgext import color
     2 from hgext import color
       
     3 from mercurial import dispatch, ui
     2 
     4 
     3 # ensure errors aren't buffered
     5 # ensure errors aren't buffered
     4 testui = color.colorui()
     6 testui = color.colorui()
     5 testui.pushbuffer()
     7 testui.pushbuffer()
     6 testui.write('buffered\n')
     8 testui.write('buffered\n')
     7 testui.warn('warning\n')
     9 testui.warn('warning\n')
     8 testui.write_err('error\n')
    10 testui.write_err('error\n')
     9 print repr(testui.popbuffer())
    11 print repr(testui.popbuffer())
       
    12 
       
    13 # test dispatch.dispatch with the same ui object
       
    14 hgrc = open(os.environ["HGRCPATH"], 'w')
       
    15 hgrc.write('[extensions]\n')
       
    16 hgrc.write('color=\n')
       
    17 hgrc.close()
       
    18 
       
    19 ui_ = ui.ui()
       
    20 ui_.setconfig('ui', 'formatted', 'True')
       
    21 
       
    22 # call some arbitrary command just so we go through
       
    23 # color's wrapped _runcommand twice.
       
    24 # we're not interested in the output, so write that to devnull
       
    25 def runcmd():
       
    26     sys.stdout = open(os.devnull, 'w')
       
    27     dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
       
    28     sys.stdout = sys.__stdout__
       
    29 
       
    30 runcmd()
       
    31 print "colored? " + str(issubclass(ui_.__class__, color.colorui))
       
    32 runcmd()
       
    33 print "colored? " + str(issubclass(ui_.__class__, color.colorui))