#!/usr/bin/python # # Samyak Singh (ssing94) # Michael Louie (louiem) # # diningHours_test: tests the dining hours plugin. # # Test the dining hour plugin for obtaining local system time # and compare to two test times for recognize in/off hours. # Does not require any additional commands to be implemented # or otherwise unsable. # # Because local system times vary depending on time of testing, # we cannot verify full functionality of plugin. Two test ids # were created (testopen and testclosed) to test if plugin can # obtain the local system time and recognizes that testopen # is opened and testclosed is closed regardless of time. # # SETUP #################################################################################### 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 an instance of the shell c = pexpect.spawn(def_module.shell + plugin_dir, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # TEST #################################################################################### # test "dh"; expecting invocation error message. c.sendline("dh") assert c.expect("Invocation") == 0, "Failed to throw invovcation message!" # test "dh testopen"; expecting print current time and hours for TestOpen. c.sendline("dh testopen") assert c.expect("2399") == 0, "Failed to print a dining hall name and its hour!" # test "dh testopen -t" to recognize opened hours; # expecting print current time, open confirmation, and hours. c.sendline("dh testopen -t") assert c.expect("OPEN") == 0, "Failed to print a dining hall name, its hour, and check if it is open!" # test "dh testclosed"; expecting print current time and hours for TestClosed. c.sendline("dh testclosed") assert c.expect("9000") == 0, "Failed to print a dining hall name and its hour!" # test "dh testclosed -t" to recognize closed hours; # expecting print current time, closed confirmation, and hours. c.sendline("dh testclosed -t") assert c.expect("closed!") == 0, "Failed to print a dining hall name, its hour, and check if it is closed!" shellio.success()