Rev 22 | Rev 45 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/p/python/pythonimport osimport randomimport parseinputimport tallydef testfile(dirpath, filename):print filename + ":",filenameCSV = os.path.join(dirpath, filename)filenameOut = os.path.splitext(filenameCSV)[0] + ".out"result = tallyfile(filenameCSV)handleresult(result, filename, filenameOut)def tallyfile(filenameCSV):nWinners, ballots = parseinput.parsefile(filenameCSV)random.seed(1)return str(tally.dotally(nWinners, ballots)) + "\n"def handleresult(result, filename, filenameOut):if os.path.isfile(filenameOut):fOut = open(filenameOut)correct = fOut.read()if result == correct:print "OK"else:print "***** MISMATCH *****"print " EXPECTED:", correctprint " GOT: ", resultelse:print "***** Creating output for " + filename + ": " + result,fOut = open(filenameOut, "w")fOut.write(result)def main(dir):tally.fTrace = 0for dirpath, dirnames, filenames in os.walk(dir):for filename in filenames:if filename.endswith(".csv"):testfile(dirpath, filename)if __name__=="__main__":main("tests")