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) c.timeout = 5 # run a command c.sendline("tempCon -F 32") # Test Fahrenheit assert c.expect("Your temperature in Fahrenheit is: 32.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in celcius is: 0.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in rankine is: 491.67") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in kelvin is: 273.15") == 0, "Shell did not print expected prompt" c.sendline("tempCon -R 212") # Test rankine assert c.expect("Your temperature in Fahrenheit is: -247.67") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in celcius is: -149.82") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in rankine is: 212.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in kelvin is: 117.78") == 0, "Shell did not print expected prompt" c.sendline("tempCon -K 100") # Test kelvin assert c.expect("Your temperature in Fahrenheit is: -279.67") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in celcius is: -173.15") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in rankine is: 180.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in kelvin is: 100.00") == 0, "Shell did not print expected prompt" c.sendline("tempCon -C 50") #Test celcius assert c.expect("Your temperature in Fahrenheit is: 122.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in celcius is: 50.00") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in rankine is: 581.67") == 0, "Shell did not print expected prompt" assert c.expect("Your temperature in kelvin is: 323.15") == 0, "Shell did not print expected prompt" c.sendline("tempCon -n") assert c.expect("Try -k for kelvin, -C for celcius, -F for Fahrenheit, -R for rankine") == 0, "Shell did not print expected prompt" c.sendline("tempCon -n 12") #wrong input assert c.expect("You gave this plugin the wrong parameters") == 0, "Shell did not print expected prompt"