예제 #1
0
 def __init__(self):
     self.url = 'http://fanyi.youdao.com/openapi.do'
     self.t = Term()
     self.payload = {
         'keyfrom': '# your app name',
         'key': '# your key',
         'type': 'data',
         'doctype': 'json',
         'version': '1.1'
     }
예제 #2
0
    def test_lines_cols(self, monkeypatch):
        # using curses
        tty = StringIO()
        tty.fileno = lambda : 0 # fake whatever fileno
        tty.isatty = lambda : True
        term = Term(stream=tty)
        assert isinstance(term.cols(), int)
        assert isinstance(term.lines(), int)

        # curses not available gets None
        import curses
        monkeypatch.setattr(curses, 'tigetnum', lambda : 5/0)
        assert None == term.cols()
        assert None == term.lines()

        # uses stty
        term2 = Term(stream=tty, code='ansi')
        assert isinstance(term2.cols(), int)
        assert isinstance(term2.lines(), int)
예제 #3
0
 def create():
     stream = StringIO()
     stream.fileno = lambda : 0 # fake whatever fileno
     term = Term(stream=stream)
     # replace real codes with <code-name>
     for name in term.codes.keys():
         if sys.version_info >= (3, 0):
             term.codes[name] = '<{}>'.format(name)
         else:  # pragma: nocover
             term.codes[name] = '<{}>'.format(name)
     term.codes['NORMAL'] = '<NORMAL>'
     term.codes['DEFAULT'] = '<DEFAULT>'
     term.codes = dict((k, v) for k, v in term.codes.items())
     term() # flush initial streeam that contains real code
     stream.seek(0)
     stream.truncate(0)
     return term
예제 #4
0
 def test_color(self):
     tty = StringIO()
     tty.fileno = lambda : 0 # fake whatever fileno
     tty.isatty = lambda : True
     term = Term(stream=tty)
     term.demo()