#!/usr/bin/python # # # # # 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 expessions 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 ##spaw 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 Timeout c.timeout = 5 #Tests go below c.sendline("average 1 2 3"); assert c.expect_exact("The average is: 2.000000") == 0, "Incorrect average computed" c.sendline("average 1 2"); assert c.expect_exact("The average is: 1.500000") == 0, "Incorrect output" c.sendline("average"); assert c.expect_exact("Error: must provide numbers for an average") == 0, "case not handled correctly" c.sendline("average three"); assert c.expect_exact("three is not a legitimate number") == 0, "case no handled correctly" c.sendline("average 9999999999") assert c.expect_exact("9999999999 is either too large or too small to be converted into an int") == 0, "case not handled correctly" c.sendline("exit"); shellio.success()