mirror of
https://github.com/clearml/wexpect-venv
synced 2025-06-26 18:15:52 +00:00
[FIX] command and args now can be given in one string
This commit is contained in:
parent
18a1bfd60f
commit
a5815fa4a8
48
tests/test_constructor.py
Normal file
48
tests/test_constructor.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
'''
|
||||||
|
PEXPECT LICENSE
|
||||||
|
|
||||||
|
This license is approved by the OSI and FSF as GPL-compatible.
|
||||||
|
http://opensource.org/licenses/isc-license.txt
|
||||||
|
|
||||||
|
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
|
||||||
|
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
|
||||||
|
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
|
||||||
|
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
'''
|
||||||
|
import wexpect
|
||||||
|
import unittest
|
||||||
|
from . import PexpectTestCase
|
||||||
|
|
||||||
|
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.
|
||||||
|
'''
|
||||||
|
p1 = wexpect.spawn('uname -m -n -p -r -s -v')
|
||||||
|
p2 = wexpect.spawn('uname', ['-m', '-n', '-p', '-r', '-s', '-v'])
|
||||||
|
p1.expect(wexpect.EOF)
|
||||||
|
p2.expect(wexpect.EOF)
|
||||||
|
assert p1.before == p2.before
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
suite = unittest.makeSuite(TestCaseConstructor,'test')
|
||||||
|
|
||||||
84
tests/test_destructor.py
Normal file
84
tests/test_destructor.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
'''
|
||||||
|
PEXPECT LICENSE
|
||||||
|
|
||||||
|
This license is approved by the OSI and FSF as GPL-compatible.
|
||||||
|
http://opensource.org/licenses/isc-license.txt
|
||||||
|
|
||||||
|
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
|
||||||
|
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
|
||||||
|
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
|
||||||
|
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
'''
|
||||||
|
import wexpect
|
||||||
|
import unittest
|
||||||
|
from . import PexpectTestCase
|
||||||
|
import gc
|
||||||
|
import platform
|
||||||
|
import time
|
||||||
|
|
||||||
|
class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
|
||||||
|
def test_destructor (self):
|
||||||
|
if platform.python_implementation() != 'CPython':
|
||||||
|
# Details of garbage collection are different on other implementations
|
||||||
|
return 'SKIP'
|
||||||
|
gc.collect()
|
||||||
|
time.sleep(3)
|
||||||
|
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.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 = None
|
||||||
|
p2 = None
|
||||||
|
p3 = None
|
||||||
|
p4 = None
|
||||||
|
gc.collect()
|
||||||
|
time.sleep(3) # 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)
|
||||||
|
del (p1)
|
||||||
|
del (p2)
|
||||||
|
del (p3)
|
||||||
|
del (p4)
|
||||||
|
gc.collect()
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
suite = unittest.makeSuite(TestCaseDestructor,'test')
|
||||||
|
|
||||||
@ -1700,10 +1700,9 @@ class spawn_windows (spawn_unix, object):
|
|||||||
raise TypeError ('The argument, args, must be a list.')
|
raise TypeError ('The argument, args, must be a list.')
|
||||||
|
|
||||||
if args == []:
|
if args == []:
|
||||||
#Momentairly broken - path '\' characters being misinterpreted
|
self.args = split_command_line(command)
|
||||||
#self.args = split_command_line(command)
|
|
||||||
self.args = [command]
|
|
||||||
self.command = self.args[0]
|
self.command = self.args[0]
|
||||||
|
print('command@@ {} args {}'.format(command, args))
|
||||||
else:
|
else:
|
||||||
self.args = args[:] # work with a copy
|
self.args = args[:] # work with a copy
|
||||||
self.args.insert (0, command)
|
self.args.insert (0, command)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user