コード例 #1
0
def getExpectedOutput():
    suite = testCases.getTests()
    out = []
    f = open("expectedOutput.txt", "r+")
    cmd = sys.stdin
    sys.stdin = f
    for i in range(suite.count):
        out.append(input())
    sys.stdin = cmd
    return out
コード例 #2
0
def getExpectedOutput():
	suite = testCases.getTests()
	out=[]
	f=open("expectedOutput.txt" , "r+")
	cmd=sys.stdin
	sys.stdin=f
	for i in range(suite.count):
		out.append(input())
	sys.stdin=cmd
	f.close()
	os.remove("expectedOutput.txt")
	return out
コード例 #3
0
def getInputCache():
	suite = testCases.getTests()
	cache=[]
	f=open("inputCache.txt" , "r+")
	cmd=sys.stdin
	sys.stdin=f
	for i in range(suite.count):
		cache.append(input())
	sys.stdin=cmd
	f.close()
	os.remove("inputCache.txt")
	return cache
コード例 #4
0
import testCases
tests = testCases.getTests()
for i in range(len(tests)):
    print "creating files for " + tests[i].description
    inputStr = ""
    for j in range(len(tests[i].instances)):
        inputStr = inputStr + tests[i].instances[j].inputStr + "\n"
    f = open("test_suite_" + str(i + 1) + ".txt", "w+")
    f.write(inputStr)
    f.close()
コード例 #5
0
import sys
import testCases
#print 'Number of arguments:', len(sys.argv), 'arguments.'
#print 'Argument List:', str(sys.argv)
id=int(sys.argv[1])
#print "got id "+str(id) 
tests=testCases.getTests()
check=1
for i in range(len(tests[id].instances)):
	lines=tests[id].instances[i].outputStr.split("\n")
	for j in range(len(lines)):
		actual=str(raw_input())
		if actual!=lines[j]:
			print '\033[91m'+tests[id].description+" failed at "+tests[id].instances[i].description
			print "Input : \n"+tests[id].instances[i].inputStr
			print "Expected : \n"+tests[id].instances[i].outputStr
			print "Mismatch in line #"+str(j+1)
			print "Got :"+actual
			print '\033[0m'
			check=0
			break
if check==1 :
	print '\033[92m'
	print tests[id].description + " passed"
コード例 #6
0
def getDescription(index):
	suite = testCases.getTests()
	str=suite.description+" failed at "
	str=str+suite.instances[index].description
	return str
コード例 #7
0
			cons.set_text_attr(cons.FOREGROUND_RED | cons.BACKGROUND_GREY)
			print(getDescription(i))
			resultArr[i]="red"
			print("Input: ",inputCache[i])
			print("Expected: ",expected[i])
			print("Got: ",actual[i])
		break
	for j in range(len(expected[i])):
		if expected[i][j]!=actual[i][j]:
			cons.set_text_attr(cons.FOREGROUND_RED | cons.BACKGROUND_GREY)
			print(getDescription(i))
			resultArr[i]="red"
			print("Input: ",inputCache[i])
			print("Expected: ",expected[i])
			print("Got: ",actual[i])
			break
cons.set_text_attr(default_colors) 		
if testCases.getTests().archiving == 1:
	print("Generating Report.")
	reportStr="<h1>"+testCases.getTests().description+"</h1><table border='2'><tr style='background:blue'><th width='100'>Input</th><th width='100'>Expected Output</th><th width='100'>Output Received</th></tr>"
	for i in range(len(expected)):
		reportStr=reportStr+"<tr style='background:"+resultArr[i]+"'><td>"+inputCache[i]+"</td><td>"+expected[i]+"</td><td>"+actual[i]+"</td></tr>"
	reportStr=reportStr+"</table><br>Report generated at "+strftime("%Y-%m-%d %H:%M:%S", gmtime())
	print("Report Generated.\nUse view_report to view latest report.\nTo view all report go to test_archive directory.")
	f=open("test_archive/"+str(time.time())+".html" , "w+")#temporary cache file to store expected output
	f.write(reportStr)
	f.close()
print("End of test.");
cons.set_text_attr(default_colors) 

コード例 #8
0
            print(getDescription(i))
            resultArr[i] = "red"
            print("Input: ", inputCache[i])
            print("Expected: ", expected[i])
            print("Got: ", actual[i])
    elif expected[i] != actual[i]:
        cons.set_text_attr(cons.FOREGROUND_RED | cons.BACKGROUND_GREY)
        print(getDescription(i))
        resultArr[i] = "red"
        print("Input: ", inputCache[i])
        print("Expected: ", expected[i])
        print("Got: ", actual[i])

timeArr.append(time.time())
cons.set_text_attr(default_colors)
if testCases.getTests().archiving == 1:
    print("Generating Report.")
    reportStr = "<table border='2'><tr style='background:blue'><th width='100'>Input</th><th width='100'>Expected Output</th><th width='100'>Output Received</th><th width='100'>Time(in seconds)</th></tr>"
    for i in range(len(expected)):
        reportStr = reportStr + "<tr style='background:" + resultArr[
            i] + "'><td>" + inputCache[i] + "</td><td>" + expected[
                i] + "</td><td>" + actual[i] + "</td><td>" + str(
                    timeArr[i + 1] - timeArr[i]) + "</td></tr>"
    reportStr = reportStr + "</table>"
    print(
        "Report Generated.\nUse view_report to view latest report.\nTo view all report go to test_archive directory."
    )
    f = open("test_archive/" + str(time.time()) + ".html",
             "w+")  #temporary cache file to store expected output
    f.write(reportStr)
    f.close()
コード例 #9
0
		else:
			cons.set_text_attr(cons.FOREGROUND_RED | cons.BACKGROUND_GREY)
			print(getDescription(i))
			resultArr[i]="red"
			print("Input: ",inputCache[i])
			print("Expected: ",expected[i])
			print("Got: ",actual[i])
	elif expected[i]!=actual[i]:
		cons.set_text_attr(cons.FOREGROUND_RED | cons.BACKGROUND_GREY)
		print(getDescription(i))
		resultArr[i]="red"
		print("Input: ",inputCache[i])
		print("Expected: ",expected[i])
		print("Got: ",actual[i])
	
timeArr.append(time.time())	
cons.set_text_attr(default_colors) 		
if testCases.getTests().archiving == 1:
	print("Generating Report.")
	reportStr="<table border='2'><tr style='background:blue'><th width='100'>Input</th><th width='100'>Expected Output</th><th width='100'>Output Received</th><th width='100'>Time(in seconds)</th></tr>"
	for i in range(len(expected)):
		reportStr=reportStr+"<tr style='background:"+resultArr[i]+"'><td>"+inputCache[i]+"</td><td>"+expected[i]+"</td><td>"+actual[i]+"</td><td>"+str(timeArr[i+1]-timeArr[i])+"</td></tr>"
	reportStr=reportStr+"</table>"
	print("Report Generated.\nUse view_report to view latest report.\nTo view all report go to test_archive directory.")
	f=open("test_archive/"+str(time.time())+".html" , "w+")#temporary cache file to store expected output
	f.write(reportStr)
	f.close()
print("End of test.");
cons.set_text_attr(default_colors)