图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. #*****************************************************************************
  3. # Copyright (C) 2006 Michael Graz. <mgraz@plan10.com>
  4. #
  5. # Distributed under the terms of the BSD License. The full license is in
  6. # the file COPYING, distributed as part of this software.
  7. #*****************************************************************************
  8. from __future__ import print_function, unicode_literals, absolute_import
  9. from pyreadline.modes.emacs import *
  10. from pyreadline import keysyms
  11. from pyreadline.lineeditor import lineobj
  12. from pyreadline.keysyms.common import make_KeyPress_from_keydescr
  13. import unittest
  14. class MockReadline:
  15. def __init__ (self):
  16. self.l_buffer=lineobj.ReadLineTextBuffer("")
  17. self._history=history.LineHistory()
  18. def add_history (self, line):
  19. self._history.add_history (lineobj.TextLine (line))
  20. def _print_prompt (self):
  21. pass
  22. def _bell (self):
  23. pass
  24. def insert_text(self, string):
  25. '''Insert text into the command line.'''
  26. self.l_buffer.insert_text(string)
  27. class MockConsole:
  28. def __init__ (self):
  29. self.bell_count = 0
  30. self.text = ''
  31. def size (self):
  32. return (1, 1)
  33. def cursor(self, visible=None, size=None):
  34. pass
  35. def bell (self):
  36. self.bell_count += 1
  37. def write (self, text):
  38. self.text += text
  39. class Event:
  40. def __init__ (self, char):
  41. if char=="escape":
  42. self.char='\x1b'
  43. elif char=="backspace":
  44. self.char='\x08'
  45. elif char=="tab":
  46. self.char='\t'
  47. elif char=="space":
  48. self.char=' '
  49. else:
  50. self.char = char
  51. def keytext_to_keyinfo_and_event (keytext):
  52. keyinfo = keysyms.common.make_KeyPress_from_keydescr (keytext)
  53. if len(keytext) == 3 and keytext[0] == '"' and keytext[2] == '"':
  54. event = Event (keytext[1])
  55. else:
  56. event = Event (keyinfo.tuple() [3])
  57. return keyinfo, event
  58. #override runTests from from main in unittest to remove sys.exit call
  59. class Tester(unittest.TestProgram):
  60. def runTests(self):
  61. if self.testRunner is None:
  62. self.testRunner = unittest.TextTestRunner(verbosity=self.verbosity)
  63. result = self.testRunner.run(self.test)
  64. # sys.exit(not result.wasSuccessful())