PageRenderTime 72ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/test-ui-color.py

https://bitbucket.org/mirror/mercurial/
Python | 33 lines | 22 code | 6 blank | 5 comment | 0 complexity | d740761311fbc3a9f627df3d48d8807b MD5 | raw file
Possible License(s): GPL-2.0
  1. import os
  2. from hgext import color
  3. from mercurial import dispatch, ui
  4. # ensure errors aren't buffered
  5. testui = color.colorui()
  6. testui.pushbuffer()
  7. testui.write(('buffered\n'))
  8. testui.warn(('warning\n'))
  9. testui.write_err('error\n')
  10. print repr(testui.popbuffer())
  11. # test dispatch.dispatch with the same ui object
  12. hgrc = open(os.environ["HGRCPATH"], 'w')
  13. hgrc.write('[extensions]\n')
  14. hgrc.write('color=\n')
  15. hgrc.close()
  16. ui_ = ui.ui()
  17. ui_.setconfig('ui', 'formatted', 'True')
  18. # we're not interested in the output, so write that to devnull
  19. ui_.fout = open(os.devnull, 'w')
  20. # call some arbitrary command just so we go through
  21. # color's wrapped _runcommand twice.
  22. def runcmd():
  23. dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
  24. runcmd()
  25. print "colored? " + str(issubclass(ui_.__class__, color.colorui))
  26. runcmd()
  27. print "colored? " + str(issubclass(ui_.__class__, color.colorui))