示例#1
0
 def test_tetris(self):
     s = ANSI.ANSI(24, 80)
     with open('tetris.data') as f:
         tetris_text = f.read()
     for c in tetris_text:
         s.process(c)
     assert str(s) == tetris_target
示例#2
0
 def test_fsm_memory(self):
     """Test the FSM stack/memory does not have numbers left on it
     after some sequences with numbers are passed in."""
     s = ANSI.ANSI(1, 20)
     s.write('\x1b[0;1;2;3m\x1b[4;5;6;7q\x1b[?8h\x1b[?9ltest')
     assert str(s) == ('test                ')
     assert s.state.memory == [s]
示例#3
0
文件: pex.py 项目: nowayelse/pex
    def __init__(self, sid=''):

        # self.out = sids[sid].before.replace('\r\r\n', '').split('\r\n')
        # return

        if pyte_ok:
            screen = pyte.Screen(os.get_terminal_size()[0], max_lines)
            stream = pyte.Stream(screen)
            screen.mode.add(pyte.modes.LNM)
            ss = sids[sid].before.replace('\r\r\n', '').replace('\r\n', 'CRNL')
            stream.feed(ss)
            self.out = [
                i.rstrip() for i in ''.join(screen.display).split('CRNL')
            ]
            del screen, stream
        else:
            l, s, r = sids[sid].before.replace('\r\r\n', '').rpartition('\x1b')
            if l == '':
                l, s, r = sids[sid].before.replace('\r\r\n',
                                                   '').partition('\r\n')
            else:
                l1, s, r = r.partition('\r\n')
            term = ANSI.ANSI(*os.get_terminal_size()[::-1])
            term.process_list(l)
            self.out = [(''.join(str(term).split('\n'))).strip()
                        ] + r.split('\r\n')
示例#4
0
 def test_write(self):
     s = ANSI.ANSI(6, 65)
     s.fill('.')
     s.cursor_home()
     for c in write_text:
         s.write(c)
     assert str(s) == write_target
示例#5
0
 def test_utf8_bytes(self):
     """Test that when bytes are passed in containing UTF-8 encoded
     characters, where the encoding of each character consists of
     multiple bytes, the characters are correctly decoded.
     Incremental decoding is also tested."""
     s = ANSI.ANSI(2, 10, encoding="utf-8")
     # This is the UTF-8 encoding of the UCS character "HOURGLASS"
     # followed by the UTF-8 encoding of the UCS character
     # "KEYBOARD".  These characters can't be encoded in cp437 or
     # latin-1.  The "KEYBOARD" character is split into two
     # separate writes.
     s.write(b"\xe2\x8c\x9b")
     s.write(b"\xe2\x8c")
     s.write(b"\xa8")
     if PY3:
         assert str(s) == u"\u231b\u2328        \n          "
     else:
         assert unicode(s) == u"\u231b\u2328        \n          "
         assert str(s) == b"\xe2\x8c\x9b\xe2\x8c\xa8        \n          "
     assert s.dump() == u"\u231b\u2328                  "
     assert (
         s.pretty()
         == u"+----------+\n|\u231b\u2328        |\n|          |\n+----------+\n"
     )
     assert s.get_abs(1, 1) == u"\u231b"
     assert s.get_region(1, 1, 1, 5) == [u"\u231b\u2328   "]
示例#6
0
 def test_torturet (self):
     s = ANSI.ANSI (24,80)
     with open('torturet.vt') as f:
         sample_text = f.read()
     for c in sample_text:
         s.process (c)
     assert s.pretty() == torture_target, 'processed: \n' + s.pretty() + '\nexpected:\n' + torture_target
示例#7
0
    def __init__(self, engine="/usr/local/bin/gnuchess -a -h 1"):
        self.child = pexpect.spawn(engine)
        self.term = ANSI.ANSI()

        self.child.expect('Chess')
        if self.child.after != 'Chess':
            raise IOError('incompatible chess program')
        self.term.process_list(self.before)
        self.term.process_list(self.after)
        self.last_computer_move = ''
示例#8
0
 def test_lines(self):
     s = ANSI.ANSI(5, 5)
     s.write('a'*6 + '\n')
     s.write('ab\bcd\n')
     s.write('ab\rcd\n')
     assert str(s) == ('aaaaa\n'
                       'a    \n'
                       'acd  \n'
                       'cd   \n'
                       '     ')
示例#9
0
 def test_unicode(self):
     """Test passing in of a unicode string."""
     s = ANSI.ANSI(2, 10, encoding="utf-8")
     s.write(u'\u231b\u2328')
     if PY3:
         assert str(s) == u'\u231b\u2328        \n          '
     else:
         assert unicode(s) == u'\u231b\u2328        \n          '
         assert str(s) == b'\xe2\x8c\x9b\xe2\x8c\xa8        \n          '
     assert s.dump() == u'\u231b\u2328                  '
     assert s.pretty() == u'+----------+\n|\u231b\u2328        |\n|          |\n+----------+\n'
     assert s.get_abs(1, 1) == u'\u231b'
     assert s.get_region(1, 1, 1, 5) == [u'\u231b\u2328   ']
示例#10
0
 def test_unicode(self):
     """Test passing in of a unicode string."""
     s = ANSI.ANSI(2, 10, encoding="utf-8")
     s.write(u"\u231b\u2328")
     if PY3:
         assert str(s) == u"\u231b\u2328        \n          "
     else:
         assert unicode(s) == u"\u231b\u2328        \n          "
         assert str(s) == b"\xe2\x8c\x9b\xe2\x8c\xa8        \n          "
     assert s.dump() == u"\u231b\u2328                  "
     assert (
         s.pretty()
         == u"+----------+\n|\u231b\u2328        |\n|          |\n+----------+\n"
     )
     assert s.get_abs(1, 1) == u"\u231b"
     assert s.get_region(1, 1, 1, 5) == [u"\u231b\u2328   "]
示例#11
0
 def test_decode_error(self):
     """Test that default handling of decode errors replaces the
     invalid characters."""
     s = ANSI.ANSI(2, 10, encoding="ascii")
     s.write(b'\xff') # a non-ASCII character
     # In unicode, the non-ASCII character is replaced with
     # REPLACEMENT CHARACTER.
     if PY3:
         assert str(s) == u'\ufffd         \n          '
     else:
         assert unicode(s) == u'\ufffd         \n          '
         assert str(s) == b'?         \n          '
     assert s.dump() == u'\ufffd                   '
     assert s.pretty() == u'+----------+\n|\ufffd         |\n|          |\n+----------+\n'
     assert s.get_abs(1, 1) == u'\ufffd'
     assert s.get_region(1, 1, 1, 5) == [u'\ufffd    ']
示例#12
0
 def test_torturet(self):
     s = ANSI.ANSI(24, 80)
     with open('torturet.vt') as f:
         sample_text = f.read()
     # This causes ANSI.py's DoLog to write in the cwd.  Make sure we're in a
     # writeable directory.
     d = tempfile.mkdtemp()
     old_cwd = os.getcwd()
     os.chdir(d)
     try:
         for c in sample_text:
             s.process(c)
     finally:
         os.chdir(old_cwd)
         shutil.rmtree(d)
     assert s.pretty() == torture_target, 'processed: \n' + s.pretty(
     ) + '\nexpected:\n' + torture_target
示例#13
0
 def test_lines(self):
     s = ANSI.ANSI(5, 5)
     s.write("a" * 6 + "\n")
     s.write("ab\bcd\n")
     s.write("ab\rcd\n")
     assert str(s) == ("aaaaa\n" "a    \n" "acd  \n" "cd   \n" "     ")