#!/usr/bin/python # # Tests the functionality of temp_converter esh plugin # # Written for CS 3214 Spring 2015. # # To run this test on your own shell, simply run: # # /web/courses/cs3214/spring2015/projects/student-plugins/schung7_mosescho/history eshoutput.py # # from the directory in which your "esh" and your "eshoutput.py" is located. # # @author Steven Chung, Moses Cho # 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 c.sendline("ls") c.sendline('history') assert c.expect('1 ls') == 0, \ "expect temp %s" % ('1 ls') c.sendline("cal") c.sendline('history') assert c.expect("1 ls\r\n2 cal") == 0, \ "expect temp %s" % ('1 ls\r\n2 cal') c.sendline("echo") c.sendline('history') assert c.expect("1 ls\r\n2 cal\r\n3 echo") == 0, \ "expect temp %s" % ('1 ls\r\n2 cal\r\n3 echo') c.sendline("ps") c.sendline('history') assert c.expect("1 ls\r\n2 cal\r\n3 echo\r\n4 ps") == 0, \ "expect temp %s" % ('1 ls\r\n2 cal\r\n3 echo\r\n4 ps') c.sendline("true") c.sendline('history') assert c.expect("1 ls\r\n2 cal\r\n3 echo\r\n4 ps\r\n5 true") == 0, \ "expect temp %s" % ('1 ls\r\n2 cal\r\n3 echo\r\n4 ps\r\n5 true') c.sendline("users") c.sendline('history') assert c.expect("1 cal\r\n2 echo\r\n3 ps\r\n4 true\r\n5 users") == 0, \ "expect temp %s" % ('1 cal\r\n2 echo\r\n3 ps\r\n4 true\r\n5 users') # Exit the test shellio.success()