#!/usr/bin/python # # Block header comment # # import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) #pulling in the regular expression and other definitions definitions_scriptname = sys.argv[1] plugin_dir = sys.argv[2] def_module = imp.load_source('', definitions_scriptname) logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile #spawn an instance of the shell c = pexpect.spawn(def_module.shell + plugin_dir, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # set the shell timeout for expect calls c.timeout = 2 # ensure that the shell loaded the plugin assert c.expect("Plugin 'areyousure' initialized...") == 0, "plugin did not initialize" # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" # try running a command c.sendline("echo The command ran") # make sure the command shows up assert c.expect("echo The command ran\r\n") == 0, "The shell did not get the command" # ensure that shell prints the expected plugin output assert c.expect(def_module.plugin_prompt) == 0, "Plugin did not print expected output" # respond yes so that the command will run. c.sendline("y") # ensure that the command ran assert c.expect("The command ran") == 0, "The command did not run" # try running another command c.sendline("sleep 20") # ensure that shell prints the expected plugin output assert c.expect(def_module.plugin_prompt) == 0, "Plugin did not print expected output" # respond no this time c.sendline("n") # the prompt shour display right away assert c.expect(def_module.prompt) == 0, "Shell did not return to prompt" # now exit the shell c.sendline("exit") c.sendline("y") shellio.success()