# This tests the functionality of the 'simple_interest' esh plugin # Written for CS 3214 Spring 2015 # # To run the test on your own shell, add the test to your plugins.tst and simply run: # # $ cp /web/courses/cs3214/spring2015/projects/student-plugins/alisiraj_neily1/ffc/ffc_test.py # $ cd # $ ~cs3214/bin/stdriver.py -p plugins/ plugins.tst # # from the directory that your "esh" and "eshoutput.py" are in. # # @author Siraj Ali, Neil Yavorski # import sys, imp, atexit 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 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 timeout c.timeout = 2 ############################################################################# # Now the real test starts! # # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (1)" #check to see if the output of the 'ffc' command is correct c.sendline("simple_interest") assert c.expect("usage: simple_interest Principal_Amt interest rate/yr years") == 0, "usage didn't print correctly" c.sendline("simple_interest 5000 .03 5") assert c.expect("Interest: 750.00") == 0, "should be 750" c.sendline("simple_interest 1239.21 .00142 25") assert c.expect("Interest: 43.99") == 0, "should be 43.99" c.sendline("simple_interest 212.94 .0033 4") assert c.expect("Interest: 2.81") == 0, "should be 2.81" # Exit the test shellio.success()