#Tests for the relative prime esh plug-in # # To run this test on your own shell, simply run: # # web/courses/cs3214/projects/spring2015/projects/student-plugins/brannon1_jjann93/relative_prime_test.py eshoutput.py # # from the directory in which your "esh" and your "eshoutput.py" is located. # @author Brannon and John # #====== # Setup #====== 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) # set timeout for all following 'expect*' calls to 2 seconds 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)" #======== # Testing #======== # Base test the nCr plugin c.sendline("rp 2") assert c.expect("The relative prime numbers of 2 between 1 and 2 are: 1"), \ "expect relative prime %s" % ('1') # Try with bigger values c.sendline("rp 8") assert c.expect("The relative prime numbers of 8 between 1 and 8 are: 1, 3, 5, 7"), \ "expect relative prime %s" % ('8') #Try with prime c.sendline("rp 5") assert c.expect("The relative prime numbers of 5 between 1 and 5 are: 1 2 3 4"), \ "expect relative prime %s" % ('5') # Test for errors # Not enough arguments given c.sendline("rp") assert c.expect("Need an arguments for relative prime"), \ "expect error message" # Not positive integer values c.sendline("rp -1") assert c.expect("Need an integer greater than 1"), \ "expect error message" c.sendline("rp asedfasd") assert c.expect("Need an integer greater than 1"), \ "expect error message" # Exit the test shellio.success()