blob: 999d94e3940681a684e70e4e89fcd5d96562374f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python
import fdpexpect, pexpect
import unittest
import PexpectTestCase
import sys
import os
class ExpectTestCase(PexpectTestCase.PexpectTestCase):
def setUp(self):
print self.id()
PexpectTestCase.PexpectTestCase.setUp(self)
def test_fd (self):
fd = os.open ('TESTDATA.txt', os.O_RDONLY)
s = fdpexpect.fdspawn (fd)
s.expect ('This is the end of test data:')
s.expect (pexpect.EOF)
assert s.before == ' END\n'
def test_maxread (self):
fd = os.open ('TESTDATA.txt', os.O_RDONLY)
s = fdpexpect.fdspawn (fd)
s.maxread = 100
s.expect('2')
s.expect ('This is the end of test data:')
s.expect (pexpect.EOF)
assert s.before == ' END\n'
def test_fd_isalive (self):
fd = os.open ('TESTDATA.txt', os.O_RDONLY)
s = fdpexpect.fdspawn (fd)
assert s.isalive()
os.close (fd)
assert not s.isalive(), "Should not be alive after close()"
def test_fd_isatty (self):
fd = os.open ('TESTDATA.txt', os.O_RDONLY)
s = fdpexpect.fdspawn (fd)
assert not s.isatty()
#os.close(fd)
s.close()
### def test_close_does_not_close_fd (self):
### """Calling close() on a fdpexpect.fdspawn object should not
### close the underlying file descriptor.
### """
### fd = os.open ('TESTDATA.txt', os.O_RDONLY)
### s = fdpexpect.fdspawn (fd)
### try:
### s.close()
### self.fail('Expected an Exception.')
### except pexpect.ExceptionPexpect, e:
### pass
if __name__ == '__main__':
unittest.main()
suite = unittest.makeSuite(ExpectTestCase, 'test')
#fout = open('delete_me_1','wb')
#fout.write(the_old_way)
#fout.close
#fout = open('delete_me_2', 'wb')
#fout.write(the_new_way)
#fout.close
|