#!/usr/bin/python # # Tests the functionality of gback's glob module # # This functions as a template for your own tests. # # Written for CS 3214 Spring 2015. # # To run this test on your own shell, simply run: # # /web/courses/cs3214/spring2015/projects/student-plugins/gback/glob/gback_glob_test.py 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 # 'glob.so' file is located within the same directory. # # @author gback # 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 # # Actual Tests # # Checks to see if it can correctly convert the integer "57" to roman numerals c.sendline("convertIntToRmNum 57") assert c.expect("LVII") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "1" to roman numerals c.sendline("convertIntToRmNum 1") assert c.expect("I") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "5" to roman numerals c.sendline("convertIntToRmNum 5") assert c.expect("V") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "9" to roman numerals c.sendline("convertIntToRmNum 9") assert c.expect("IX") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "10" to roman numerals c.sendline("convertIntToRmNum 10") assert c.expect("X") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "40" to roman numerals c.sendline("convertIntToRmNum 40") assert c.expect("XL") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "50" to roman numerals c.sendline("convertIntToRmNum 50") assert c.expect("L") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "90" to roman numerals c.sendline("convertIntToRmNum 90") assert c.expect("XC") == 0, "convertIntToRmNum failed" # Checks to see if it can correctly convert the integer "100" to roman numerals c.sendline("convertIntToRmNum 100") assert c.expect("C") == 0, "convertIntToRmNum failed" # Exit the test shellio.success()