def assertFilesEqual(self, pan1, pan2, comment=""): """ Do two files contain the same data? (maybe we should use diff for long files?) @param pan1 [string] = filename or pathname for 1st file @param pan2 [string] = filename or pathname for 2nd file @param comment [string] """ data1 = butil.readFile(pan1) data2 = butil.readFile(pan2) if data1 == data2: self.passedTest("%s; files <%s> and <%s> contain the same data" % (comment, pan1, pan2)) else: msg = "FAILED: %s; files <%s>, <%s> contain different data"\ % (comment, pan1, pan2) raise AssertionError(msg)
def readModLog() -> ModLog: """ read the modlog file """ if butil.fileExists(MODLOG_PN): mlStr = butil.readFile(MODLOG_PN) ml = json.loads(mlStr) return ml else: prn("Mod log file <%s> doe not exist.", MODLOG_PN) return []
def assertFilesEqual(self, pan1, pan2, comment=""): """ Do two files contain the same data? (maybe we should use diff for long files?) @param pan1 [string] = filename or pathname for 1st file @param pan2 [string] = filename or pathname for 2nd file @param comment [string] """ data1 = butil.readFile(pan1) data2 = butil.readFile(pan2) if data1 == data2: self.passedTest("%s; files <%s> and <%s> contain the same data" % (comment, pan1, pan2)) else: msg = "FAILED: %s; files <%s>, <%s> contain different data"\ % (comment, pan1, pan2) raise AssertionError, msg
def loadArticles(): """ load articles from the euro election top-level directory """ #print "loadArticles()" topDir = "/home/phil/proj/euroelection/articles" allFns = os.listdir(topDir) artFns = [fn for fn in allFns if fn.endswith(".art")] #print "loadArticles() artFns=%r" % (artFns,) for artFn in artFns: artPn = topDir+"/"+artFn #print "loading articles in <%s>..." % (artPn,) artFStr = butil.readFile(topDir+"/"+artFn) readArticles(artFStr)
def assertFileHasData(self, pan, data, comment=""): """ Are the contents of file (pan) equal to (data)? @param pan [string] = a full pathname to a file @param data [string] = what is supposed to be in the file """ dataInFile = butil.readFile(pan) difDisplay = "%r" % (dataInFile, ) if len(dataInFile) > 80: difDisplay = "%d chars starting with %r" \ % (len(dataInFile), dataInFile[:80]) if dataInFile == data: self.passedTest("%s; file <%s> has data: %s" % (comment, pan, difDisplay)) else: dataDisplay = "%r" % (data, ) if len(data) > 80: dataDisplay = "%d chars starting with %r" \ % (len(data), data[:80]) msg = "FAILED: %s; file <%s> contains: %s\nshould be: %s"\ % (comment, pan, difDisplay, dataDisplay) raise AssertionError(msg)
def assertFileHasData(self, pan, data, comment=""): """ Are the contents of file (pan) equal to (data)? @param pan [string] = a full pathname to a file @param data [string] = what is supposed to be in the file """ dataInFile = butil.readFile(pan) difDisplay = "%r" % (dataInFile,) if len(dataInFile) > 80: difDisplay = "%d chars starting with %r" \ % (len(dataInFile), dataInFile[:80]) if dataInFile == data: self.passedTest("%s; file <%s> has data: %s" % (comment, pan, difDisplay)) else: dataDisplay = "%r" % (data,) if len(data) > 80: dataDisplay = "%d chars starting with %r" \ % (len(data), data[:80]) msg = "FAILED: %s; file <%s> contains: %s\nshould be: %s"\ % (comment, pan, difDisplay, dataDisplay) raise AssertionError, msg
def loadFile(self, filename): if debug: print "loading <%s>" % (filename,) fileContents = butil.readFile(filename) self.readEval(fileContents)