#!/usr/bin/python # # this will do integer calculation # # 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 c.timeout = 5 #Test add function c.sendline("cal add 1 10") assert c.expect_exact("11") == 0, "add test failed" #Test sub function c.sendline("cal sub 10 2") assert c.expect_exact("8") == 0, "sub test failed" #Test mul function c.sendline("cal mul 5 10") assert c.expect_exact("50") == 0, "mul test failed" #Test div function c.sendline("cal div 10 10") assert c.expect_exact("1") == 0, "div test failed" # the test was successful shellio.success()