def performOnCurrent(self): for test in self.getRerunMarkedTests(): rerunNumber = test.stateInGui.briefText.split()[-1] pattern = os.path.join( os.getenv("TEXTTEST_TMP"), "*." + rerunNumber + "_from_" + plugins.startTimeString().replace(":", "") + "*") dirs = glob(pattern) if len(dirs) == 1: rerunDir = dirs[0] appDir = os.path.join(rerunDir, test.app.name + test.app.versionSuffix()) if not os.path.isdir(appDir): allAppDirs = glob( os.path.join(rerunDir, test.app.name + "*")) if len(allAppDirs) > 0: allAppVersions = [ d.replace( os.path.join(rerunDir, test.app.name + "."), "") for d in allAppDirs ] raise plugins.TextTestError( "Cannot load data for rerun, version '" + test.app.getFullVersion() + "' could not be found, only version(s) '" + ", ".join(allAppVersions) + "'") if self.loadFrom(test, appDir): continue raise plugins.TextTestError( "Cannot load data for rerun, test " + test.name + " has not yet completed or has been deleted in rerun " + rerunNumber)
def getConfMessageForFile(self, fileName, associatedObject): fileToView = self.getFileToView(fileName, associatedObject) if os.path.isfile(fileToView) or os.path.islink(fileToView): viewTool = self.getViewToolName(fileToView) if viewTool: args = (viewTool, fileToView, associatedObject) maxFileSize = plugins.parseBytes( self.getConfigValue("max_file_size", viewTool)) if maxFileSize >= 0: largestFileSize = self.getLargestFileSize( fileToView, associatedObject) if largestFileSize > maxFileSize: message = "You are trying to view a file of size " + str(largestFileSize) + " bytes, while a limit of " + \ str(maxFileSize) + " bytes is set for the tool '" + \ viewTool + "'. Are you sure you wish to continue?" return message, args return "", args else: raise plugins.TextTestError( "No " + self.getToolDescription() + " is defined for files of type '" + os.path.basename(fileToView).split(".")[0] + "'.\nPlease point the configuration entry '" + self.getToolConfigEntry() + "' at a valid program to view the file.") else: raise plugins.TextTestError( "File '" + os.path.basename(fileName) + "' cannot be viewed as it has been removed in the file system." + self.noFileAdvice())
def getFileName(self): fileName = self.optionGroup.getOptionValue("f") if not fileName: raise plugins.TextTestError("Cannot save selection - no file name specified") elif os.path.isdir(fileName): raise plugins.TextTestError("Cannot save selection - existing directory specified") else: return fileName
def findBugs(self, fileName, execHosts, isChanged, multipleDiffs): if not self.checkUnchanged and not isChanged: self.diag.info("File not changed, ignoring all bugs") return [] if not fileName: self.diag.info( "File doesn't exist, checking only for absence bugs") return self.findAbsenceBugs(self.absentList, execHosts=execHosts, isChanged=isChanged, multipleDiffs=multipleDiffs, tmpDir=None) if not os.path.exists(fileName): raise plugins.TextTestError( "The file '" + fileName + "' does not exist. Maybe it has been removed by an external process. " ) self.diag.info("Looking for bugs in " + fileName) dirname = os.path.dirname(fileName) return self.findBugsInText(open(fileName).readlines(), execHosts=execHosts, isChanged=isChanged, multipleDiffs=multipleDiffs, tmpDir=dirname)
def addContents(self): notebook = Gtk.Notebook() notebook.set_scrollable(True) notebook.popup_enable() docDir = plugins.installationDir("doc") versionInfo = self.readVersionInfo(docDir) for version in reversed(sorted(versionInfo.keys())): buffer = Gtk.TextBuffer() buffer.set_text(versionInfo[version]) textView = Gtk.TextView.new_with_buffer(buffer) textView.set_editable(False) textView.set_cursor_visible(False) textView.set_left_margin(5) textView.set_right_margin(5) scrolledWindow = Gtk.ScrolledWindow() scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolledWindow.add(textView) scrolledWindow.set_shadow_type(Gtk.ShadowType.IN) versionStr = ".".join(map(str, version)) notebook.append_page(scrolledWindow, Gtk.Label(label=self.labelPrefix() + versionStr)) if notebook.get_n_pages() == 0: # pragma : no cover - should never happen raise plugins.TextTestError("\nNo " + self.getTitle() + " could be found in\n" + docDir + "\n") else: parentSize = self.topWindow.get_size() self.dialog.resize(int(parentSize[0] * 0.9), int(parentSize[1] * 0.7)) self.dialog.vbox.pack_start(notebook, True, True, 0)
def getServerAddress(self, optionMap): servAddrStr = optionMap.get("servaddr", os.getenv("CAPTUREMOCK_SERVER")) if not servAddrStr: raise plugins.TextTestError( "Cannot run slave, no server address has been provided to send results to!" ) host, port = servAddrStr.split(":") return host, int(port)
def __init__(self, args): argDict = self.parseArguments(args, ["dest"]) self.otherTTHome = argDict.get("dest") self.otherSuites = {} self.placements = {} if not self.otherTTHome: raise plugins.TextTestError( "Must provide 'dest' argument to indicate where tests should be exported" )
def notifySaveSelection(self, fileName, writeCriteria=False): try: file = open(fileName, "w") if writeCriteria: file.write(self.selectionCriteria + "\n") else: self.writeTestList(file) file.close() except IOError as e: raise plugins.TextTestError("\nFailed to save selection:\n" + str(e) + "\n")
def updateWithBugFile(self, bugFile, ancestors): bugFile.seek(0) bugMap = BugMap() bugMap.readFromFileObject(bugFile) if applyBugsToTests(self.currTestSelection, bugMap): for realFile in ReportBugs.getFiles(self, ancestors): realFile.write(bugFile.getvalue()) realFile.close() else: raise plugins.TextTestError("Information entered did not trigger on the selected test, please try again")
def _getResponderClasses(self, allApps, *args): self.useQueueSystem = self.calculateUseQueueSystem(allApps) if self.useQueueSystem and not self.cloudUseConsistent(allApps): raise plugins.TextTestError( "No support currently for running ec2cloud tests at the same time as tests with other queue systems" ) if self.slaveRun(): return self.getSlaveResponderClasses() else: return default.Config._getResponderClasses(self, allApps, *args)
def getComparisons(self, test): try: # Leave out new ones return test.state.changedResults + test.state.correctResults + test.state.missingResults except AttributeError: raise plugins.TextTestError( "Cannot establish which files should be compared as no comparison information exists.\n" + "To create this information, perform 'recompute status' (press '" + guiutils.guiConfig.getCompositeValue("gui_accelerators", "recompute_status") + "') and try again.")
def getAllProperties(self): errors, properties = [], [] for file, comp in self.currFileSelection: if self.dynamic and comp: self.processFile(comp.tmpFile, properties, errors) self.processFile(comp.stdFile, properties, errors) else: self.processFile(file, properties, errors) if len(errors): raise plugins.TextTestError("Failed to get file properties:\n" + "\n".join(errors)) return properties
def getProcessResults(self, args, **kwargs): try: process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, **kwargs) except OSError: raise plugins.TextTestError( "Could not run " + self.name + ": make sure you have it installed locally") stdout, stderr = process.communicate() return process.returncode, stdout, stderr
def checkSanity(self, app): if self.errorMessage: # We failed already, basically raise plugins.TextTestError(self.errorMessage) runDir = self.findRunDir(app) if not runDir: raise plugins.TextTestWarning("Could not find any runs matching " + app.description()) self.diag.info("Found run directory " + repr(runDir)) self.reconnDir = self.findAppDirUnder(app, runDir) self.diag.info("Found application directory " + repr(self.reconnDir)) if not self.reconnDir: raise plugins.TextTestWarning("Could not find an application directory matching " + app.description() + " for the run directory found at " + runDir) for datedVersion in self.datedVersions: app.addConfigEntry("unsaveable_version", datedVersion)
def getTestProcess(self, test, machine, postfix=""): commandArgs = self.getExecuteCmdArgs(test, machine, postfix) self.diag.info("Running test with args : " + repr(commandArgs)) namingScheme = test.app.getConfigValue("filename_convention_scheme") stdoutStem = test.app.getStdoutName(namingScheme) + postfix stderrStem = test.app.getStderrName(namingScheme) + postfix inputStem = test.app.getStdinName(namingScheme) + postfix testEnv = self.getTestRunEnvironment(test, postfix) try: return subprocess.Popen(commandArgs, preexec_fn=self.getPreExecFunction(), stdin=open(self.getInputFile(test, inputStem)), cwd=test.getDirectory(temporary=1, local=1), stdout=self.makeFile(test, stdoutStem), stderr=self.makeFile(test, stderrStem), env=testEnv, startupinfo=self.getProcessStartUpInfo(test)) except OSError: message = "OS-related error starting the test command - probably cannot find the program " + \ repr(commandArgs[0]) raise plugins.TextTestError(message)
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: self.diag.info("Failed to save, no file at " + tmpFile) raise plugins.TextTestError( "The following file seems to have been removed since it was created:\n" + repr(tmpFile)) self.differenceCache = self.APPROVED
def createView(self): # Initialize for menuName in self.menuNames: realMenuName = menuName if not menuName.isupper(): realMenuName = menuName.capitalize() self.actionGroup.add_action( Gtk.Action(menuName + "menu", "_" + realMenuName, None, None)) self.createToggleActions() for file in self.getGUIDescriptionFileNames(): try: self.diag.info("Reading UI from file " + file) self.uiManager.add_ui_from_file(file) except Exception as e: raise plugins.TextTestError( "Failed to parse GUI description file '" + file + "': " + str(e)) self.uiManager.ensure_update() self.widget = self.uiManager.get_widget("/MainMenuBar") return self.widget
def getModified(self, fullLine, dir): trafficType = fullLine[2:5] args = [self.script, fullLine[6:]] if os.name == "nt": interpreter = plugins.getInterpreter(self.script) if interpreter: args = [interpreter] + args if trafficType in self.trafficTypes: proc = subprocess.Popen(args, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if len(stderr) > 0: raise plugins.TextTestError( "Couldn't modify traffic :\n " + str(stderr, getpreferredencoding())) else: return fullLine[:6] + str(stdout, getpreferredencoding()) else: return fullLine
def setUpCaptureMock(self, test, interceptDir, rcFiles): extReplayFile = test.getFileName("traffic") if extReplayFile: # "Legacy" setup to avoid the need to rename hundreds of files extRecordFile = test.makeTmpFileName("traffic") pyReplayFile = extReplayFile pyRecordFile = extRecordFile else: extReplayFile = test.getFileName("externalmocks") extRecordFile = test.makeTmpFileName("externalmocks") pyReplayFile = test.getFileName("pythonmocks") pyRecordFile = test.makeTmpFileName("pythonmocks") recordEditDir = test.makeTmpFileName("file_edits", forComparison=0) replayEditDir = test.getFileName( "file_edits") if extReplayFile else None sutDirectory = test.getDirectory(temporary=1, local=1) capturemock_path = test.getConfigValue("capturemock_path") if capturemock_path: sys.path.insert(0, capturemock_path) try: from capturemock import setUpServer, setUpPython externalActive = setUpServer(self.recordSetting, extRecordFile, extReplayFile, recordEditDir=recordEditDir, replayEditDir=replayEditDir, rcFiles=rcFiles, interceptDir=interceptDir, sutDirectory=sutDirectory, environment=test.environment) pythonActive = setUpPython(self.recordSetting, pyRecordFile, pyReplayFile, rcFiles=rcFiles, environment=test.environment) return externalActive or pythonActive except ImportError as e: raise plugins.TextTestError( "Test requires CaptureMock to be installed, but the capturemock module could not be found\nError was: " + str(e) + "\nSearched in " + repr(sys.path))
def __init__(self, app): if shutil.which(self.submitProg) is None: raise plugins.TextTestError("Cannot submit TextTest tests to grid engine: '" + self.submitProg + "' not installed!") self.coreFileLocation = self.getCoreFileLocation(app)
def getProgramArgs(self): if self.errorMessage: raise plugins.TextTestError(self.errorMessage) else: return self.programArgs
def performOnCurrent(self): backupVersions = self.getBackupVersions() if self.optionGroup.getOptionValue("v") in backupVersions: raise plugins.TextTestError( "Cannot backup to the same version we're trying to approve! Choose another name." )