<s> """<STR_LIT>""" <EOL> import unittest <EOL> import pexpect <EOL> import os <EOL> import re <EOL> from mininet . util import quietRun <EOL> from distutils . version import StrictVersion <EOL> def tsharkVersion ( ) : <EOL> "<STR_LIT>" <EOL> versionStr = quietRun ( '<STR_LIT>' ) <EOL> versionMatch = re . findall ( r'<STR_LIT>' , versionStr ) [ <NUM_LIT:0> ] <EOL> return versionMatch . split ( ) [ <NUM_LIT:1> ] <EOL> class testWalkthrough ( unittest . TestCase ) : <EOL> "<STR_LIT>" <EOL> prompt = '<STR_LIT>' <EOL> def testHelp ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> index = p . expect ( [ '<STR_LIT>' , pexpect . EOF ] ) <EOL> self . assertEqual ( index , <NUM_LIT:0> ) <EOL> def testWireshark ( self ) : <EOL> "<STR_LIT>" <EOL> assert self <EOL> if StrictVersion ( tsharkVersion ( ) ) < StrictVersion ( '<STR_LIT>' ) : <EOL> tshark = pexpect . spawn ( '<STR_LIT>' ) <EOL> else : <EOL> tshark = pexpect . spawn ( '<STR_LIT>' ) <EOL> tshark . expect ( [ '<STR_LIT>' , "<STR_LIT>" ] ) <EOL> mn = pexpect . spawn ( '<STR_LIT>' ) <EOL> mn . expect ( '<STR_LIT>' ) <EOL> tshark . expect ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> tshark . sendintr ( ) <EOL> def testBasic ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> index = p . expect ( [ '<STR_LIT>' , self . prompt ] ) <EOL> self . assertEqual ( index , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' ) <EOL> nodes = p . match . group ( <NUM_LIT:0> ) . split ( ) <EOL> self . assertEqual ( len ( nodes ) , <NUM_LIT:4> , '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> expected = [ x for x in nodes ] <EOL> while len ( expected ) > <NUM_LIT:0> : <EOL> index = p . expect ( expected ) <EOL> node = p . match . group ( <NUM_LIT:0> ) <EOL> expected . remove ( node ) <EOL> p . expect ( '<STR_LIT:\n>' ) <EOL> self . assertEqual ( len ( expected ) , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> expected = [ r'<STR_LIT>' % n for n in nodes ] <EOL> actual = [ ] <EOL> for _ in nodes : <EOL> index = p . expect ( expected ) <EOL> node = p . match . group ( <NUM_LIT:1> ) <EOL> actual . append ( node ) <EOL> p . expect ( '<STR_LIT:\n>' ) <EOL> self . assertEqual ( actual . sort ( ) , nodes . sort ( ) , <EOL> '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testHostCommands ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> interfaces = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . prompt ] <EOL> p . sendline ( '<STR_LIT>' ) <EOL> ifcount = <NUM_LIT:0> <EOL> while True : <EOL> index = p . expect ( interfaces ) <EOL> if index == <NUM_LIT:0> or index == <NUM_LIT:3> : <EOL> ifcount += <NUM_LIT:1> <EOL> elif index == <NUM_LIT:1> : <EOL> self . fail ( '<STR_LIT>' ) <EOL> elif index == <NUM_LIT:2> : <EOL> self . fail ( '<STR_LIT>' ) <EOL> else : <EOL> break <EOL> self . assertEqual ( ifcount , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> ifcount = <NUM_LIT:0> <EOL> while True : <EOL> index = p . expect ( interfaces ) <EOL> if index == <NUM_LIT:0> : <EOL> self . fail ( '<STR_LIT>' ) <EOL> elif index == <NUM_LIT:1> or index == <NUM_LIT:2> or index == <NUM_LIT:3> : <EOL> ifcount += <NUM_LIT:1> <EOL> else : <EOL> break <EOL> self . assertEqual ( ifcount , <NUM_LIT:3> , '<STR_LIT>' ) <EOL> p . sendline ( "<STR_LIT>" ) <EOL> p . expect ( self . prompt ) <EOL> h1Output = p . before <EOL> p . sendline ( "<STR_LIT>" ) <EOL> p . expect ( self . prompt ) <EOL> s1Output = p . before <EOL> h1Output = h1Output . split ( '<STR_LIT:\n>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> s1Output = s1Output . split ( '<STR_LIT:\n>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( h1Output , s1Output , '<STR_LIT>' ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testConnectivity ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testSimpleHTTP ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testRegressionRun ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( r"<STR_LIT>" ) <EOL> bw = float ( p . match . group ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( bw > <NUM_LIT:0> ) <EOL> p . expect ( pexpect . EOF ) <EOL> def testTopoChange ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' ) <EOL> received = int ( p . match . group ( <NUM_LIT:1> ) ) <EOL> sent = int ( p . match . group ( <NUM_LIT:2> ) ) <EOL> self . assertEqual ( sent , <NUM_LIT:6> , '<STR_LIT>' ) <EOL> self . assertEqual ( sent , received , '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' ) <EOL> received = int ( p . match . group ( <NUM_LIT:1> ) ) <EOL> sent = int ( p . match . group ( <NUM_LIT:2> ) ) <EOL> self . assertEqual ( sent , <NUM_LIT:12> , '<STR_LIT>' ) <EOL> self . assertEqual ( sent , received , '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> def testLinkChange ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( r"<STR_LIT>" ) <EOL> bw = float ( p . match . group ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( bw < <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertTrue ( bw > <NUM_LIT> , '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' <EOL> r'<STR_LIT>' ) <EOL> delay = float ( p . match . group ( <NUM_LIT:2> ) ) <EOL> self . assertTrue ( delay > <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertTrue ( delay < <NUM_LIT> , '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testVerbosity ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> self . assertEqual ( len ( p . before ) , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> lines = p . before . split ( '<STR_LIT:\n>' ) <EOL> self . assertTrue ( len ( lines ) > <NUM_LIT> , "<STR_LIT>" ) <EOL> def testCustomTopo ( self ) : <EOL> "<STR_LIT>" <EOL> assert self <EOL> custom = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> custom = os . path . join ( custom , '<STR_LIT>' ) <EOL> custom = os . path . normpath ( custom ) <EOL> p = pexpect . spawn ( <EOL> '<STR_LIT>' % custom ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> def testStaticMAC ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:3> ) : <EOL> p . sendline ( '<STR_LIT>' % i ) <EOL> p . expect ( '<STR_LIT>' % i ) <EOL> p . expect ( self . prompt ) <EOL> def testSwitches ( self ) : <EOL> "<STR_LIT>" <EOL> switches = [ '<STR_LIT:user>' , '<STR_LIT>' ] <EOL> for sw in switches : <EOL> p = pexpect . spawn ( '<STR_LIT>' % sw ) <EOL> p . expect ( r"<STR_LIT>" ) <EOL> bw = float ( p . match . group ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( bw > <NUM_LIT:0> ) <EOL> p . expect ( pexpect . EOF ) <EOL> def testBenchmark ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' ) <EOL> time = float ( p . match . group ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( time < <NUM_LIT:2> , '<STR_LIT>' ) <EOL> def testOwnNamespace ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> interfaces = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , self . prompt ] <EOL> p . sendline ( '<STR_LIT>' ) <EOL> ifcount = <NUM_LIT:0> <EOL> while True : <EOL> index = p . expect ( interfaces ) <EOL> if index == <NUM_LIT:1> or index == <NUM_LIT:3> : <EOL> ifcount += <NUM_LIT:1> <EOL> elif index == <NUM_LIT:0> : <EOL> self . fail ( '<STR_LIT>' ) <EOL> elif index == <NUM_LIT:2> : <EOL> self . fail ( '<STR_LIT>' ) <EOL> else : <EOL> break <EOL> self . assertEqual ( ifcount , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( r'<STR_LIT>' ) <EOL> dropped = int ( p . match . group ( <NUM_LIT:1> ) ) <EOL> self . assertEqual ( dropped , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testPythonInterpreter ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( "<STR_LIT>" ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( "<STR_LIT>" ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> def testLink ( self ) : <EOL> "<STR_LIT>" <EOL> p = pexpect . spawn ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . expect ( '<STR_LIT>' ) <EOL> p . expect ( self . prompt ) <EOL> p . sendline ( '<STR_LIT>' ) <EOL> p . wait ( ) <EOL> @ unittest . skipUnless ( os . path . exists ( '<STR_LIT>' ) or <EOL> '<STR_LIT>' in quietRun ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def testRemoteController ( self ) : <EOL> "<STR_LIT>" <EOL> assert self <EOL> if not os . path . exists ( '<STR_LIT>' ) : <EOL> p = pexpect . spawn ( <EOL> '<STR_LIT>' ) <EOL> p . expect ( pexpect . EOF ) <EOL> pox = pexpect . spawn ( '<STR_LIT>' ) <EOL> net = pexpect . spawn ( <EOL> '<STR_LIT>' ) <EOL> net . expect ( '<STR_LIT>' ) <EOL> net . expect ( pexpect . EOF ) <EOL> pox . sendintr ( ) <EOL> pox . wait ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
