<s> from twisted . conch . insults import helper <EOL> from twisted . conch . insults . insults import G0 , G1 , G2 , G3 <EOL> from twisted . conch . insults . insults import modes , privateModes <EOL> from twisted . conch . insults . insults import ( <EOL> NORMAL , BOLD , UNDERLINE , BLINK , REVERSE_VIDEO ) <EOL> from twisted . trial import unittest <EOL> WIDTH = <NUM_LIT> <EOL> HEIGHT = <NUM_LIT> <EOL> class BufferTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . term = helper . TerminalBuffer ( ) <EOL> self . term . connectionMade ( ) <EOL> def testInitialState ( self ) : <EOL> self . assertEqual ( self . term . width , WIDTH ) <EOL> self . assertEqual ( self . term . height , HEIGHT ) <EOL> self . assertEqual ( str ( self . term ) , <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:1> ) ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def test_initialPrivateModes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> { privateModes . AUTO_WRAP : True , <EOL> privateModes . CURSOR_MODE : True } , <EOL> self . term . privateModes ) <EOL> def test_carriageReturn ( self ) : <EOL> """<STR_LIT>""" <EOL> self . term . cursorForward ( <NUM_LIT:5> ) <EOL> self . term . cursorDown ( <NUM_LIT:3> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:5> , <NUM_LIT:3> ) ) <EOL> self . term . insertAtCursor ( "<STR_LIT:\r>" ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> def test_linefeed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . term . cursorForward ( <NUM_LIT:5> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> self . term . insertAtCursor ( "<STR_LIT:\n>" ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:5> , <NUM_LIT:1> ) ) <EOL> def test_newline ( self ) : <EOL> """<STR_LIT>""" <EOL> self . term . cursorForward ( <NUM_LIT:5> ) <EOL> self . term . cursorDown ( <NUM_LIT:3> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:5> , <NUM_LIT:3> ) ) <EOL> self . term . write ( "<STR_LIT:\n>" ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:4> ) ) <EOL> def test_setPrivateModes ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = self . term . privateModes . copy ( ) <EOL> self . term . setPrivateModes ( [ privateModes . SCROLL , privateModes . SCREEN ] ) <EOL> expected [ privateModes . SCROLL ] = True <EOL> expected [ privateModes . SCREEN ] = True <EOL> self . assertEqual ( expected , self . term . privateModes ) <EOL> def test_resetPrivateModes ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = self . term . privateModes . copy ( ) <EOL> self . term . resetPrivateModes ( [ privateModes . AUTO_WRAP , privateModes . CURSOR_MODE ] ) <EOL> del expected [ privateModes . AUTO_WRAP ] <EOL> del expected [ privateModes . CURSOR_MODE ] <EOL> self . assertEqual ( expected , self . term . privateModes ) <EOL> def testCursorDown ( self ) : <EOL> self . term . cursorDown ( <NUM_LIT:3> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> self . term . cursorDown ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:4> ) ) <EOL> self . term . cursorDown ( HEIGHT ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , HEIGHT - <NUM_LIT:1> ) ) <EOL> def testCursorUp ( self ) : <EOL> self . term . cursorUp ( <NUM_LIT:5> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . term . cursorDown ( <NUM_LIT:20> ) <EOL> self . term . cursorUp ( <NUM_LIT:1> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> self . term . cursorUp ( <NUM_LIT> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def testCursorForward ( self ) : <EOL> self . term . cursorForward ( <NUM_LIT:2> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> self . term . cursorForward ( <NUM_LIT:2> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:4> , <NUM_LIT:0> ) ) <EOL> self . term . cursorForward ( WIDTH ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( WIDTH , <NUM_LIT:0> ) ) <EOL> def testCursorBackward ( self ) : <EOL> self . term . cursorForward ( <NUM_LIT:10> ) <EOL> self . term . cursorBackward ( <NUM_LIT:2> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:8> , <NUM_LIT:0> ) ) <EOL> self . term . cursorBackward ( <NUM_LIT:7> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> self . term . cursorBackward ( <NUM_LIT:1> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . term . cursorBackward ( <NUM_LIT:1> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def testCursorPositioning ( self ) : <EOL> self . term . cursorPosition ( <NUM_LIT:3> , <NUM_LIT:9> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:3> , <NUM_LIT:9> ) ) <EOL> def testSimpleWriting ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . term . write ( s ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:2> ) ) <EOL> def testOvertype ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . term . write ( s ) <EOL> self . term . cursorBackward ( len ( s ) ) <EOL> self . term . resetModes ( [ modes . IRM ] ) <EOL> self . term . write ( "<STR_LIT:H>" ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> ( "<STR_LIT:H>" + s [ <NUM_LIT:1> : ] ) + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:2> ) ) <EOL> def testInsert ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . term . write ( s ) <EOL> self . term . cursorBackward ( len ( s ) ) <EOL> self . term . setModes ( [ modes . IRM ] ) <EOL> self . term . write ( "<STR_LIT:H>" ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> ( "<STR_LIT:H>" + s ) + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:2> ) ) <EOL> def testWritingInTheMiddle ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . term . cursorDown ( <NUM_LIT:5> ) <EOL> self . term . cursorForward ( <NUM_LIT:5> ) <EOL> self . term . write ( s ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> '<STR_LIT:\n>' * <NUM_LIT:5> + <EOL> ( self . term . fill * <NUM_LIT:5> ) + s + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:7> ) ) <EOL> def testWritingWrappedAtEndOfLine ( self ) : <EOL> s = "<STR_LIT>" <EOL> self . term . cursorForward ( WIDTH - <NUM_LIT:5> ) <EOL> self . term . write ( s ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s [ : <NUM_LIT:5> ] . rjust ( WIDTH ) + '<STR_LIT:\n>' + <EOL> s [ <NUM_LIT:5> : ] + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:3> ) ) <EOL> def testIndex ( self ) : <EOL> self . term . index ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . term . cursorDown ( HEIGHT ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , HEIGHT - <NUM_LIT:1> ) ) <EOL> self . term . index ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , HEIGHT - <NUM_LIT:1> ) ) <EOL> def testReverseIndex ( self ) : <EOL> self . term . reverseIndex ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . term . cursorDown ( <NUM_LIT:2> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> self . term . reverseIndex ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def test_nextLine ( self ) : <EOL> """<STR_LIT>""" <EOL> self . term . nextLine ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> self . term . cursorForward ( <NUM_LIT:5> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:5> , <NUM_LIT:1> ) ) <EOL> self . term . nextLine ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:0> , <NUM_LIT:2> ) ) <EOL> def testSaveCursor ( self ) : <EOL> self . term . cursorDown ( <NUM_LIT:5> ) <EOL> self . term . cursorForward ( <NUM_LIT:7> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:7> , <NUM_LIT:5> ) ) <EOL> self . term . saveCursor ( ) <EOL> self . term . cursorDown ( <NUM_LIT:7> ) <EOL> self . term . cursorBackward ( <NUM_LIT:3> ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:4> , <NUM_LIT:12> ) ) <EOL> self . term . restoreCursor ( ) <EOL> self . assertEqual ( self . term . reportCursorPosition ( ) , ( <NUM_LIT:7> , <NUM_LIT:5> ) ) <EOL> def testSingleShifts ( self ) : <EOL> self . term . singleShift2 ( ) <EOL> self . term . write ( '<STR_LIT>' ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:H>' ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G2 ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:i>' ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G0 ) <EOL> self . term . singleShift3 ( ) <EOL> self . term . write ( '<STR_LIT>' ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:!>' ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G3 ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:!>' ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G0 ) <EOL> def testShifting ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> s3 = "<STR_LIT>" <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . term . shiftOut ( ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . term . shiftIn ( ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> g = G0 <EOL> h = <NUM_LIT:0> <EOL> for s in ( s1 , s2 , s3 ) : <EOL> for i in range ( len ( s ) ) : <EOL> ch = self . term . getCharacter ( i , h ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , s [ i ] ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , g ) <EOL> g = g == G0 and G1 or G0 <EOL> h += <NUM_LIT:1> <EOL> def testGraphicRendition ( self ) : <EOL> self . term . selectGraphicRendition ( BOLD , UNDERLINE , BLINK , REVERSE_VIDEO ) <EOL> self . term . write ( '<STR_LIT>' ) <EOL> self . term . selectGraphicRendition ( NORMAL ) <EOL> self . term . write ( '<STR_LIT:X>' ) <EOL> self . term . selectGraphicRendition ( BLINK ) <EOL> self . term . write ( '<STR_LIT:Y>' ) <EOL> self . term . selectGraphicRendition ( BOLD ) <EOL> self . term . write ( '<STR_LIT>' ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . bold ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . underline ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . blink ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . reverseVideo ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:X>' ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . bold ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . underline ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . blink ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . reverseVideo ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT:Y>' ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . blink ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . bold ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . underline ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . reverseVideo ) <EOL> ch = self . term . getCharacter ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . blink ) <EOL> self . assertTrue ( ch [ <NUM_LIT:1> ] . bold ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . underline ) <EOL> self . assertFalse ( ch [ <NUM_LIT:1> ] . reverseVideo ) <EOL> def testColorAttributes ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> self . term . selectGraphicRendition ( helper . FOREGROUND + helper . RED , <EOL> helper . BACKGROUND + helper . GREEN ) <EOL> self . term . write ( s1 + "<STR_LIT:\n>" ) <EOL> self . term . selectGraphicRendition ( NORMAL ) <EOL> self . term . write ( s2 + "<STR_LIT:\n>" ) <EOL> for i in range ( len ( s1 ) ) : <EOL> ch = self . term . getCharacter ( i , <NUM_LIT:0> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , s1 [ i ] ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G0 ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . bold , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . underline , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . blink , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . reverseVideo , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . foreground , helper . RED ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . background , helper . GREEN ) <EOL> for i in range ( len ( s2 ) ) : <EOL> ch = self . term . getCharacter ( i , <NUM_LIT:1> ) <EOL> self . assertEqual ( ch [ <NUM_LIT:0> ] , s2 [ i ] ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . charset , G0 ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . bold , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . underline , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . blink , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . reverseVideo , False ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . foreground , helper . WHITE ) <EOL> self . assertEqual ( ch [ <NUM_LIT:1> ] . background , helper . BLACK ) <EOL> def testEraseLine ( self ) : <EOL> s1 = '<STR_LIT>' <EOL> s2 = '<STR_LIT>' <EOL> s3 = '<STR_LIT>' <EOL> self . term . write ( '<STR_LIT:\n>' . join ( ( s1 , s2 , s3 ) ) + '<STR_LIT:\n>' ) <EOL> self . term . cursorPosition ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . term . eraseLine ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s1 + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' + <EOL> s3 + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:4> ) ) <EOL> def testEraseToLineEnd ( self ) : <EOL> s = '<STR_LIT>' <EOL> self . term . write ( s ) <EOL> self . term . cursorBackward ( <NUM_LIT:5> ) <EOL> self . term . eraseToLineEnd ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s [ : - <NUM_LIT:5> ] + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:2> ) ) <EOL> def testEraseToLineBeginning ( self ) : <EOL> s = '<STR_LIT>' <EOL> self . term . write ( s ) <EOL> self . term . cursorBackward ( <NUM_LIT:5> ) <EOL> self . term . eraseToLineBeginning ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s [ - <NUM_LIT:4> : ] . rjust ( len ( s ) ) + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:2> ) ) <EOL> def testEraseDisplay ( self ) : <EOL> self . term . write ( '<STR_LIT>' ) <EOL> self . term . write ( '<STR_LIT>' ) <EOL> self . term . eraseDisplay ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:1> ) ) <EOL> def testEraseToDisplayEnd ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> self . term . write ( '<STR_LIT:\n>' . join ( ( s1 , s2 , '<STR_LIT>' ) ) ) <EOL> self . term . cursorPosition ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> self . term . eraseToDisplayEnd ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s1 + '<STR_LIT:\n>' + <EOL> s2 [ : <NUM_LIT:5> ] + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:3> ) ) <EOL> def testEraseToDisplayBeginning ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> self . term . write ( '<STR_LIT:\n>' . join ( ( s1 , s2 ) ) ) <EOL> self . term . cursorPosition ( <NUM_LIT:5> , <NUM_LIT:1> ) <EOL> self . term . eraseToDisplayBeginning ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> '<STR_LIT:\n>' + <EOL> s2 [ <NUM_LIT:6> : ] . rjust ( len ( s2 ) ) + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:3> ) ) <EOL> def testLineInsertion ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> self . term . write ( '<STR_LIT:\n>' . join ( ( s1 , s2 ) ) ) <EOL> self . term . cursorPosition ( <NUM_LIT:7> , <NUM_LIT:1> ) <EOL> self . term . insertLine ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s1 + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' + <EOL> s2 + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:4> ) ) <EOL> def testLineDeletion ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> s3 = "<STR_LIT>" <EOL> self . term . write ( '<STR_LIT:\n>' . join ( ( s1 , s2 , s3 ) ) ) <EOL> self . term . cursorPosition ( <NUM_LIT:9> , <NUM_LIT:1> ) <EOL> self . term . deleteLine ( ) <EOL> self . assertEqual ( <EOL> str ( self . term ) , <EOL> s1 + '<STR_LIT:\n>' + <EOL> s3 + '<STR_LIT:\n>' + <EOL> '<STR_LIT:\n>' * ( HEIGHT - <NUM_LIT:3> ) ) <EOL> class FakeDelayedCall : <EOL> called = False <EOL> cancelled = False <EOL> def __init__ ( self , fs , timeout , f , a , kw ) : <EOL> self . fs = fs <EOL> self . timeout = timeout <EOL> self . f = f <EOL> self . a = a <EOL> self . kw = kw <EOL> def active ( self ) : <EOL> return not ( self . cancelled or self . called ) <EOL> def cancel ( self ) : <EOL> self . cancelled = True <EOL> def call ( self ) : <EOL> self . called = True <EOL> self . f ( * self . a , ** self . kw ) <EOL> class FakeScheduler : <EOL> def __init__ ( self ) : <EOL> self . calls = [ ] <EOL> def callLater ( self , timeout , f , * a , ** kw ) : <EOL> self . calls . append ( FakeDelayedCall ( self , timeout , f , a , kw ) ) <EOL> return self . calls [ - <NUM_LIT:1> ] <EOL> class ExpectTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . term = helper . ExpectableBuffer ( ) <EOL> self . term . connectionMade ( ) <EOL> self . fs = FakeScheduler ( ) <EOL> def testSimpleString ( self ) : <EOL> result = [ ] <EOL> d = self . term . expect ( "<STR_LIT>" , timeout = <NUM_LIT:1> , scheduler = self . fs ) <EOL> d . addCallback ( result . append ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . assertTrue ( result ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( len ( self . fs . calls ) , <NUM_LIT:1> ) <EOL> self . assertFalse ( self . fs . calls [ <NUM_LIT:0> ] . active ( ) ) <EOL> def testBrokenUpString ( self ) : <EOL> result = [ ] <EOL> d = self . term . expect ( "<STR_LIT>" ) <EOL> d . addCallback ( result . append ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT:d>" ) <EOL> self . assertTrue ( result ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> def testMultiple ( self ) : <EOL> result = [ ] <EOL> d1 = self . term . expect ( "<STR_LIT>" ) <EOL> d1 . addCallback ( result . append ) <EOL> d2 = self . term . expect ( "<STR_LIT>" ) <EOL> d2 . addCallback ( result . append ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT:hello>" ) <EOL> self . assertFalse ( result ) <EOL> self . term . write ( "<STR_LIT:U+0020>" ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:1> ) <EOL> self . term . write ( "<STR_LIT>" ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ <NUM_LIT:1> ] . group ( ) , "<STR_LIT>" ) <EOL> def testSynchronous ( self ) : <EOL> self . term . write ( "<STR_LIT>" ) <EOL> result = [ ] <EOL> d = self . term . expect ( "<STR_LIT>" ) <EOL> d . addCallback ( result . append ) <EOL> self . assertTrue ( result ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> def testMultipleSynchronous ( self ) : <EOL> self . term . write ( "<STR_LIT>" ) <EOL> result = [ ] <EOL> d1 = self . term . expect ( "<STR_LIT>" ) <EOL> d1 . addCallback ( result . append ) <EOL> d2 = self . term . expect ( "<STR_LIT>" ) <EOL> d2 . addCallback ( result . append ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ <NUM_LIT:1> ] . group ( ) , "<STR_LIT>" ) <EOL> def _cbTestTimeoutFailure ( self , res ) : <EOL> self . assertTrue ( hasattr ( res , '<STR_LIT:type>' ) ) <EOL> self . assertEqual ( res . type , helper . ExpectationTimeout ) <EOL> def testTimeoutFailure ( self ) : <EOL> d = self . term . expect ( "<STR_LIT>" , timeout = <NUM_LIT:1> , scheduler = self . fs ) <EOL> d . addBoth ( self . _cbTestTimeoutFailure ) <EOL> self . fs . calls [ <NUM_LIT:0> ] . call ( ) <EOL> def testOverlappingTimeout ( self ) : <EOL> self . term . write ( "<STR_LIT>" ) <EOL> result = [ ] <EOL> d1 = self . term . expect ( "<STR_LIT>" , timeout = <NUM_LIT:1> , scheduler = self . fs ) <EOL> d1 . addBoth ( self . _cbTestTimeoutFailure ) <EOL> d2 = self . term . expect ( "<STR_LIT>" ) <EOL> d2 . addCallback ( result . append ) <EOL> self . fs . calls [ <NUM_LIT:0> ] . call ( ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] . group ( ) , "<STR_LIT>" ) <EOL> class CharacterAttributeTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_equality ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> helper . CharacterAttribute ( ) , <EOL> helper . CharacterAttribute ( ) ) <EOL> self . assertEqual ( <EOL> helper . CharacterAttribute ( ) , <EOL> helper . CharacterAttribute ( charset = G0 ) ) <EOL> self . assertEqual ( <EOL> helper . CharacterAttribute ( <EOL> bold = True , underline = True , blink = False , reverseVideo = True , <EOL> foreground = helper . BLUE ) , <EOL> helper . CharacterAttribute ( <EOL> bold = True , underline = True , blink = False , reverseVideo = True , <EOL> foreground = helper . BLUE ) ) <EOL> self . assertNotEqual ( <EOL> helper . CharacterAttribute ( ) , <EOL> helper . CharacterAttribute ( charset = G1 ) ) <EOL> self . assertNotEqual ( <EOL> helper . CharacterAttribute ( bold = True ) , <EOL> helper . CharacterAttribute ( bold = False ) ) <EOL> def test_wantOneDeprecated ( self ) : <EOL> """<STR_LIT>""" <EOL> helper . _FormattingState ( ) . wantOne ( bold = True ) <EOL> warningsShown = self . flushWarnings ( [ self . test_wantOneDeprecated ] ) <EOL> self . assertEqual ( len ( warningsShown ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( warningsShown [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , DeprecationWarning ) <EOL> self . assertEqual ( <EOL> warningsShown [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) </s>
