#!/usr/bin/python # # This is the test file for the letsgo command. It checks to ensure that the output for the command is right for all user inputs. To run this test on your own shell, simply run: # # /web/courses/cs3214/spring2015/projects/student-plugins/chrispc_kbuch5/letsgo/chrispc_kbuch5_letsgo_test.py eshoutput.py # # from your esh directory. # # @author chrispc # @author kbuch5 # 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]) c.timeout = 2 atexit.register(force_shell_termination, shell_process=c) assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (1)" # launch letsgo. c.sendline("letsgo") #ensure the prompt is created. assert c.expect("Let's Go! ") == 0, "The prompt is incorrect."; #send the command an incorrect answer. c.sendline("Wrong") #ensure the command prints the correct result and the prompt. assert c.expect("Incorrect. Enter 'Help' for a hint. Try again:") == 0, "The print for incorrect answers is incorrect." assert c.expect("Let's Go! ") == 0, "The prompt is incorrect." #send the command an a request for 'help'. c.sendline("Help") #ensure the command prints the correct result and the prompt. assert c.expect("Who Invents The Future?") == 0, "The print for 'help' is incorrect." assert c.expect("Let's Go! ") == 0, "The prompt is incorrect." #send the correct input c.sendline("Hokies") #verify that the command printed the correct output. assert c.expect(" _ ____ _______ _ ____ ______ _____") == 0, "The print for 'Hokies' is incorrect: line 1" shellio.success()