#usr/bin/python # # # wClock_test: the wClock test command # # Test the wClock plugin for proper output and status messages. # import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check #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] plugin_dir = sys.argv[2] def_module = imp.load_source('', definitions_scriptname) logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile # spawn instance of bash. PS1 is the env variable from which bash # draws it's prompt c = pexpect.spawn(def_module.shell + plugin_dir, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) #Set timeout c.timeout = 5 #Start Tests Here assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt" c.sendline("wClock") assert c.expect("Error: Must input a UTC offset") == 0, "Incorrect output from shell" c.sendline("wClock abc") assert c.expect_exact("abc is not a valid UTC offset, type 'wClock' for help") == 0, "incorrect output from shell" #Regex needed for this line because time will constantly change. c.sendline("wClock UTC-5") #Makes sure the line matches the format specified. (caught) = shellio.parse_regular_expression(c, def_module.catch_everything_regex) shellio.success()