#!/usr/bin/python # # WhatDoesTheFoxSay test: Tests the WhatDoesTheFoxSay builtin plugin # # This test will test the WhatDoesTheFoxSay plugin on your shell # Tests a few valid inputs for the animal with # their respective output. Also checks the error messages # when there is no input or input is not a builtin animal, the # input is not a string, or if no argument is entered. 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] 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, drainpty=True, logfile=logfile, args=['-p', 'plugins/']) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 #test WhatDoesTheFoxSay for the supported animals c.sendline("FoxSays cat") assert c.expect_exact("Cat goes Meow!") == 0, "correct player name not printed by command" c.sendline("FoxSays dog") assert c.expect_exact("Dog goes Woof!") == 0, "correct player name not printed by command" c.sendline("FoxSays seal") assert c.expect_exact("Seal goes Ow Ow Ow!") == 0, "correct player name not printed by command" #Test VTPlayer with incorrect arguments #if no argument entered c.sendline("FoxSays") assert c.expect_exact("Fox needs a animal to talk about!") == 0, "wrong statement for when FoxSays has no input" #if the argument is not a supported animal / string c.sendline("FoxSays ant") assert c.expect_exact("Fox has nothing to say!") == 0, "wrong statement when fox does not have anything to say" #if the argument is not a string c.sendline("FoxSays 1") assert c.expect_exact("Fox says that isn't a animal!") == 0, "wrong statement when Foxsays has numbers inputed into it" # end the shell program by sending it an end-of-file character c.sendline("exit"); # ensure that no extra characters are output after exiting assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters" # the test was successful shellio.success()