#group432_reverseEcho_eshoutput.py #!/usr/bin/python # #Brian Green bggreen@vt.edu # # F to C test # Tests 3 cases: positive , zero, negative # #This file needs to be declared in plugins.tst and located in the plugins directory # import sys, imp, atexit, mmap 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 c.sendline("touch ../log") c.sendline("touch ./log") c.sendline("sleep 2") # run commands through a child process child = pexpect.spawn("./esh -p plugins") #redirect output to a log file with open("log","r+")as log_file: child.logfile = log_file child.send("tocelsius 5\n") #test negatives child.expect(".*") child.send("tocelsius 14\n") child.expect(".*") child.send("tocelsius 32\n") #test 0 child.expect(".*") child.send("tocelsius 68\n") #test positive child.expect(".*") child.send("tocelsius \n") child.expect(".*") child.send("\n") # run empty child.expect(".*") a = open("log").read() # grab string for file #test that strings are found for each case in valid locations case1 = a.find("5 in celsius is: -15") != -1 case2 = a.find("14 in celsius is: -10") != -1 case3 = a.find("32 in celsius is: 0") != -1 case4 = a.find("68 in celsius is: 20") != -1 case5 = a.find("Need to type a fahrenheit to convert :(") != -1 assert case1 assert case2 #lame assert case3 assert case4 #lame assert case5 assert log_file.closed shellio.success()