Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
141 Kevin 1
#!/usr/bin/python
2
#
3
# Block header comment
4
#
5
#
6
import sys, imp, atexit
7
sys.path.append("/home/courses/cs3214/software/pexpect-dpty/");
8
import pexpect, shellio, signal, time, os, re, proc_check
9
 
10
#Ensure the shell process is terminated
11
def force_shell_termination(shell_process):
12
	c.close(force=True)
13
 
14
#pulling in the regular expression and other definitions
15
definitions_scriptname = sys.argv[1]
16
def_module = imp.load_source('', definitions_scriptname)
17
logfile = None
18
if hasattr(def_module, 'logfile'):
19
    logfile = def_module.logfile
20
 
21
#spawn an instance of the shell
22
c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile)
23
atexit.register(force_shell_termination, shell_process=c)
24
 
25
 
26
# set timeout for all following 'expect*' calls to 2 seconds
27
c.timeout = 2
28
 
29
# ensure that shell prints expected prompt
30
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
31
 
32
# save a string to a file
33
c.sendline("echo This is a test message > testfile")
34
 
35
# ensure that the shell prints the expected prompt
36
assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt"
37
 
38
# print out contents of said file
39
c.sendline("wc < testfile")
40
 
41
# check if correct string was written
42
assert c.expect(" 1  5 23") == 0, "Shell did not print expected output"
43
 
44
# remove tmp file
45
c.sendline("rm testfile")
46
 
47
c.sendline("exit");
48
assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters"
49
 
50
 
51
shellio.success()