#!/usr/bin/python # # Test for the stutter plugin # @author Julius Phu # @author Omid Anvar import sys, imp, atexit, os sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check # Determine the path this file is in thisdir = os.path.dirname(os.path.realpath(__file__)) #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) # pulling in the regular expression and other definitions # this should be the eshoutput.py file of the hosting shell, see usage above definitions_scriptname = sys.argv[1] def_module = imp.load_source('', definitions_scriptname) # you can define logfile=open("log.txt", "w") in your eshoutput.py if you want logging! logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile #spawn an instance of the shell, note the -p flags c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile, args=['-p', thisdir]) atexit.register(force_shell_termination, shell_process=c) ########################################################################################### # Tests catching of too few arguments c.sendline("stutter") assert c.expect("Too few arguments") == 0, "Doesn't catch number of arguments error" # Tests putting something thats not a natural number as the first argument c.sendline("stutter 0 hello") assert c.expect("Sorry") == 0, "Doesn't validate first argument" # Tests one word c.sendline("stutter 3 hello") assert c.expect("hehehehello") == 0, "Works incorrectly with one word" # Tests multiple words c.sendline("stutter 2 hello world") assert c.expect("hehehello wowoworld") == 0, "Works incorrectly with multiple words" # Tests a one letter word c.sendline("stutter 4 a") assert c.expect("aaaa") == 0, "Works incorrectly with one letter words" ########################################################################################### shellio.success()