From f51656b4b9254f920e8214f3993becb2ef871fe8 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 13 Jul 2007 01:04:16 +0000 Subject: Added test for ANSI screen torture test. git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@486 656d521f-e311-0410-88e0-e7920216d269 --- pexpect/screen.py | 24 +++++++++++++++++++++--- pexpect/tests/test_ansi.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/pexpect/screen.py b/pexpect/screen.py index 6bcc3e4..620aff7 100644 --- a/pexpect/screen.py +++ b/pexpect/screen.py @@ -1,10 +1,12 @@ -"""This implements a virtual screen. +"""This implements a virtual screen. This is used to support ANSI terminal +emulation. The screen representation and state is implemented in this class. +Most of the methods are inspired by ANSI screen control codes. The ANSI class +extends this class to add parsing of ANSI escape codes. $Id$ """ import copy -#import string NUL = 0 # Fill character; ignored on input. ENQ = 5 # Transmit answerback message. @@ -27,7 +29,7 @@ SPACE = chr(32) # Space or blank character. def constrain (n, min, max): - """This returns n constrained to the min and max bounds. """ + """This returns a number, n constrained to the min and max bounds. """ if n < min: return min @@ -44,6 +46,9 @@ class screen: like arrays). """ def __init__ (self, r=24,c=80): + + """This initializes a blank scree of the given dimentions.""" + self.rows = r self.cols = c self.cur_r = 1 @@ -55,6 +60,10 @@ class screen: self.w = [ [SPACE] * self.cols for c in range(self.rows)] def __str__ (self): + + """This returns a printable representation of the screen. The end of + each screen line is terminated by a newline. """ + return '\n'.join ([ ''.join(c) for c in self.w ]) def dump (self): @@ -64,6 +73,15 @@ class screen: return ''.join ([ ''.join(c) for c in self.w ]) + def pretty (self): + + """This returns a copy of the screen as a string with an ASCII text box + around the screen border. This is similar to __str__ except that it + adds a box. """ + + top_bot = '+' + '-'*self.cols + '+\n' + return top_bot + '\n'.join(['|'+line+'|' for line in str(self).split('\n')]) + '\n' + top_bot + def fill (self, ch=SPACE): self.fill_region (1,1,self.rows,self.cols, ch) diff --git a/pexpect/tests/test_ansi.py b/pexpect/tests/test_ansi.py index cc7caa3..2db0538 100755 --- a/pexpect/tests/test_ansi.py +++ b/pexpect/tests/test_ansi.py @@ -59,6 +59,33 @@ tetris_target=' XX XXXX XX ' J->LEFT K->ROTATE L->RIGHT SPACE->DROP P->PAUSE Q->QUIT \n' +\ ' ' +torture_target='+--------------------------------------------------------------------------------+\n' +\ +'|a`opqrs` This is the `srqpo`a |\n' +\ +'|VT100 series Torture Test Demonstration. |\n' +\ +'|VT100 series Torture Test Demonstration. |\n' +\ +'|This is a normal line __________________________________________________y_ |\n' +\ +'|This is a bold line (normal unless the Advanced Video Option is installed) |\n' +\ +'|This line is underlined _ " " " " " " _y_ |\n' +\ +'|This is a blinking line _ " " " " " " _y_ |\n' +\ +'|This is inverse video _ (underlined if no AVO and cursor is underline) _y_ |\n' +\ +'|Normal gjpqy Underline Blink Underline+Blink gjpqy |\n' +\ +'|Bold gjpqy Underline Blink Underline+Blink gjpqy |\n' +\ +'|Inverse Underline Blink Underline+Blink |\n' +\ +'|Bold+Inverse Underline7m Blink Underline+Blink |\n' +\ +'|This is double width |\n' +\ +'|This is double height |\n' +\ +'|This is double height |\n' +\ +'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy |\n' +\ +'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy |\n' +\ +'|_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy |\n' +\ +'|`abcdefghijklmnopqrstuvwxyz{|}~ lqwqk |\n' +\ +'|`abcdefghijklmnopqrstuvwxyz{|}~ tqnqu |\n' +\ +'|`abcdefghijklmnopqrstuvwxyz{|}~ tqnqu |\n' +\ +'|`abcdefghijklmnopqrstuvwxyz{|}~ mqvqj |\n' +\ +'| This test created by Joe Smith, 8-May-85 |\n' +\ +'| |\n' +\ +'+--------------------------------------------------------------------------------+\n' + class ansiTestCase (PexpectTestCase.PexpectTestCase): def test_write (self): s = ANSI.ANSI (6,65) @@ -67,6 +94,12 @@ class ansiTestCase (PexpectTestCase.PexpectTestCase): for c in write_text: s.write (c) assert str(s) == write_target + def test_torturet (self): + s = ANSI.ANSI (24,80) + sample_text = open ('torturet.vt').read() + for c in sample_text: + s.process (c) + assert s.pretty() == torture_target, 'processed: \n' + s.pretty() + '\nexpected:\n' + torture_target def test_tetris (self): s = ANSI.ANSI (24,80) tetris_text = open ('tetris.data').read() -- cgit v1.2.1