adding first draft of tests for all examples, they need comments and clean up, some could be made more rebust

This commit is contained in:
Brian O'Connor
2013-09-11 14:45:46 -07:00
parent 5a646a0d20
commit a46fae0687
20 changed files with 914 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python
"""TEST"""
import unittest
import pexpect
from mininet.log import setLogLevel
class testLimit( unittest.TestCase ):
"Test ping with single switch topology (common code)."
def testLimit( self ):
opts = [ '\*\*\* Testing network ([\d\.]+) Mbps',
'\*\*\* Results: \[([\d\., ]+)\]',
pexpect.EOF ]
p = pexpect.spawn( 'python -m mininet.examples.limit' )
count = 0
bw = 0
tolerance = 1
while True:
index = p.expect( opts )
if index == 0:
bw = float( p.match.group( 1 ) )
count += 1
elif index == 1:
results = p.match.group( 1 )
for x in results.split(','):
result = float( x )
self.assertTrue( result < bw + tolerance )
self.assertTrue( result > bw - tolerance)
else:
break
self.assertTrue( count > 0 )
if __name__ == '__main__':
setLogLevel( 'warning' )
unittest.main()