mirror of
https://github.com/clearml/wexpect-venv
synced 2025-02-07 05:20:52 +00:00
[FIX] all cleaned test merged
This commit is contained in:
parent
3d65f30b16
commit
8a84d0bb79
@ -20,6 +20,7 @@ PEXPECT LICENSE
|
||||
'''
|
||||
import wexpect
|
||||
import unittest
|
||||
import time
|
||||
from . import PexpectTestCase
|
||||
|
||||
class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
|
||||
@ -28,9 +29,10 @@ class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
|
||||
the same results for different styles of invoking __init__().
|
||||
This assumes that the root directory / is static during the test.
|
||||
'''
|
||||
p1 = wexpect.spawn('uname -m -n -p -r -s -v')
|
||||
p1 = wexpect.spawn('uname -m -n -p -r -s -v', timeout=5)
|
||||
p1.expect(wexpect.EOF)
|
||||
p2 = wexpect.spawn('uname', ['-m', '-n', '-p', '-r', '-s', '-v'])
|
||||
time.sleep(p1.delayafterterminate)
|
||||
p2 = wexpect.spawn('uname', ['-m', '-n', '-p', '-r', '-s', '-v'], timeout=5)
|
||||
p2.expect(wexpect.EOF)
|
||||
self.assertEqual(p1.before, p2.before)
|
||||
self.assertEqual(str(p1).splitlines()[1:9], str(p2).splitlines()[1:9])
|
||||
@ -41,9 +43,12 @@ class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
|
||||
def test_named_parameters (self):
|
||||
'''This tests that named parameters work.
|
||||
'''
|
||||
p = wexpect.spawn ('ls',timeout=10)
|
||||
p = wexpect.spawn (timeout=10, command='ls')
|
||||
p = wexpect.spawn (args=[], command='ls')
|
||||
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()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -32,35 +32,34 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
|
||||
return 'SKIP'
|
||||
gc.collect()
|
||||
time.sleep(2)
|
||||
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
|
||||
p1 = wexpect.spawn('ls', port=4321)
|
||||
p2 = wexpect.spawn('ls', port=4322)
|
||||
p3 = wexpect.spawn('ls', port=4323)
|
||||
p4 = wexpect.spawn('ls', port=4324)
|
||||
p1.expect(wexpect.EOF)
|
||||
p2.expect(wexpect.EOF)
|
||||
p3.expect(wexpect.EOF)
|
||||
p4.expect(wexpect.EOF)
|
||||
p1.kill(9)
|
||||
p2.kill(9)
|
||||
p3.kill(9)
|
||||
p4.kill(9)
|
||||
p1.kill()
|
||||
p2.kill()
|
||||
p3.kill()
|
||||
p4.kill()
|
||||
p1 = None
|
||||
p2 = None
|
||||
p3 = None
|
||||
p4 = None
|
||||
gc.collect()
|
||||
time.sleep(2) # Some platforms are slow at gc... Solaris!
|
||||
|
||||
|
||||
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
|
||||
p1.kill(9)
|
||||
p2.kill(9)
|
||||
p3.kill(9)
|
||||
p4.kill(9)
|
||||
p1 = wexpect.spawn('ls', port=4321)
|
||||
p2 = wexpect.spawn('ls', port=4322)
|
||||
p3 = wexpect.spawn('ls', port=4323)
|
||||
p4 = wexpect.spawn('ls', port=4324)
|
||||
p1.kill()
|
||||
p2.kill()
|
||||
p3.kill()
|
||||
p4.kill()
|
||||
del (p1)
|
||||
del (p2)
|
||||
del (p3)
|
||||
@ -68,13 +67,10 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
|
||||
gc.collect()
|
||||
time.sleep(2)
|
||||
|
||||
p1 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p2 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p3 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
p4 = wexpect.spawn('"%s" hello_world.py' % self.PYTHONBIN)
|
||||
fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
|
||||
|
||||
assert (fd_t1 == fd_t2 == fd_t3), "pty file descriptors not properly garbage collected (fd_t1,fd_t2,fd_t3)=(%s,%s,%s)" % (str(fd_t1),str(fd_t2),str(fd_t3))
|
||||
p1 = wexpect.spawn('ls', port=4321)
|
||||
p2 = wexpect.spawn('ls', port=4322)
|
||||
p3 = wexpect.spawn('ls', port=4323)
|
||||
p4 = wexpect.spawn('ls', port=4324)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -287,7 +287,7 @@ def run (command, timeout=-1, withexitstatus=False, events=None, extra_args=None
|
||||
return child_result
|
||||
|
||||
def spawn(command, args=[], timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None,
|
||||
env=None, codepage=None, echo=True):
|
||||
env=None, codepage=None, echo=True, **kwargs):
|
||||
"""This is the most essential function. The command parameter may be a string that
|
||||
includes a command and any arguments to the command. For example::
|
||||
|
||||
@ -790,7 +790,7 @@ class spawn_windows ():
|
||||
|
||||
return False
|
||||
|
||||
def kill(self, sig):
|
||||
def kill(self, sig=signal.SIGTERM):
|
||||
"""Sig == sigint for ctrl-c otherwise the child is terminated."""
|
||||
|
||||
if not self.isalive():
|
||||
|
Loading…
Reference in New Issue
Block a user