blob: 8df72f2f8ffa625f1e3f7ddc466050e694bd5a16 (
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/usr/bin/env python
import pexpect
import unittest
import commands
import sys
class ExpectTestCase(unittest.TestCase):
def test_exp (self):
p = pexpect.spawn('cat')
p.sendline ('Hello')
p.sendline ('there')
p.sendline ('Mr. Python')
p.expect (['Hello'])
p.expect (['there'])
p.expect (['Mr. Python'])
p.sendeof ()
p.expect (pexpect.EOF)
def test_expect (self):
the_old_way = commands.getoutput('ls -l /bin')
p = pexpect.spawn('ls -l /bin')
the_new_way = ''
while 1:
i = p.expect (['\n', pexpect.EOF])
the_new_way = the_new_way + p.before
if i == 1:
break
the_new_way = the_new_way[:-1]
the_new_way = the_new_way.replace('\r','\n')
assert the_old_way == the_new_way
def test_expect_exact (self):
the_old_way = commands.getoutput('ls -l /bin')
p = pexpect.spawn('ls -l /bin')
the_new_way = ''
while 1:
i = p.expect (['\n', pexpect.EOF])
the_new_way = the_new_way + p.before
if i == 1:
break
the_new_way = the_new_way[:-1]
the_new_way = the_new_way.replace('\r','\n')
assert the_old_way == the_new_way
def test_expect_eof (self):
the_old_way = commands.getoutput('ls -l /bin')
p = pexpect.spawn('ls -l /bin')
p.expect(pexpect.EOF) # This basically tells it to read everything.
the_new_way = p.before
the_new_way = the_new_way.replace('\r','')
the_new_way = the_new_way[:-1]
assert the_old_way == the_new_way
<<<<<<< test_expect.py
def test_expect_timeout (self):
the_old_way = commands.getoutput('ls -l /bin')
p = pexpect.spawn('ls -l /bin')
i = p.expect(pexpect.TIMEOUT) # This tells it to wait for timeout.
assert p.after == pexpect.TIMEOUT
assert the_old_way == the_new_way
=======
def test_expect_timeout (self):
the_old_way = commands.getoutput('ls -l /bin')
p = pexpect.spawn('cat')
i = p.expect(pexpect.TIMEOUT)
assert p.after == pexpect.TIMEOUT
>>>>>>> 1.17
def test_unexpected_eof (self):
p = pexpect.spawn('ls -l /bin')
try:
p.expect('ZXYXZ') # Probably never see this in ls output.
except pexpect.EOF, e:
pass
else:
self.fail ('Expected an EOF exception.')
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
|