#!/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] 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, drainpty=True, logfile=logfile, args=['-p', 'plugins/']) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 5 # run plugin c.sendline("mad-lib") assert c.expect_exact("Car Manufacturer: ") == 0, "Invalid Input" c.sendline("Ford\n") #assert c.expect_exact("\nNoun (plural): ") == 0 c.sendline("humans\n") #assert c.expect_exact("\nVerb (active): ") == 0 c.sendline("repeating\n") #assert c.expect_exact("\nAdjective: ") == 0 c.sendline("nice\n") #assert c.expect_exact("\nAdjective: ") == 0 c.sendline("tall\n") #assert c.expect_exact("\nNumber: ") == 0 c.sendline("thirty\n") #assert c.expect_exact("\nUnit of Distance (singular): ") == 0 c.sendline("foot\n") #assert c.expect_exact("\nNoun (singular): ") == 0 c.sendline("well\n") #assert c.expect_exact("\nAdjective: ") == 0 c.sendline("strange\n") #assert c.expect_exact("\nNoun (plural): ") == 0 c.sendline("lips\n") #assert c.expect_exact("\nNoun (plural): ") == 0 c.sendline("mouths\n") #assert c.expect_exact("\nUnit of Time (plural): ") == 0 c.sendline("month\n") #assert c.expect_exact("\nNoun (plural): ") == 0 c.sendline("brains\n") #assert c.expect_exact("\nAdjective: ") == 0 c.sendline("cynical\n") # exit c.sendline("exit"); assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters" shellio.success()