2019-05-05 13:49:28 +00:00
|
|
|
import wexpect
|
|
|
|
import unittest
|
2020-01-25 22:52:08 +00:00
|
|
|
import time
|
2020-02-22 22:03:28 +00:00
|
|
|
from tests import PexpectTestCase
|
2019-05-05 13:49:28 +00:00
|
|
|
|
|
|
|
class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
|
|
|
|
def test_constructor (self):
|
|
|
|
'''This tests that the constructor will work and give
|
|
|
|
the same results for different styles of invoking __init__().
|
|
|
|
This assumes that the root directory / is static during the test.
|
|
|
|
'''
|
2020-01-25 22:52:08 +00:00
|
|
|
p1 = wexpect.spawn('uname -m -n -p -r -s -v', timeout=5)
|
2019-05-05 13:49:28 +00:00
|
|
|
p1.expect(wexpect.EOF)
|
2020-01-25 22:52:08 +00:00
|
|
|
time.sleep(p1.delayafterterminate)
|
|
|
|
p2 = wexpect.spawn('uname', ['-m', '-n', '-p', '-r', '-s', '-v'], timeout=5)
|
2019-05-05 13:49:28 +00:00
|
|
|
p2.expect(wexpect.EOF)
|
2020-01-31 14:49:48 +00:00
|
|
|
time.sleep(p1.delayafterterminate)
|
2019-09-05 07:47:35 +00:00
|
|
|
self.assertEqual(p1.before, p2.before)
|
2019-10-04 11:26:36 +00:00
|
|
|
self.assertEqual(str(p1).splitlines()[1:9], str(p2).splitlines()[1:9])
|
|
|
|
|
|
|
|
run_result = wexpect.run('uname -m -n -p -r -s -v')
|
|
|
|
self.assertEqual(run_result, p2.before)
|
2019-05-05 13:49:28 +00:00
|
|
|
|
|
|
|
def test_named_parameters (self):
|
|
|
|
'''This tests that named parameters work.
|
|
|
|
'''
|
2020-01-25 22:52:08 +00:00
|
|
|
p = wexpect.spawn('ls',timeout=10)
|
|
|
|
p.wait()
|
|
|
|
p = wexpect.spawn(timeout=10, command='ls')
|
|
|
|
p.wait()
|
|
|
|
p = wexpect.spawn(args=[], command='ls')
|
|
|
|
p.wait()
|
2019-05-05 13:49:28 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
suite = unittest.makeSuite(TestCaseConstructor,'test')
|