#!/usr/bin/python # # Tests the functionality of the ascii_cat plugin # # To run this test on your own shell, simply run: # # /web/courses/cs3214/spring2015/projects/student-plugins//mzamani1_jamied93/ascii_cat eshoutput.py # # from the directory in which your "esh" and your "eshoutput.py" is located. # It should also be possible to make a copy of that file anywhere, as long as the # 'ascii_cat.so' file is located within the same directory. # # @author Michael Zamani (mzamani1) # @author Jamie Dalrymple (jamied93) # 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 5 seconds c.timeout = 5 ############################################################################# # 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)" ################################################################# # Step 1. Compare output out ascii_cat to expected output. # # expectedoutput_stretch = "\n _,'| _.-''``-...___..--';)" expectedoutput_puma = " _...---.._" expectedoutput_empty = "\nCat ascii_art available: strech, puma" expectedoutput_wrong = "\nNo cat ascii art exists with the provided name." c.sendline("ascii_cat") assert c.expect(expectedoutput_empty) == 0, "ascii_cat produces incorrect output" c.sendline("ascii_cat house") assert c.expect_exact(expectedoutput_wrong) == 0, "ascii_cat house produces incorrect output" c.sendline("ascii_cat stretch") assert c.expect_exact(expectedoutput_stretch) == 0, "ascii_cat stretch produces incorrect output" c.sendline("ascii_cat puma") assert c.expect_exact(expectedoutput_puma) == 0, "ascii_cat puma produces incorrect output" shellio.success()