#!usr/bin/python # # picker test: Tests the picker builtin plugin # # Tests valid inputs: 2+ options entered (all separated by spaces) # Tests invalid inputs: nothing input, only 1 input # 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_prcess=c) # Set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # Test magic8 with no question c.sendline("picker") assert c.expect_exact("How can I pick if you don't give me any choices?") == 0, "User did not enter any options" # Test magic8 with invalid question c.sendline("picker turner") assert c.expect_exact("Of course I'm going to pick 'turner'!\nThat's the only choice you gave me!") == 0, "User only entered one option" # Test magic8 with a valid question # Random option is returned c.sendline("picker turner owens westend") options = ["turner", "owens", "westend"] flag = 1 for o in options: flag = c.expect_exact(a) if flag == 0: break; assert flag == 0, "User entered valid options and received a decision" # 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();