comparison tests/test-ui-color.py @ 14516:842a9179132c

color: check if ui is already a subclass of colorui before wrapping it since it's possible to reuse the ui object (see 80c599eee3f3) between dispatch calls, the ui might have been wrapped already. we could probably move this test up a bit but leaving it here allows updates to take effect by extstyles() and configstyles().
author Idan Kamara <idankk86@gmail.com>
date Thu, 02 Jun 2011 00:43:34 +0300
parents 4c50552fc9bc
children afccc64eea73
comparison
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))