#!/usr/bin/python # # colorme plugin for esh by Matt Favero and Ransom Roberson # For CS 3214 Spring 2015 Project 1 # # Usage # ---- # Invoke as # # /web/courses/cs3214/spring2015/projects/student-plugins/mafavero/roulette/mafavero_colormetest.py eshoutput.py # # from the directory of esh # 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)" c.sendline("colorme red"); assert c.expect_exact("Changing color to ... \x1b[0;31mred!") == 0, "First command doesn't successfully execute (2)"; c.sendline("colorme clear"); assert c.expect_exact("Changing color to ... \x1b[0mclear!") == 0, "Second command doesn't successfully execute (3)"; shellio.success();