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 from pexpect import fdpexpect |
| 23 import unittest |
| 24 from . import PexpectTestCase |
| 25 import os |
| 26 |
| 27 class ExpectTestCase(PexpectTestCase.PexpectTestCase): |
| 28 def setUp(self): |
| 29 print(self.id()) |
| 30 PexpectTestCase.PexpectTestCase.setUp(self) |
| 31 |
| 32 def test_fd (self): |
| 33 fd = os.open ('TESTDATA.txt', os.O_RDONLY) |
| 34 s = fdpexpect.fdspawn (fd) |
| 35 s.expect(b'This is the end of test data:') |
| 36 s.expect(pexpect.EOF) |
| 37 self.assertEqual(s.before, b' END\n') |
| 38 |
| 39 def test_maxread (self): |
| 40 fd = os.open ('TESTDATA.txt', os.O_RDONLY) |
| 41 s = fdpexpect.fdspawn (fd) |
| 42 s.maxread = 100 |
| 43 s.expect('2') |
| 44 s.expect ('This is the end of test data:') |
| 45 s.expect (pexpect.EOF) |
| 46 self.assertEqual(s.before, b' END\n') |
| 47 |
| 48 def test_fd_isalive (self): |
| 49 fd = os.open ('TESTDATA.txt', os.O_RDONLY) |
| 50 s = fdpexpect.fdspawn(fd) |
| 51 assert s.isalive() |
| 52 os.close(fd) |
| 53 assert not s.isalive(), "Should not be alive after close()" |
| 54 |
| 55 def test_fd_isatty (self): |
| 56 fd = os.open ('TESTDATA.txt', os.O_RDONLY) |
| 57 s = fdpexpect.fdspawn (fd) |
| 58 assert not s.isatty() |
| 59 s.close() |
| 60 |
| 61 def test_fileobj(self): |
| 62 f = open('TESTDATA.txt', 'r') |
| 63 s = fdpexpect.fdspawn(f) # Should get the fileno from the file handle |
| 64 s.expect('2') |
| 65 s.close() |
| 66 assert not s.isalive() |
| 67 s.close() # Smoketest - should be able to call this again |
| 68 |
| 69 if __name__ == '__main__': |
| 70 unittest.main() |
| 71 |
| 72 suite = unittest.makeSuite(ExpectTestCase, 'test') |
OLD | NEW |