#!/usr/bin/python # # Samyak Singh (ssing94) # Michael Louie (louiem) # # quote_test: tests the quotes plugin. # # Test the quotes plugin to print famous quotes. # Does not require any additional commands to be implemented # or otherwise unsable. # # SETUP #################################################################################### 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 timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # TEST #################################################################################### # test "quote obama" c.sendline("quote obama"); assert c.expect("Why can't I just eat my waffle?") == 0, "Shell did not print expected quote from Obama." # test "quote mlk" c.sendline("quote mlk"); assert c.expect("Injustice anywhere is a threat to justice everywhere.") == 0, "Shell did not print expected quote from MLK." # test "quote oprah" c.sendline("quote oprah"); assert c.expect("Turn your wounds into wisdom.") == 0, "Shell did not print expected quote from Oprah." # test "quote lincoln" c.sendline("quote lincoln"); assert c.expect("I destroy my enemies when I make them my friends.") == 0, "Shell did not print expected quote from Lincoln." # test "quote jfk" c.sendline("quote jfk"); assert c.expect("Forgive your enemies, but never forget their names.") == 0, "Shell did not print expected quote from JFK." shellio.success()