OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 ''' |
| 3 PEXPECT LICENSE |
| 4 |
| 5 This license is approved by the OSI and FSF as GPL-compatible. |
| 6 http://opensource.org/licenses/isc-license.txt |
| 7 |
| 8 Copyright (c) 2012, Noah Spurrier <noah@noah.org> |
| 9 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY |
| 10 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE |
| 11 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. |
| 12 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 13 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 14 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 15 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 |
| 20 ''' |
| 21 import pexpect |
| 22 import unittest |
| 23 from . import PexpectTestCase |
| 24 import gc |
| 25 import platform |
| 26 import time |
| 27 |
| 28 class TestCaseDestructor(PexpectTestCase.PexpectTestCase): |
| 29 def test_destructor (self): |
| 30 if platform.python_implementation() != 'CPython': |
| 31 # Details of garbage collection are different on other implementatio
ns |
| 32 return 'SKIP' |
| 33 gc.collect() |
| 34 time.sleep(3) |
| 35 p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 36 p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 37 p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 38 p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 39 fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd) |
| 40 p1.expect(pexpect.EOF) |
| 41 p2.expect(pexpect.EOF) |
| 42 p3.expect(pexpect.EOF) |
| 43 p4.expect(pexpect.EOF) |
| 44 p1.kill(9) |
| 45 p2.kill(9) |
| 46 p3.kill(9) |
| 47 p4.kill(9) |
| 48 p1 = None |
| 49 p2 = None |
| 50 p3 = None |
| 51 p4 = None |
| 52 gc.collect() |
| 53 time.sleep(3) # Some platforms are slow at gc... Solaris! |
| 54 |
| 55 p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 56 p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 57 p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 58 p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 59 fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd) |
| 60 p1.kill(9) |
| 61 p2.kill(9) |
| 62 p3.kill(9) |
| 63 p4.kill(9) |
| 64 del (p1) |
| 65 del (p2) |
| 66 del (p3) |
| 67 del (p4) |
| 68 gc.collect() |
| 69 time.sleep(3) |
| 70 |
| 71 p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 72 p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 73 p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 74 p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN) |
| 75 fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd) |
| 76 |
| 77 assert (fd_t1 == fd_t2 == fd_t3), "pty file descriptors not properly gar
bage collected (fd_t1,fd_t2,fd_t3)=(%s,%s,%s)" % (str(fd_t1),str(fd_t2),str(fd_t
3)) |
| 78 |
| 79 |
| 80 if __name__ == '__main__': |
| 81 unittest.main() |
| 82 |
| 83 suite = unittest.makeSuite(TestCaseDestructor,'test') |
| 84 |
OLD | NEW |