#/usr/bin/python # # Tests for the counter esh plug-in # # To run this test on your own shell, simply run: # # ~cs3214/public_html/spring2015/projects/student-plugins/crc1559_cgibs13/counter/counter_test.py eshoutput.py # # from the directory in which your "esh" and your "eshoutput.py" is located. # #====== # Setup #====== import sys, imp, atexit, os sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check 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] 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, drainpty=True, logfile=logfile, args=['-p', thisdir]) atexit.register(force_shell_termination, shell_process=c) c.timeout = 2 ############################################################################# # Now the real test starts! # # ensure that shell prints expected prompt #======== # Testing #======== # Run the counter plug-in c.sendline("counter wordyo") assert c.expect('6 characters') == 0 # Throw a two word command c.sendline("counter word1 word2") assert c.expect('11 characters') == 0 # Exit the test shellio.success()