Rev 45 | Blame | Last modification | View Log | Download | RSS feed
#!/p/python/pythonimport osimport randomimport cStringIOimport parseinputimport tallyimport votedef testfile(dirpath, filename):print filename + ":",tally.fdOut = cStringIO.StringIO()filenameCSV = os.path.join(dirpath, filename)filenameOut = os.path.splitext(filenameCSV)[0] + ".out"nWinners, ballots = parseinput.parsefile(filenameCSV)random.seed(1)vote.domany(10, nWinners, ballots)tally.trace("")vote.doone(nWinners, ballots)result = tally.fdOut.getvalue()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):for dirpath, dirnames, filenames in os.walk(dir):for filename in filenames:if filename.endswith(".csv"):testfile(dirpath, filename)if __name__=="__main__":main("tests")