def generateGraph(self, fileName, graphTitle, results, colourFinder): plugins.log.info("Generating graph at " + fileName + " ...") graph = Graph(graphTitle, width=24, height=20) self.addAllPlots(graph, results, colourFinder) self.addDateLabels(graph, results) plugins.ensureDirExistsForFile(fileName) graph.save(fileName)
def ensureLocationFileExists(self, fileName, dataDirName=""): locationFile = os.path.join(self.location, fileName) if not os.path.isfile(locationFile): plugins.ensureDirExistsForFile(locationFile) plugins.log.info("No file at '" + locationFile + "', copying default file from installation") includeSite, includePersonal = self.inputOptions.configPathOptions() srcFile = plugins.findDataPaths([fileName], includeSite, includePersonal, dataDirName)[-1] shutil.copyfile(srcFile, locationFile) return locationFile
def saveFileEdits(self, test, versionString): tmpFileEditDir = test.makeTmpFileName("file_edits", forComparison=0) fileEditDir = test.dircache.pathName("file_edits") if versionString: fileEditDir += "." + versionString if os.path.isdir(tmpFileEditDir): for root, _, files in os.walk(tmpFileEditDir): for file in sorted(files): fullPath = os.path.join(root, file) savePath = fullPath.replace(tmpFileEditDir, fileEditDir) self.updateStatus(test, "edited file " + file, versionString) plugins.ensureDirExistsForFile(savePath) shutil.copyfile(fullPath, savePath)
def copyTestContents(self, test, newDir): stdFiles, defFiles = test.listApprovedFiles(allVersions=True) for sourceFile in stdFiles + defFiles: dirname, local = os.path.split(sourceFile) if dirname == test.getDirectory(): targetFile = os.path.join(newDir, local) shutil.copy2(sourceFile, targetFile) extFiles = test.listExternallyEditedFiles()[1] dataFiles = test.listDataFiles() + extFiles for sourcePath in dataFiles: if os.path.isdir(sourcePath): continue targetPath = sourcePath.replace(test.getDirectory(), newDir) plugins.ensureDirExistsForFile(targetPath) shutil.copy2(sourcePath, targetPath)
def saveFileEdits(self, test, versionString): tmpFileEditDir = test.makeTmpFileName("file_edits", forComparison=0) fileEditDir = test.dircache.pathName("file_edits") if versionString: fileEditDir += "." + versionString if os.path.isdir(fileEditDir) and test.app.isRecording(): # Recording that we've approved the CaptureMock part of. Don't let files from previous recordings get left behind! shutil.rmtree(fileEditDir) if os.path.isdir(tmpFileEditDir): for root, _, files in os.walk(tmpFileEditDir): for file in sorted(files): fullPath = os.path.join(root, file) savePath = fullPath.replace(tmpFileEditDir, fileEditDir) self.updateStatus(test, "edited file " + file, versionString) plugins.ensureDirExistsForFile(savePath) shutil.copyfile(fullPath, savePath)
def directoryUnserialise(rootDir, f): currFile = None for line in f: if currFile is not None: if line.startswith(endPrefix + fileText): currFile.close() currFile = None else: currFile.write(line) else: if line.startswith(fileText): fn = line.strip().split()[-1] path = os.path.join(rootDir, fn) plugins.ensureDirExistsForFile(path) currFile = open(path, "w") elif line.startswith(endPrefix + dirText): break
def saveTmpFile(self, test, exact=True): self.diag.info("Saving tmp file to " + self.stdFile + ", exact=" + repr(exact)) plugins.ensureDirExistsForFile(self.stdFile) # Allow for subclasses to differentiate between a literal overwrite and a # more intelligent save, e.g. for performance. Default is the same for exact # and inexact save tmpFile = self.getTmpFileForSave(test) if os.path.isfile(tmpFile): if exact: copyfile(tmpFile, self.stdFile) else: self.saveResults(tmpFile, self.stdFile) else: raise plugins.TextTestError, "The following file seems to have been removed since it was created:\n" + repr( tmpFile) self.differenceCache = self.APPROVED
def intercept(self, moduleFile, interceptDir): interceptName = os.path.join(interceptDir, os.path.basename(moduleFile)) plugins.ensureDirExistsForFile(interceptName) self.copyOrLink(moduleFile, interceptName)
def writeCache(self, jobName, buildName, updatedHashes): cacheFileName = self.getCacheFileName(jobName, buildName) from texttestlib import plugins plugins.ensureDirExistsForFile(cacheFileName) with open(cacheFileName, "w") as f: pprint(updatedHashes, f)