diff --git a/Code/Tools/DOI/doi.py b/Code/Tools/DOI/doi.py index 8e55bbda69b8..523d8c6399e9 100644 --- a/Code/Tools/DOI/doi.py +++ b/Code/Tools/DOI/doi.py @@ -97,7 +97,7 @@ def build_xml_form(doi, relationships, creator_name_list, version_str): identifier.text = doi identifier.set('identifierType', 'DOI') - # Creators are defined as "the main researchers involved in producing the + # Creators are defined as "the main researchers involved in producing the # data, or the authors of the publication, in priority order". Allowed # values are "a corporate/institutional or personal name". # @@ -384,7 +384,7 @@ def run(options): creator_name_list = authors.authors_up_to_git_tag(tag) # In the case of the main DOI we need to add the whitelisted names too. creator_name_list = sorted(set(creator_name_list + authors.whitelist)) - + xml_form = build_xml_form(doi, {}, creator_name_list, None) create_or_update_metadata(xml_form, server_url_base, doi, options) @@ -401,7 +401,7 @@ def run(options): relationships = { main_doi : 'IsPartOf' } if has_previous_version: relationships[prev_doi] = 'IsNewVersionOf' - + creator_name_list = authors.authors_under_git_tag(tag) xml_form = build_xml_form( doi, @@ -417,11 +417,11 @@ def run(options): # Create/update the metadata and DOI of the previous version, if it # was found to have a DOI. if has_previous_version: - prev_relationships = { + prev_relationships = { main_doi : 'IsPartOf', doi : 'IsPreviousVersionOf' } - + prev_creator_name_list = authors.authors_under_git_tag(prev_tag) prev_xml_form = build_xml_form( prev_doi, diff --git a/Code/Tools/DefaultConfigFiles/configToCpp.py b/Code/Tools/DefaultConfigFiles/configToCpp.py index 901ba88b7675..6cd03a271650 100644 --- a/Code/Tools/DefaultConfigFiles/configToCpp.py +++ b/Code/Tools/DefaultConfigFiles/configToCpp.py @@ -7,8 +7,8 @@ with open(sys.argv[2]) as f: for line in f: - line = line.rstrip('\n') - if line == "": - print sys.argv[1] + " << std::endl;" - else: - print sys.argv[1] + " << \"" + line + "\" << std::endl;" + line = line.rstrip('\n') + if line == "": + print sys.argv[1] + " << std::endl;" + else: + print sys.argv[1] + " << \"" + line + "\" << std::endl;" diff --git a/Code/Tools/PeriodicTable/generate_atom_code.py b/Code/Tools/PeriodicTable/generate_atom_code.py index 099f19c09549..030cb3c39b70 100755 --- a/Code/Tools/PeriodicTable/generate_atom_code.py +++ b/Code/Tools/PeriodicTable/generate_atom_code.py @@ -96,7 +96,7 @@ def readExisting(filename): # read in an existing file (code_before, code_after) = readExisting(filename) - + # setup the file for the elements and isotopes print "writing information to %s" % filename handle = open(filename, 'w') diff --git a/Code/Tools/Pylint/run_pylint.py b/Code/Tools/Pylint/run_pylint.py index d86d712b0aaa..4af4d89a1555 100644 --- a/Code/Tools/Pylint/run_pylint.py +++ b/Code/Tools/Pylint/run_pylint.py @@ -144,7 +144,7 @@ def main(argv): def parse_arguments(argv): """ Parse arguments for script input - + Args: argv (list): List of strings giving command line arguments """ @@ -227,7 +227,7 @@ def setup_mantidpath(mantidpath): os.environ["MANTIDPATH"] = mantidpath cur_pypath = os.environ.get("PYTHONPATH", "") # for subprocesses - os.environ["PYTHONPATH"] = mantidpath + os.pathsep + cur_pypath + os.environ["PYTHONPATH"] = mantidpath + os.pathsep + cur_pypath sys.path.insert(0, mantidpath) # for current process #------------------------------------------------------------------------------ @@ -272,7 +272,7 @@ def run_checks(targets, serializer, options): Run pylint on the chosen targets Args: - targets (list): A list of relative directory/file targets relative + targets (list): A list of relative directory/file targets relative to options.basedir serializer (file-like): An object with a write method that will receive the output diff --git a/Code/Tools/TestViewer/main_window.py b/Code/Tools/TestViewer/main_window.py index 35032e49af47..06bbb4291e5d 100644 --- a/Code/Tools/TestViewer/main_window.py +++ b/Code/Tools/TestViewer/main_window.py @@ -28,7 +28,7 @@ class TestWorker(QtCore.QThread): def __init__(self, parent = None): QtCore.QThread.__init__(self, parent) self.exiting = False - + #----------------------------------------------------------------------------- def set_parameters(self, mainWindow, selected_only=False, make_tests=True, parallel=False): """Set the parameters of how the tests will be built and run; @@ -39,11 +39,11 @@ def set_parameters(self, mainWindow, selected_only=False, make_tests=True, paral self.parallel = parallel self.mainWindow = mainWindow return test_info.all_tests.run_tests_computation_steps(selected_only, make_tests) - + #----------------------------------------------------------------------------- def test_run_callback(self, obj): """ Simple callback for running tests. This is called into the MainProcess. - + Parameters: obj :: the object, either a TestSuite or TestProject that was just calculated """ @@ -51,25 +51,25 @@ def test_run_callback(self, obj): suite = obj text = "%s done." % suite.classname test_info.all_tests.replace_suite(suite) - + elif isinstance(obj, TestProject): pj = obj # Replace the project in THIS thread! test_info.all_tests.replace_project( pj ) text = "Made project %s" % pj.name - + else: - text = str(obj) - + text = str(obj) + self.mainWindow.emit( QtCore.SIGNAL("testRun"), text, obj) - + #----------------------------------------------------------------------------- def run(self): print "Test Run started..." - test_info.all_tests.run_tests_in_parallel(self.selected_only, self.make_tests, + test_info.all_tests.run_tests_in_parallel(self.selected_only, self.make_tests, self.parallel, callback_func=self.test_run_callback) - - + + @@ -93,52 +93,52 @@ def set_monitor_tests(self, state): #----------------------------------------------------------------------------- def run(self): print "Beginning to monitor files and/or libraries..." - + while not self.exiting: if not self.mainWindow.running: # Don't monitor files while a test suite is building or running if self.monitor_tests: if test_info.all_tests.is_source_modified(selected_only=True): self.mainWindow.emit( QtCore.SIGNAL("testMonitorChanged()") ) - - + + time.sleep(self.delay) - - - - - - + + + + + + #================================================================================================== #================================================================================================== -class TestViewerMainWindow(QtGui.QMainWindow, ui_main_window.Ui_MainWindow): +class TestViewerMainWindow(QtGui.QMainWindow, ui_main_window.Ui_MainWindow): """ The main GUI window of the test viewer. """ - def __init__(self, settings=None, bin_folder="", source_folder="", parent=None): + def __init__(self, settings=None, bin_folder="", source_folder="", parent=None): QtGui.QWidget.__init__(self, parent) - + # Save the settings object self.settings = settings self.bin_folder = bin_folder self.source_folder = source_folder - + # Populate all GUI elements self.setupUi(self) self.buttonTest.hide() self.set_running(False) - + # Create the worker self.worker = TestWorker() - + # Now the file monitor self.monitor_worker = TestMonitorFilesWorker(self) self.monitor_worker.start() - + self.connect(self.worker, QtCore.SIGNAL("finished()"), self.complete_run) self.connect(self.worker, QtCore.SIGNAL("terminated()"), self.complete_run) - + # --- Menu Commands --- self.connect(self.action_Quit, QtCore.SIGNAL("triggered()"), self.quit) @@ -162,60 +162,60 @@ def __init__(self, settings=None, bin_folder="", source_folder="", parent=None): self.connect(self.buttonSelectFailed, QtCore.SIGNAL("clicked()"), self.select_failed) self.connect(self.buttonSelectSVN, QtCore.SIGNAL("clicked()"), self.select_svn) self.connect(self.buttonSelectByString, QtCore.SIGNAL("clicked()"), self.select_by_string) - + # -- Text commands --- - self.connect(self.textTimeout, QtCore.SIGNAL("textChanged()"), self.text_settings_changed) - self.connect(self.textMemory, QtCore.SIGNAL("textChanged()"), self.text_settings_changed) - + self.connect(self.textTimeout, QtCore.SIGNAL("textChanged()"), self.text_settings_changed) + self.connect(self.textMemory, QtCore.SIGNAL("textChanged()"), self.text_settings_changed) + # --- Tree commands ---- #self.connect(self.treeTests, QtCore.SIGNAL("doubleClicked(QModelIndex)"), self.tree_doubleClicked) self.connect(self.treeTests, QtCore.SIGNAL("doubleClicked(QModelIndex)"), self.tree_doubleClicked) self.connect(self.treeTests, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.tree_contextMenu) - + # Signal that will be called by the worker thread self.connect(self, QtCore.SIGNAL("testRun"), self.test_run_callback) # Signal called by the monitor thread self.connect(self, QtCore.SIGNAL("testMonitorChanged()"), self.run_selected) - + self.last_tree_update = time.time() self.last_console_update = time.time() # The accumulated stdoutput from commands self.stdout = "" - + self.setup_tree() - + self.current_results = None self.show_results() - + self.readSettings() - + #----------------------------------------------------------------------------- def setup_tree(self): """ Set up the QTreeWidget of the tree """ - + # Re-discover all the projects # TODO: Use arguments for the source paths test_info.all_tests.discover_CXX_projects(self.bin_folder, self.source_folder) - + tree = self.treeTests #@type tree QTreeWidget - - # Create the tree model and put it in there + + # Create the tree model and put it in there # It is important to save the model in self otherwise I think it gets garbage collected without error! self.model = TestTreeModel() # It is probably smart to hold a ref. to the proxy object too self.proxy = TreeFilterProxyModel() self.proxy.setSourceModel(self.model) self.proxy.setFilterWildcard("*G*") - + # Set the tree to use the SORTING/FILTERING proxy of the real model tree.setModel(self.proxy) - + tree.setAlternatingRowColors(True) tree.header().setResizeMode(0,QHeaderView.Stretch) tree.header().setResizeMode(1,QHeaderView.Interactive) tree.header().setResizeMode(2,QHeaderView.Interactive) - + tree.connect( tree, QtCore.SIGNAL("clicked (QModelIndex)"), self.tree_clicked) tree.connect( tree, QtCore.SIGNAL("activated (QModelIndex)"), self.tree_clicked) self.connect( tree.selectionModel(), QtCore.SIGNAL("currentChanged (const QModelIndex &, const QModelIndex &)"), self.tree_selected) @@ -223,7 +223,7 @@ def setup_tree(self): #----------------------------------------------------------------------------- def test(self): pass - + #----------------------------------------------------------------------------- def tree_doubleClicked(self, index): """ Double-clicked on tree at that QModelIndex """ @@ -235,7 +235,7 @@ def tree_doubleClicked(self, index): if isinstance(object, TestSingle): print "Running single test:", object.fullname object.parent.run_tests(self.test_run_callback, object.name) - + def tree_contextMenu(self, point): """ Open the context menu (if on an appropriate index point :: location clicked on the tree. @@ -255,7 +255,7 @@ def tree_contextMenu(self, point): for test in object.tests: print "Running %s" % test.fullname object.run_tests(self.test_run_callback, test.name) - + elif isinstance(object, TestSingle): menu = QMenu() runTestsAction = menu.addAction("Run Single Test") @@ -263,9 +263,9 @@ def tree_contextMenu(self, point): if action == runTestsAction: print "Running single test:", object.fullname object.parent.run_tests(self.test_run_callback, object.name) - - + + #----------------------------------------------------------------------------- def readSettings(self): @@ -273,16 +273,16 @@ def readSettings(self): self.checkInParallel.setChecked( s.value("checkInParallel", False).toBool() ) self.checkMonitorTests.setChecked( s.value("checkMonitorTests", False).toBool() ) if s.contains("splitter"): self.splitter.restoreState( s.value("splitter").toByteArray() ) - self.resize( s.value("TestViewerMainWindow.width", 1500).toInt()[0], + self.resize( s.value("TestViewerMainWindow.width", 1500).toInt()[0], s.value("TestViewerMainWindow.height", 900).toInt()[0] ) - self.move( s.value("TestViewerMainWindow.x", 0).toInt()[0], + self.move( s.value("TestViewerMainWindow.x", 0).toInt()[0], s.value("TestViewerMainWindow.y", 0).toInt()[0] ) column_default_width = [200, 230, 100] - for i in [1,2]: + for i in [1,2]: self.treeTests.setColumnWidth( i, s.value("treeTests.columnWidth(%d)"%i, column_default_width[i]).toInt()[0] ) if self.treeTests.columnWidth(i) < 50: self.treeTests.setColumnWidth( i, 50) - + # --- Text settings --- memory = s.value("memory_limit_MB", 8000).toInt()[0] test_info.memory_limit_kb = memory*1024; @@ -292,21 +292,21 @@ def readSettings(self): test_info.process_timeout_sec = timeout; self.textTimeout.setPlainText("%d" % timeout) self.select_by_string_lastValue = str(s.value("select_by_string_lastValue", "-Performance").toString()) - + #----------------------------------------------------------------------------- def saveSettings(self): s = self.settings s.setValue("checkInParallel", self.checkInParallel.isChecked() ) s.setValue("checkMonitorTests", self.checkMonitorTests.isChecked() ) s.setValue("splitter", self.splitter.saveState()) - for i in [1,2]: + for i in [1,2]: s.setValue("treeTests.columnWidth(%d)"%i, self.treeTests.columnWidth(i) ) s.setValue("TestViewerMainWindow.width", self.width()) s.setValue("TestViewerMainWindow.height", self.height()) s.setValue("TestViewerMainWindow.x", self.x()) s.setValue("TestViewerMainWindow.y", self.y()) s.setValue("select_by_string_lastValue", self.select_by_string_lastValue) - + #----------------------------------------------------------------------------- def get_int_from_text(self, plainTextBox): """ Get a value from a text box. Color it red and return None if it is bad.""" @@ -318,42 +318,42 @@ def get_int_from_text(self, plainTextBox): except: plainTextBox.setStyleSheet("QPlainTextEdit { background-color: tomato; }"); return None - - - + + + #----------------------------------------------------------------------------- def text_settings_changed(self): """ called when one of the text boxes changes """ s = self.settings - + memory = self.get_int_from_text(self.textMemory); if not memory is None: test_info.memory_limit_kb = memory*1024; s.setValue("memory_limit_MB", memory) - + timeout = self.get_int_from_text(self.textTimeout); if not timeout is None: test_info.process_timeout_sec = timeout; s.setValue("process_timeout_sec", timeout) - - - - + + + + #----------------------------------------------------------------------------- def closeEvent(self, event): """Window is closing """ # Save all settings that haven't been saved before self.saveSettings() - + #----------------------------------------------------------------------------- def quit(self): """ Exit the program """ test_info.all_tests.abort() print "Exiting TestViewer. Happy coding!" self.close() - - - + + + #----------------------------------------------------------------------------- def expand_tree_to_projects(self): """ Collapse suites so that only the top projects are shown """ @@ -362,7 +362,7 @@ def expand_tree_to_projects(self): for i in xrange(rowcount): # Collapse each project-level one self.treeTests.setExpanded( self.treeTests.model().index(i, 0, QModelIndex() ), False) - + #----------------------------------------------------------------------------- def expand_tree_to_suites(self): """ Collapse single test results but expand projects """ @@ -377,13 +377,13 @@ def expand_tree_to_suites(self): for j in xrange(num_suites): suite_indx = self.treeTests.model().index(j, 0, indx ) self.treeTests.setExpanded( suite_indx, False) - + #----------------------------------------------------------------------------- def expand_tree_to_all(self): """ Expand all tree items """ self.treeTests.expandAll() - - + + #----------------------------------------------------------------------------- def markup_console(self, in_line): """Return a marked-up (with HTML) version of a line @@ -405,41 +405,41 @@ def markup_console(self, in_line): else: #Print normally color = "" - + # Bolden any lines with --- in them if line.startswith("---"): line = "%s" % line # Add the color tag if color != "": line = '%s' % (color, line) - # Add a new line + # Add a new line return line + "
\n" - + #----------------------------------------------------------------------------- def test_stdout_callback(self, line): """ Add a line to stdoutput from test running """ pass - + #----------------------------------------------------------------------------- def test_run_callback(self, text, obj): """ Update the progress bar and label when a calculation is done (callback from test runner. Parameters: - obj: either a TestSuite or a TestProject; + obj: either a TestSuite or a TestProject; if it is a string, then it is the stdout of the make command""" # Update the tree's data for the suite if not obj is None: - + # For test results, increment the progress bar if isinstance(obj, TestSingle) or isinstance(obj, TestSuite) or isinstance(obj, TestProject): - val = self.progTest.value()+1 + val = self.progTest.value()+1 self.progTest.setValue( val ) self.progTest.setFormat("%p% : " + text) # Try to update the current results shown if not self.current_results is None: - if obj.get_fullname() == self.current_results.get_fullname(): + if obj.get_fullname() == self.current_results.get_fullname(): self.show_results() - + if isinstance(obj, TestSuite): #print "Updating GUI of TestSuite", obj.name self.model.update_suite(obj) @@ -457,19 +457,19 @@ def test_run_callback(self, text, obj): else: # Accumulated stdout self.stdout += self.markup_console( unicode(obj) ) - if (time.time() - self.last_console_update) > 1.5: # Dont update more often than this: + if (time.time() - self.last_console_update) > 1.5: # Dont update more often than this: self.textConsole.setText( u'\n' + self.stdout ) sb = self.textConsole.verticalScrollBar(); sb.setValue(sb.maximum()); self.last_console_update = time.time() - - + + #----------------------------------------------------------------------------- def quick_update_tree(self): """ Update the tree view without resetting all the model data """ self.treeTests.model().update_all() - + #----------------------------------------------------------------------------- def set_running(self, running): """ Sets whether a test suite is running. Adjusts the GUI as needed""" @@ -477,16 +477,16 @@ def set_running(self, running): self.buttonAbort.setEnabled(running) self.buttonRunAll.setEnabled(not running) self.buttonRunSelected.setEnabled(not running) - + #----------------------------------------------------------------------------- def complete_run(self): """ Event called when completing/aborting a test run """ self.set_running(False) - + self.progTest.setValue(0) self.progTest.setFormat("") self.update_tree() - + failed = test_info.all_tests.failed num_run = test_info.all_tests.num_run if failed > 0: @@ -495,14 +495,14 @@ def complete_run(self): else: self.labelResult.setStyleSheet("QLabel { background-color: green }") self.labelResult.setText("All Passed! %d of %d tests failed." % (failed, num_run)) - + #----------------------------------------------------------------------------- def update_tree(self): """ Update the tree view with whatever the current results are """ self.model.setupModelData() self.treeTests.update() self.show_results() - + #----------------------------------------------------------------------------- def tree_clicked(self, index): @@ -514,14 +514,14 @@ def tree_clicked(self, index): item = self.treeTests.model().data( index, Qt.UserRole).toPyObject() self.current_results = item self.show_results() - + #----------------------------------------------------------------------------- def tree_selected(self, current_index, previous_index): """ Selection in the tree changed from previous_index to current_index """ item = self.treeTests.model().data( current_index, Qt.UserRole).toPyObject() self.current_results = item self.show_results() - + #----------------------------------------------------------------------------- def show_results(self): @@ -529,52 +529,52 @@ def show_results(self): @param res :: either TestProject, TestSuite, or TestSingle object containing the results to show.""" if self.current_results is None: self.labelTestType.setText("Test Project Results:") - self.labelTestName.setText( "" ) + self.labelTestName.setText( "" ) self.textResults.setText( "" ) return res = self.current_results if isinstance(res, TestProject): self.labelTestType.setText("Test Project Results:") elif isinstance(res, TestSuite): - self.labelTestType.setText("Test Suite Results:") + self.labelTestType.setText("Test Suite Results:") elif isinstance(res, TestSingle): - self.labelTestType.setText("Single Test Results:") + self.labelTestType.setText("Single Test Results:") else: raise "Incorrect object passed to show_results; should be TestProject, TestSuite, or TestSingle." self.labelTestName.setText( res.get_fullname() ) - self.labelTestName.hide() - self.textResults.setText( u'\n' + self.labelTestName.hide() + self.textResults.setText( u'\n' + res.get_results_text() ) - + #----------------------------------------------------------------------------- def checked_show_fail_only(self, state): """ Toggle the filtering """ self.proxy.set_filter_failed_only(state > 0) - + def checked_show_selected_only(self, state): """ Toggle the filtering """ self.proxy.set_filter_selected_only(state > 0) - + def checked_monitor_libraries(self, state): self.monitor_worker.set_monitor_libraries( state > 0 ) - + def checked_monitor_tests(self, state): self.monitor_worker.set_monitor_tests( state > 0 ) - + #----------------------------------------------------------------------------- def run_all(self): self.do_run(False) def run_selected(self): self.do_run(True) - + def do_run(self, selected_only): """ Start a parallelized test running with the given parameters """ parallel = self.checkInParallel.isChecked() # Do some setup of the worker and GUI num_steps = self.worker.set_parameters(self, selected_only=selected_only, make_tests=True, parallel=parallel) - if num_steps < 1: num_steps = 1 + if num_steps < 1: num_steps = 1 self.progTest.setValue(0) self.progTest.setMaximum( num_steps ) self.set_running(True) @@ -585,36 +585,36 @@ def do_run(self, selected_only): self.tabWidgetRight.setCurrentIndex(1) # Begin the thread in the background self.worker.start() - + #----------------------------------------------------------------------------- def abort(self): test_info.all_tests.abort() - + #----------------------------------------------------------------------------- def select_all(self): """ Select all tests """ test_info.all_tests.select_all(True) self.proxy.invalidateFilter() self.treeTests.update() - + def select_none(self): """ De-Select all tests """ test_info.all_tests.select_all(False) self.proxy.invalidateFilter() self.treeTests.update() - + def select_failed(self): """ Select all failing tests """ test_info.all_tests.select_failed() self.proxy.invalidateFilter() self.treeTests.update() - + def select_svn(self): """ Select all files modified by SVN/git st """ test_info.all_tests.select_svn() self.proxy.invalidateFilter() self.treeTests.update() - + def select_by_string(self): """ Use a string to select """ dlg = QtGui.QInputDialog(self) @@ -626,34 +626,34 @@ def select_by_string(self): test_info.all_tests.select_by_string(self.select_by_string_lastValue) self.proxy.invalidateFilter() self.treeTests.update() - - + + def start(): # Start the settings object. # TODO: Change the company name here and in MantidPlot settings = QSettings("ISIS", "MantidTestViewer"); settings_bin_folder = str(settings.value("bin_folder", "../../Mantid/bin").toString()) settings_source_folder = str(settings.value("source_folder", "../../Mantid/Framework").toString()) - + bin_folder = "" if len(sys.argv) > 1: bin_folder = sys.argv[1] - + source_folder = "" if len(sys.argv) > 2: source_folder = sys.argv[2] - + if bin_folder == "--help": print """TestViewer.py [BINFOLDER] [SOURCEFOLDER] GUI to run and view Mantid tests. BINFOLDER Path to the bin/ folder that contains the test executables. - Will use the last path used if not specified: + Will use the last path used if not specified: %s - SOURCEFOLDER Path to the root of the framework source folder. - Will use the last path used if not specified: + SOURCEFOLDER Path to the root of the framework source folder. + Will use the last path used if not specified: %s """ % (settings_bin_folder, settings_source_folder) sys.exit() - + # No command line arguments? Get them from the settings if bin_folder == "": bin_folder = settings_bin_folder @@ -670,24 +670,24 @@ def start(): source_folder = os.path.join( bin_folder, "/../Framework" ) else: # Use whatever was given - settings.setValue("source_folder", source_folder) + settings.setValue("source_folder", source_folder) print "Starting TestViewer ..." print "... bin folder is", bin_folder print "... source folder is", source_folder print "." - + app = QtGui.QApplication([]) app.setOrganizationName("Mantid") app.setOrganizationDomain("mantidproject.org") app.setApplicationName("Mantid Test Viewer") - + main = TestViewerMainWindow(settings, bin_folder, source_folder) main.show() - - app.exec_() - + + app.exec_() + if __name__ == '__main__': start() - + diff --git a/Code/Tools/TestViewer/test_info.py b/Code/Tools/TestViewer/test_info.py index 2b962e41e644..c43fb05c0cf7 100644 --- a/Code/Tools/TestViewer/test_info.py +++ b/Code/Tools/TestViewer/test_info.py @@ -63,75 +63,75 @@ class TestResult: BUILD_ERROR = 3 """ All tests failed """ ALL_FAILED = 4 - """ Probably a segfault """ + """ Probably a segfault """ ABORTED = 5 - + def __init__(self, value=0, old=False): self.value = value self.old = old - + def is_failed(self): return self.value == self.SOME_FAILED or self.value == self.BUILD_ERROR \ or self.value == self.ALL_FAILED or self.value == self.ABORTED - + def __eq__(self, other): """ Equality comparison """ if isinstance(other, TestResult): return ((self.value == other.value) and (self.old == other.old)) - else: + else: return self.value == other - + def __neq__(self, other): if isinstance(other, TestResult): return (self.value != other.value) or (self.old != other.old) else: return self.value != other - + def get_string(self): """Return a string summarizing the state. Used in GUI.""" s = "Unknown" - if self.value == self.NOT_RUN: s = "Not Run" - if self.value == self.ALL_PASSED: s = "All Passed" - if self.value == self.SOME_FAILED: s = "FAILED!" - if self.value == self.BUILD_ERROR: s = "BUILD ERROR!" + if self.value == self.NOT_RUN: s = "Not Run" + if self.value == self.ALL_PASSED: s = "All Passed" + if self.value == self.SOME_FAILED: s = "FAILED!" + if self.value == self.BUILD_ERROR: s = "BUILD ERROR!" if self.value == self.ALL_FAILED: s = "ALL FAILED!" if self.value == self.ABORTED: s = "ABORTED!" if self.old and (self.value != self.NOT_RUN): s += " (old)" - return s - - + return s + + def add(self, other): """ Add the state from a another test result or another suite. """ if other == self.BUILD_ERROR: self.value = self.BUILD_ERROR return - + if other == self.ALL_PASSED: if self.value == self.ALL_FAILED: self.value = self.SOME_FAILED elif self.value == self.NOT_RUN: self.value = self.ALL_PASSED - + if other == self.ALL_FAILED or other == self.ABORTED: if self.value == self.ALL_PASSED: self.value = self.SOME_FAILED elif self.value == self.NOT_RUN: self.value = self.ALL_FAILED - + if other == self.SOME_FAILED: if (self.value == self.ALL_PASSED) or (self.value == self.ALL_FAILED): self.value = self.SOME_FAILED elif self.value == self.NOT_RUN: self.value = self.SOME_FAILED - + # If anything is old, then this one is old too! if isinstance(other, TestResult): if other.old and other.value != self.NOT_RUN: self.old = True - - - + + + #================================================================================================== class TestSingle(object): """ A single test instance (one test inside one suite) """ @@ -141,27 +141,27 @@ def __init__(self, name, parent, fullname=None): self.fullname = name else: self.fullname = fullname - + # Parent TestSuite object self.parent = parent - + # Starting test state self.state = TestResult() - + # Last date and time the test was run self.lastrun = None - + # Time (in seconds) to execute the testTestSingle self.runtime = 0.0 - + # Last failure text self.failure = "" # Line in the file of the failure self.failure_line = 0 - - # Stdout output for that failure - self.stdout = "" - + + # Stdout output for that failure + self.stdout = "" + #---------------------------------------------------------------------------------- def get_failed(self): """Return 1 if the test failed""" @@ -169,13 +169,13 @@ def get_failed(self): return 1 else: return 0 - failed = property(get_failed) - + failed = property(get_failed) + #---------------------------------------------------------------------------------- def get_fullname(self): """Return a full, uniquely identifying name for this """ return self.fullname - + #---------------------------------------------------------------------------------- def get_results_text(self): """Returns HTML text describing these test results """ @@ -195,11 +195,11 @@ def get_results_text(self): # # Use the pre tag but wrap long lines. # s += u'
'
 #            # Print the rest
-#            for line in lines: 
+#            for line in lines:
 #                s += unicode( html_escape(line) + "\n")
 #            s += u"
" return s - + #---------------------------------------------------------------------------------- def replace_contents(self, other): """ Replace the contents of self with those of other (coming after running in @@ -211,17 +211,17 @@ def replace_contents(self, other): self.failure = other.failure self.failure_line = other.failure_line self.stdout = other.stdout - + #---------------------------------------------------------------------------------- def load_results(self, case): - """Load the results from a xml Junit file + """Load the results from a xml Junit file Parameters case : a xml.Node object containing the testcase xml results """ # Get the runtime self.runtime = float(case.getAttribute("time")) # Assumed passed self.state = TestResult(TestResult.ALL_PASSED, old=False) - + # Get the system output self.stdout = "" systemout = case.getElementsByTagName("system-out") @@ -231,7 +231,7 @@ def load_results(self, case): # Look for failures fails = case.getElementsByTagName("failure") - + if len(fails)>0: self.state = TestResult(TestResult.ALL_FAILED, old=False) # File and line of failure @@ -252,26 +252,26 @@ def load_results(self, case): # Get the failure text self.failure = errors[0].firstChild.wholeText # Put it in std out so we can see it - self.stdout += "\n" + self.failure + self.stdout += "\n" + self.failure #---------------------------------------------------------------------------------- def run_test(self): """Run only this single test and interpret the results. """ self.parent.run_tests() - + #---------------------------------------------------------------------------------- def get_state_str(self): """Return a string summarizing the state. Used in GUI.""" return self.state.get_string() - + def age(self): """ Age the results (flag them as "old" ) """ self.state.old = True - + def __repr__(self): return "TestSingle(%s): state=%s, lastrun=%s, runtime=%s.\n%s" % (self.name, self.get_state_str(), self.lastrun, self.runtime, self.stdout) - + #================================================================================================== class TestSuite(object): @@ -297,7 +297,7 @@ def __init__(self, name, parent, classname, command, rundir, xml_file, source_fi self.contents_changed = False # Last date and time the test was run self.lastrun = None - + # Source file (BlaBlaTest.h) for this suite self.source_file = source_file if not os.path.exists(self.source_file): @@ -306,7 +306,7 @@ def __init__(self, name, parent, classname, command, rundir, xml_file, source_fi else: # Last modified time of the source file self.source_file_mtime = os.path.getmtime(self.source_file) - + # A list of test singles inside this suite self.tests = [] # Is it selected to run? @@ -326,7 +326,7 @@ def __init__(self, name, parent, classname, command, rundir, xml_file, source_fi def get_fullname(self): """Return a full, uniquely identifying name for this """ return self.classname - + #---------------------------------------------------------------------------------- def get_results_text(self, details=True): """Returns HTML text describing these test results """ @@ -341,7 +341,7 @@ def get_results_text(self, details=True): for test in self.tests: if details or test.failed: s += test.get_results_text() - + # Now the mantid.log, if any if details: if self.log_contents == "": @@ -354,8 +354,8 @@ def get_results_text(self, details=True): else: # Too long to escape HTML html_log = html_escape( self.log_contents[:10000] ) - html_log += "

LOG TOO LONG ...
" - + html_log += "

LOG TOO LONG ...
" + html_log = html_log.replace("\n", "
") s += html_log return s @@ -382,37 +382,37 @@ def replace_contents(self, other): self.log_contents = other.log_contents # Re-compile the states from the individual tests self.compile_states() - - + + #---------------------------------------------------------------------------------- def add_single(self, test_name, fullname): """ Add a single test to this suite """ self.tests.append( TestSingle(test_name, self, fullname) ) - + #---------------------------------------------------------------------------------- def get_parent(self): """ Return the parent Project of this suite """ return self.parent - + #---------------------------------------------------------------------------------- def get_modified(self): - """" Returns True if the required source file was modified. + """" Returns True if the required source file was modified. NOTE: This overwrites the previous cached modified time, AKA it will only return True once per change.""" oldtime = self.source_file_mtime if os.path.exists(self.source_file): self.source_file_mtime = os.path.getmtime(self.source_file) return (self.source_file_mtime != oldtime) - + def get_selected(self): return self.selected - + #---------------------------------------------------------------------------------- def set_selected(self, value): """Sets the selection state of this suite. """ self.selected = value #if self.parent.selected: - + #---------------------------------------------------------------------------------- def age(self): """ Age the results (flag them as "old" ) """ @@ -424,7 +424,7 @@ def age(self): def is_built(self): """Returns True if the test build for this suite was successful.""" return self.build_succeeded - + #---------------------------------------------------------------------------------- def set_build_failed(self, output): """Sets that the build failed for all single tests in this suite. @@ -437,7 +437,7 @@ def set_build_failed(self, output): test.state = TestResult(TestResult.BUILD_ERROR, old=False) test.failure = "Build failure" test.stdout = "" - + #---------------------------------------------------------------------------------- def compile_states(self): """ Add up the single test results into this suite """ @@ -448,12 +448,12 @@ def compile_states(self): for test in self.tests: self.state.add( test.state ) if test.state.is_failed(): - self.failed += 1 + self.failed += 1 self.num_run += 1 else: - self.passed += 1 + self.passed += 1 self.num_run += 1 - + #---------------------------------------------------------------------------------- def get_runtime(self): """Return the total runtime of contained tests """ @@ -461,9 +461,9 @@ def get_runtime(self): for test in self.tests: runtime += test.runtime return runtime - runtime = property(get_runtime) - - + runtime = property(get_runtime) + + #---------------------------------------------------------------------------------- def get_state_str(self): """Return a string summarizing the state. Used in GUI.""" @@ -472,19 +472,19 @@ def get_state_str(self): return self.state.get_string() + " (%d of %d failed)" % (self.failed, self.num_run) #, self.num_run) else: return self.state.get_string() + " (%d)" % (self.num_run) #, self.num_run) - - + + #---------------------------------------------------------------------------------- def run_tests(self, stdout_callback_func, single_test_name=None): """ Runs this test suite, then loads the produced XML file and interprets its results. This method should be written so that it can be run in parallel. """ - + self.contents_changed = False - + # Present working directory pwd = os.getcwd() - + make_temp_dir = False if make_temp_dir: # Create a temporary directory just for running this test suite @@ -492,70 +492,70 @@ def run_tests(self, stdout_callback_func, single_test_name=None): rundir = tempdir else: rundir = self.rundir - + os.chdir(rundir) - + # XML file where the ouput will be xml_path = os.path.join(rundir, self.xml_file) # Delete the XML so that it will be empty if the test dies if os.path.exists(xml_path): os.remove(xml_path) - - + + # In order to catch "segmentation fault" message, we call bash and get the output of that! # Max memory for process in KB is a global full_command = "bash -c 'ulimit -v %d ; %s" % (memory_limit_kb, self.command) - + # Are we doing a single test? - single_test = (not single_test_name is None) + single_test = (not single_test_name is None) if single_test: full_command += " " + single_test_name # Close off the quotes full_command += "'" - + # Execute the test command; wait for it to return, up to a timeout (status, output) = run_command_with_timeout(full_command, process_timeout_sec, run_shell=False) - + if status == -15: output = output + "\n\nPROCESS TIMED OUT" - + # Get the output XML filename if os.path.exists(xml_path) and os.path.getsize(xml_path) > 0: # Yes, something was output - self.parse_xml(xml_path, single_test) + self.parse_xml(xml_path, single_test) else: # No - you must have segfaulted or some other error! self.set_aborted(output, single_test_name) - + # Now try to load the log_file if os.path.exists(self.log_file): self.log_contents = open(self.log_file).read() else: self.log_contents = "" - + # Go back to old directory and remove the temp one os.chdir(pwd) - + if make_temp_dir: try: shutil.rmtree(tempdir) except: print "Error removing temporary directory ", tempdir - + # Finalize - self.compile_states() - + self.compile_states() + #---------------------------------------------------------------------------------- def set_aborted(self, stdout, single_test_name = None): """ Set that all tests aborted and save the stdout """ for test in self.tests: - if single_test_name is None or (single_test_name == test.name): + if single_test_name is None or (single_test_name == test.name): test.state.value = self.state.ABORTED test.state.old = False test.stdout = stdout test.lastrun = datetime.datetime.now() - - + + #---------------------------------------------------------------------------------- def find_test(self, test_name): """Find and return a TestSingle instance of given name""" @@ -563,24 +563,24 @@ def find_test(self, test_name): if test.name == test_name: return test return None - + #---------------------------------------------------------------------------------- def parse_xml(self, xml_path, single_test=False): """Interpret a jUnit-style XML file produced for this suite. - + Parameters xml_path :: full path to the produced XML path single_test :: we expect only one test to have really run""" - + self.lastrun = datetime.datetime.now() - + try: dom = parse(xml_path) except: # Empty file, for example? Just return return - + #print dom.getElementsByTagName(self.name) suites = dom.getElementsByTagName("testsuite") if len(suites) == 0: @@ -591,7 +591,7 @@ def parse_xml(self, xml_path, single_test=False): break else: xmlSuite = suites[0] - + # Get all the test cases (aka TestSuite) xmlCases = xmlSuite.getElementsByTagName("testcase") for case in xmlCases: @@ -615,8 +615,8 @@ def parse_xml(self, xml_path, single_test=False): test.load_results(case) else: print "Was unable to parse results of test %s.%s!" % (classname, test_name) - - + + # Now we look for tests that are no longer in the suite, and remove them if not single_test: tests_copy = self.tests[:] @@ -626,30 +626,30 @@ def parse_xml(self, xml_path, single_test=False): self.tests.remove(test) # Mark that we need to update the tree in the GUI self.contents_changed = True - + #---------------------------------------------------------------------------------- def __repr__(self): return "TestSuite(%s) with %d TestSingle(s).\nCommand=%s\nXML File=%s\nSource file=%s" % (self.name, len(self.tests), self.command, self.xml_file, self.source_file) - + #================================================================================================== class TestProject(object): """ A sub-project of several test suites, e.g. KernelTest """ - + #---------------------------------------------------------------------------------- def __init__(self, name, executable, make_command): self.name = name - + # Path to the executable command self.executable = executable - + # Command that will build the given executable self.make_command = make_command - + # Test suites in this project self.suites = [] - + # Is it selected to run? self.selected = True @@ -663,7 +663,7 @@ def __init__(self, name, executable, make_command): #---------------------------------------------------------------------------------- def get_lastrun(self): - """Return the last time any of the suites were run""" + """Return the last time any of the suites were run""" latest = datetime.datetime(2000,1,1) for suite in self.suites: if not suite.lastrun is None: @@ -673,13 +673,13 @@ def get_lastrun(self): return latest else: return None - lastrun = property(get_lastrun) + lastrun = property(get_lastrun) #---------------------------------------------------------------------------------- def get_fullname(self): """Return a full, uniquely identifying name for this """ return self.name - + #---------------------------------------------------------------------------------- def get_selected(self): """Return whether this is selected or not. NOTE: @@ -687,17 +687,17 @@ def get_selected(self): num_sel = 0 num_not_sel = 0 for suite in self.suites: - if suite.selected: + if suite.selected: num_sel += 1 else: num_not_sel += 1 - + if num_sel > 0 and num_not_sel == 0: return 1 if num_not_sel > 0 and num_sel == 0: return 0 return 2 - + #---------------------------------------------------------------------------------- def get_results_text(self): """Returns HTML text describing these test results """ @@ -712,10 +712,10 @@ def get_results_text(self): for suite in self.suites: s += suite.get_results_text(details=False) return s - + #---------------------------------------------------------------------------------- def is_source_modified(self, selected_only): - """Return true if any of the source files were modified + """Return true if any of the source files were modified @param selected_only :: True if you only check the selected ones.""" anymod = False for suite in self.suites: @@ -723,7 +723,7 @@ def is_source_modified(self, selected_only): if not selected_only or suite.get_selected(): anymod = anymod or this_one_changed return anymod - + #---------------------------------------------------------------------------------- def replace_contents(self, other): """ Replace the contents of self with those of other (coming after running in @@ -741,47 +741,47 @@ def replace_contents(self, other): #---------------------------------------------------------------------------------- def make(self, callback_func=None): """Make the project using the saved command. - @param callback_func :: Callback function that will accept a + @param callback_func :: Callback function that will accept a string for each line of the make command's output. """ - + msg = "-------- Making Test %s ---------" % self.name if not callback_func is None: callback_func("%s" % msg) - + full_command = self.make_command if not callback_func is None: callback_func(full_command) # This will run while calling the stdout callback. (status, output) = run_command_with_callback(full_command, callback_func) if (status != 0): - msg = "-------- BUILD FAILED! ---------" + msg = "-------- BUILD FAILED! ---------" if not callback_func is None: callback_func("%s" % msg) self.build_succeeded = False self.build_stdout = output else: - msg = "-------- Build Succeeded ---------" + msg = "-------- Build Succeeded ---------" if not callback_func is None: callback_func("%s" % msg) self.build_succeeded = True # Build was successful for suite in self.suites: suite.build_succeeded = True - - - + + + #---------------------------------------------------------------------------------- def age(self): """ Age the results (flag them as "old" ) """ self.state.old = True for suite in self.suites: suite.age() - + #---------------------------------------------------------------------------------- def find_source_file(self, suite_name): """ Find the source file corresponding to the given suite in this project Returns: the full path to the test file. """ return os.path.join( self.source_path, "test/" + suite_name + ".h") - - + + #---------------------------------------------------------------------------------- def is_anything_selected(self): """Return True if any of the suites are selected.""" @@ -789,7 +789,7 @@ def is_anything_selected(self): if suite.selected: return True return False - + #---------------------------------------------------------------------------------- def get_runtime(self): """Return the total runtime of contained tests """ @@ -797,8 +797,8 @@ def get_runtime(self): for suite in self.suites: runtime += suite.get_runtime() return runtime - runtime = property(get_runtime) - + runtime = property(get_runtime) + #---------------------------------------------------------------------------------- def compile_states(self): """ Add up the single test results into this suite """ @@ -807,12 +807,12 @@ def compile_states(self): self.failed = 0 self.num_run = 0 for suite in self.suites: - state = suite.state + state = suite.state self.state.add( state ) - self.passed += suite.passed + self.passed += suite.passed self.num_run += suite.num_run self.failed += suite.failed - + #---------------------------------------------------------------------------------- def get_state_str(self): """Return a string summarizing the state. Used in GUI.""" @@ -821,22 +821,22 @@ def get_state_str(self): return self.state.get_string() + " (%d of %d failed)" % (self.failed, self.num_run) #, self.num_run) else: return self.state.get_string() + " (%d)" % (self.num_run) #, self.num_run) - + #---------------------------------------------------------------------------------- def populate(self, project_source_path): - """ Discover the suites and single tests in this test project. + """ Discover the suites and single tests in this test project. @param project_source_path :: root path to the project. e.g. Framework/Kernel """ self.suites = [] self.source_path = project_source_path - + # CXX test simply lists "TestSuite testName" last_suite_name = "" suite = None - + # Get the bare XML file name (dir, file) = os.path.split(self.executable) - + output = commands.getoutput(self.executable + " --help-tests") xml_file = "TEST-%s.xml" % self.name @@ -845,7 +845,7 @@ def populate(self, project_source_path): os.remove(xml_file) except: pass - + lines = output.split("\n") # Look for the The first two lines are headers count = 0 @@ -854,9 +854,9 @@ def populate(self, project_source_path): count += 1 if count >= len(lines): print "Error interpreting CXX test output of %s" % (self.executable) - + lines = lines[count:] - + for line in lines: words = line.split() if len(words) == 2: @@ -869,29 +869,29 @@ def populate(self, project_source_path): # The class name goes KernelTest.DateAndTimeTest classname = self.name + "." + suite_name source_file = self.find_source_file(suite_name) - + # The xml file output goes (as of rev 8587, new cxxtestgen see ticket #2204 ) xml_file = "TEST-" + classname + ".xml" - # Correct the XML file for python unit tests + # Correct the XML file for python unit tests if self.executable.endswith(".py"): xml_file = "Testing/" + xml_file - - # The shell command to run + + # The shell command to run log_file = classname + ".log" command = "MANTIDLOGPATH=%s" % log_file + " " + self.executable + " " + suite_name # Create that suite - suite = TestSuite(suite_name, self, classname, + suite = TestSuite(suite_name, self, classname, command, dir, xml_file, source_file, log_file) last_suite_name = suite_name self.suites.append(suite) - + # Add a single test to whatever suite we are in suite.add_single(test_name, classname+"."+test_name) else: # Could not interpret line pass - + def __repr__(self): return "TestProject(%s)" % (self.name) @@ -905,24 +905,24 @@ def __repr__(self): def run_tests_in_suite(multiple_tests, suite, stdout_callback_func ): """Run all tests in a given suite. Method called by the multiprocessing Pool.apply_async() method. - + Parameters: multiple_tests :: a MultipleProjects instance calling this method. suite :: the suite to run stdout_callback_func :: callback function for each line of stdout """ - if not multiple_tests is None: + if not multiple_tests is None: if multiple_tests.abort_run: return "Aborted." if not suite is None: suite.run_tests(stdout_callback_func) # Simply return the object back (for use by the callback function) return suite - + #================================================================================================== def make_test(multiple_tests, project): """Make the tests in a given project. Method called by the multiprocessing Pool.apply_async() method. - + Parameters: multiple_tests :: a MultipleProjects instance calling this method. project :: the project to make @@ -931,52 +931,52 @@ def make_test(multiple_tests, project): the callback function must replace the old project with this one; because the changes happened in the OTHER thread! """ - if not multiple_tests is None: + if not multiple_tests is None: if multiple_tests.abort_run: return "Aborted." if not project is None: project.make() return project else: return None - - - - + + + + #================================================================================================== #================================================================================================== #================================================================================================== class MultipleProjects(object): """ A Class containing a list of all the available test projects. This will be made into a single global variable instance. """ - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def __init__(self): # The projects contained self.projects = [] # Abort flag self.abort_run = False - + # The state of the overall project self.state = TestResult() self.passed = 0 self.failed = 0 self.num_run = 0 - + # Head folder of the source files (Framework normally) self.source_path = "." - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def abort(self): """ Set a flag to abort all further calculations. """ print "... Attempting to abort ..." self.abort_run = True - + #---------------------------------------------------------------------------------- def age(self): """ Age the results (flag them as "old" ) """ for pj in self.projects: pj.age() - + #---------------------------------------------------------------------------------- def select_all(self, value): """ Select all tests """ @@ -984,7 +984,7 @@ def select_all(self, value): pj.selected = value for suite in pj.suites: suite.selected = value - + #---------------------------------------------------------------------------------- def select_failed(self): """ Select all failing tests """ @@ -992,7 +992,7 @@ def select_failed(self): pj.selected = (pj.failed > 0) for suite in pj.suites: suite.selected = (suite.failed > 0) - + #---------------------------------------------------------------------------------- def select_svn(self): """ Do a 'git status st' call and interpret the results to find which tests need to be run. """ @@ -1015,13 +1015,13 @@ def select_svn(self): for pj in self.projects: for suite in pj.suites: # If the test file and the source file are the same, - if os.path.exists(suite.source_file): + if os.path.exists(suite.source_file): if os.path.samefile( suite.source_file, filename): suite.selected = True pj.selected = True foundit = suite break - + if foundit is None: # Ok, not directly a test name. Look for a similar test file # Get the bare filename, no .h or .cpp @@ -1039,17 +1039,17 @@ def select_svn(self): print "%s: No test found." % (filename) else: print "%s: Test found: '%s'" % ( filename, foundit.get_fullname() ) - - - #-------------------------------------------------------------------------- + + + #-------------------------------------------------------------------------- def select_by_string(self, val): """ Search by words """ if len(val) < 2: print "Too few characters!" - return - + return + num = 0 - + if val.startswith("-"): # Select all and exclude word = val[1:] @@ -1061,40 +1061,40 @@ def select_by_string(self, val): word = val for pj in self.projects: for suite in pj.suites: - suite.selected = word in suite.name + suite.selected = word in suite.name if suite.selected: num += 1 - + print num, " suites were selected." - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def discover_CXX_projects(self, path, source_path): """Look for CXXTest projects in the given paths. Populates all the test in it.""" - + path = os.path.abspath(path) - + self.source_path = source_path self.projects = [] - # How many cores to use to make projects + # How many cores to use to make projects num_threads = multiprocessing.cpu_count()-1 if num_threads < 1: num_threads = 1 - + testnames = set() - + dirList=os.listdir(path) for fname in dirList: # Look for executables ending in Test #if (fname.endswith("Test") or fname.endswith("Test.py")) and os.path.isfile( os.path.join(path, fname) ): if (fname.endswith("Test")) and os.path.isfile( os.path.join(path, fname) ): testnames.add(fname) - + # Now add the known tests, in case they were deleted - for x in ["AlgorithmsTest", "DataObjectsTest", "MDAlgorithmsTest", "PythonAPITest", "APITest", - "GeometryTest", "CurveFittingTest", "ICatTest", "MDEventsTest", + for x in ["AlgorithmsTest", "DataObjectsTest", "MDAlgorithmsTest", "PythonAPITest", "APITest", + "GeometryTest", "CurveFittingTest", "ICatTest", "MDEventsTest", "DataHandlingTest", "KernelTest", "CrystalTest", "VatesAPITest"]: testnames.add(x) - + for fname in testnames: make_command = "cd %s ; make %s -j%d " % (os.path.join(path, ".."), fname, num_threads) projectname = fname @@ -1108,8 +1108,8 @@ def discover_CXX_projects(self, path, source_path): pj.populate(project_source_path) self.projects.append(pj) - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def make_fake_results(self): """Generate some fake results for quick debugging """ for pj in self.projects: @@ -1120,7 +1120,7 @@ def make_fake_results(self): test.state = TestResult(random.randint(0, 4)) test.state.old = (random.randint(0,10) > 5) test.runtime = random.random()/1000 - + #---------------------------------------------------------------------------------- def compile_states(self): """ Add up the single test results into this suite """ @@ -1129,12 +1129,12 @@ def compile_states(self): self.failed = 0 self.num_run = 0 for pj in self.projects: - state = pj.state + state = pj.state self.state.add( state ) - self.passed += pj.passed + self.passed += pj.passed self.num_run += pj.num_run self.failed += pj.failed - + #---------------------------------------------------------------------------------- def get_state_str(self): """Return a string summarizing the state. Used in GUI.""" @@ -1145,7 +1145,7 @@ def get_state_str(self): #---------------------------------------------------------------------------------- def is_source_modified(self, selected_only): - """Return true if any of the source files were modified + """Return true if any of the source files were modified @param selected_only :: True if you only check the selected ones.""" anymod = False for pj in self.projects: @@ -1153,26 +1153,26 @@ def is_source_modified(self, selected_only): anymod = anymod or pj.is_source_modified(selected_only) return anymod - #-------------------------------------------------------------------------- + #-------------------------------------------------------------------------- def find_project(self, name): """Return the TestProject named name; None if not found""" for pj in self.projects: if pj.name == name: return pj return None - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def find_suite(self, classname): - """ Return the TestSuite with the given classname (e.g. KernelTest.UnitTest). + """ Return the TestSuite with the given classname (e.g. KernelTest.UnitTest). Returns None if not found""" for pj in self.projects: for suite in pj.suites: if suite.classname == classname: return suite return None - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def replace_project(self, pj): """Given a project from another thread, replace the current one with this one. Will look for a matching name""" @@ -1180,8 +1180,8 @@ def replace_project(self, pj): if self.projects[i].name == pj.name: self.projects[i].replace_contents(pj) break - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def replace_suite(self, st): """Given a suite from another thread, replace the current one with this one. Will look for a matching name""" @@ -1195,12 +1195,12 @@ def replace_suite(self, st): if suite.name == st.name: pj.suites[i].replace_contents(st) break - - #-------------------------------------------------------------------------- + + #-------------------------------------------------------------------------- def get_selected_suites(self, selected_only=True): """Returns a list of all selected suites. Suites where make failed are excluded! - + Parameters: selected_only :: set to False to return all suites """ suites = [] @@ -1212,9 +1212,9 @@ def get_selected_suites(self, selected_only=True): # Suite must be built to be included here! suites.append(st) # print "get_selected_suites ", len(suites) - return suites - - #-------------------------------------------------------------------------- + return suites + + #-------------------------------------------------------------------------- def run_tests_computation_steps(self, selected_only=True, make_tests=True): """Returns the number of computation steps that will be done with these parameters This is used by the GUI to know how to report progress.""" @@ -1225,32 +1225,32 @@ def run_tests_computation_steps(self, selected_only=True, make_tests=True): count += 1 count += len(self.get_selected_suites(selected_only)) return count - - #-------------------------------------------------------------------------- - def run_tests_in_parallel(self, selected_only=True, make_tests=True, parallel=True, + + #-------------------------------------------------------------------------- + def run_tests_in_parallel(self, selected_only=True, make_tests=True, parallel=True, callback_func=None): """Run tests in parallel using multiprocessing. Parameters: selected_only: run only the selected suites. make_tests: set to True to make the tests before running them. - parallel: set to True to do them in parallel, false to do linearly + parallel: set to True to do them in parallel, false to do linearly callback_func: function that takes as argument the suite that was just finished or the project that was just made. - This function MUST replace the original object in order to synchronize the + This function MUST replace the original object in order to synchronize the threads' data. """ self.abort_run = False - + start = time.time() - + # Age all the old results self.age() - + # How many thread in parallel? one fewer threads than the # of cpus num_threads = multiprocessing.cpu_count()-1 if num_threads < 1: num_threads = 1 - + # Now let's run the make test command for each one if make_tests: # This is a list of all projects that are needed (selected ones only) @@ -1258,15 +1258,15 @@ def run_tests_in_parallel(self, selected_only=True, make_tests=True, parallel=Tr for pj in self.projects: if pj.is_anything_selected() or (not selected_only): pj_to_build.append(pj) - - all_builds_successful = True + + all_builds_successful = True for pj in pj_to_build: # Abort when requested if self.abort_run: break # Run the make command pj.make(callback_func) # Callback when completed a project - if not callback_func is None: + if not callback_func is None: callback_func(pj) all_builds_successful = all_builds_successful and pj.build_succeeded # Set the build failure to all suites that are selected @@ -1279,49 +1279,49 @@ def run_tests_in_parallel(self, selected_only=True, make_tests=True, parallel=Tr # Send a message that all builds were good! if all_builds_successful and (not callback_func is None): callback_func(MSG_ALL_BUILDS_SUCCESSFUL) - - - - - + + + + + # Build a long list of all (selected and successfully built) suites suites = self.get_selected_suites(selected_only) - + if parallel: - # Make the pool + # Make the pool p = Pool( num_threads ) - + # Call the method that will run each suite results = [] for suite in suites: result = p.apply_async( run_tests_in_suite, (self, suite, None), callback=callback_func) results.append( (result, suite) ) p.close() - + # This will block until completed p.join() - + else: for suite in suites: result = run_tests_in_suite( self, suite, callback_func) if not callback_func is None: callback_func(result) - + # Now we compile all the projects' states for pj in self.projects: pj.compile_states() self.compile_states() print "... %s tests %sand completed in %f seconds ..." % (["All", "Selected"][selected_only], ["","built "][parallel], (time.time() - start)) - - + + # Global variable containing a list of all the available test projects -global all_tests -all_tests = MultipleProjects() +global all_tests +all_tests = MultipleProjects() #================================================================================================== def test_run_print_callback(obj): """ Simple callback for running tests. This is called into the MainProcess. - + Parameters: obj :: the object, either a TestSuite or TestProject that was just calculated """ @@ -1330,19 +1330,19 @@ def test_run_print_callback(obj): suite = obj print "Done running %s" % suite.classname all_tests.replace_suite(suite) - + elif isinstance(obj, TestProject): pj = obj # Replace the project in THIS thread! all_tests.replace_project( pj ) print "Made project %s" % pj.name - + else: pass -# print "-->" + obj -# sys.stdout.flush() - - +# print "-->" + obj +# sys.stdout.flush() + + #================================================================================================== @@ -1357,7 +1357,7 @@ def run_command_with_callback(full_command, callback_func, run_shell=True): output :: accumulated stdoutput """ output = "" - + if not run_shell: full_command = shlex.split(full_command) @@ -1385,16 +1385,16 @@ def run_command_with_callback(full_command, callback_func, run_shell=True): #Keep reading output. line=get.readline() - # Do we prematurely abort it? + # Do we prematurely abort it? if all_tests.abort_run: p.kill() if not callback_func is None: callback_func("Aborted by user.") break - + # The return code or exit status p.wait() status = p.returncode - + return (status, output) @@ -1403,7 +1403,7 @@ def run_command_with_callback(full_command, callback_func, run_shell=True): #================================================================================================== def run_command_with_timeout(full_command, timeout, run_shell=True): """Run a shell command with a timeout. - + Parameters: full_command :: shell command callback_func :: command @@ -1411,7 +1411,7 @@ def run_command_with_timeout(full_command, timeout, run_shell=True): status :: status code output :: accumulated stdoutput """ - + # Object to run a command in a process with a timeout. class Command(object): def __init__(self, cmd, run_shell): @@ -1420,34 +1420,34 @@ def __init__(self, cmd, run_shell): self.run_shell = run_shell self.returncode = 0 self.output = "" - + def run(self, timeout): def target(): self.process = subprocess.Popen(self.cmd, shell=self.run_shell, stdin=None, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, close_fds=True, universal_newlines=True) (self.output, stdin) = self.process.communicate() - + thread = threading.Thread(target=target) thread.start() - + thread.join(timeout) if thread.is_alive(): self.process.terminate() thread.join() - + self.returncode = self.process.returncode - - + + if not run_shell: full_command = shlex.split(full_command) command = Command(full_command, run_shell) command.run(timeout) - + output = command.output # Status is -15 when it times out status = command.returncode - + return (status, output) @@ -1455,10 +1455,10 @@ def target(): - + +#================================================================================== +#=================== Unit Tests ==================== #================================================================================== -#=================== Unit Tests ==================== -#================================================================================== def test_results_compiling(): r = TestResult() assert r.value == TestResult.NOT_RUN @@ -1474,7 +1474,7 @@ def test_results_compiling(): assert r.value == TestResult.SOME_FAILED r.add(TestResult.BUILD_ERROR) assert r.value == TestResult.BUILD_ERROR - + r = TestResult() assert r.value == TestResult.NOT_RUN r.add(TestResult.ALL_FAILED) @@ -1494,39 +1494,39 @@ def test_age(): a.state = TestResult(TestResult.ALL_PASSED) a.age() assert (a.state.old) - -test_results_compiling() + +test_results_compiling() test_age() - - - + + + #================================================================================================== if __name__ == '__main__': # run_command_with_timeout("echo 'Process started'; sleep 2; echo 'Process finished'", timeout=3) # run_command_with_timeout("echo 'Process started'; sleep 2; echo 'Process finished'", timeout=1) - + all_tests.discover_CXX_projects("/home/8oz/Code/Mantid/Code/Mantid/bin/", "/home/8oz/Code/Mantid/Code/Mantid/Framework/") all_tests.select_svn() all_tests.select_all(False) - + suite = all_tests.find_suite("MDEventsTest.MDEventTest") suite.run_tests(test_run_print_callback, 'test_Constructors') - + # suite = all_tests.find_suite("MDEventsTest.MDEventTest") # suite.set_selected(True) # suite = all_tests.find_suite("KernelTest.ConfigServiceTest") # suite.set_selected(True) -# all_tests.run_tests_in_parallel(selected_only=True, make_tests=True, +# all_tests.run_tests_in_parallel(selected_only=True, make_tests=True, # parallel=True, callback_func=test_run_print_callback) - + # for pj in all_tests.projects: # print pj.name, pj.get_state_str() # for suite in pj.suites: # print suite.classname, suite.get_state_str() -# -# all_tests.run_tests_in_parallel(selected_only=False, make_tests=True, +# +# all_tests.run_tests_in_parallel(selected_only=False, make_tests=True, # parallel=False, callback_func=test_run_print_callback) @@ -1540,6 +1540,5 @@ def other_test(): #print kt.suites print "----" kt.suites[16].run_tests() - - - \ No newline at end of file + + diff --git a/Code/Tools/TestViewer/test_tree.py b/Code/Tools/TestViewer/test_tree.py index 6f22a9e8a51c..ac53c73d42d7 100644 --- a/Code/Tools/TestViewer/test_tree.py +++ b/Code/Tools/TestViewer/test_tree.py @@ -13,40 +13,40 @@ import datetime HORIZONTAL_HEADERS = ("Test", "Status", "Time (sec)", "Last Run") - - - -# ======================================================================================= + + + +# ======================================================================================= def format_time(seconds): """Return a string for the # of seconds """ if seconds < 1e-3: return "0.000" else: - return "%.3f" % (seconds) - + return "%.3f" % (seconds) + def format_time_elapsed(lastrun): """Returns the time elapsed since the test was last run, as a friendly string.""" - + if lastrun is None: return "-" - + td = datetime.datetime.now() - lastrun # TIme elapsed in seconds (onl;y python 2.7 has .total_seconds() seconds = (td.seconds + td.days * 24 * 3600) min = seconds / 60 hour = seconds / 3600 - + if seconds < 60: - return "%d s ago" % (seconds) + return "%d s ago" % (seconds) elif min < 10: - return "%d:%02d m ago" % (min, seconds-min*60) + return "%d:%02d m ago" % (min, seconds-min*60) elif min < 60: - return "%d m ago" % (min) + return "%d m ago" % (min) else: - return "%d:%02d h ago" % (hour, min-hour*60) - -# ======================================================================================= + return "%d:%02d h ago" % (hour, min-hour*60) + +# ======================================================================================= class MyColors: """ Some custom colors I want """ veryLightGray = QColor(220, 220, 220) @@ -54,59 +54,59 @@ class MyColors: darkishGreen = QColor( 64, 128, 64) lightRed = QColor( 255, 200, 200) mediumRed = QColor( 255, 150, 150) - + def desaturate(color, amount): """Desaturate a color by pct. Parameters: amount: fraction between 0.0 and 1.0. 1.0 = fully saturated; 0.0 = desaturated """ - red = color.red() - green = color.green() - blue = color.blue() + red = color.red() + green = color.green() + blue = color.blue() gray = 0.3 * red + 0.4 * green + 0.3 * blue return QColor( gray * amount + red * (1 - amount), gray * amount + green * (1 - amount), gray * amount + blue * (1 - amount) ) - -# ======================================================================================= + +# ======================================================================================= def get_background_color(state): """Return the background color for this test result. Parameters state :: TestResult """ if not isinstance(state, test_info.TestResult): return QVariant() - + col = QColor(Qt.lightGray) if state == test_info.TestResult.NOT_RUN: col = MyColors.veryLightGray - + elif state == test_info.TestResult.ALL_PASSED: col = MyColors.lightGreen if state.old: col = MyColors.darkishGreen - + elif state == test_info.TestResult.ALL_FAILED or (state == test_info.TestResult.SOME_FAILED) \ or state == test_info.TestResult.ABORTED: col = QColor(Qt.red) if state.old: col = QColor( 200, 50, 50 ) - + elif state == test_info.TestResult.BUILD_ERROR: col = QColor(Qt.magenta) if state.old: col = desaturate(col, 0.5) - + # elif state == test_info.TestResult.SOME_FAILED: # col = MyColors.lightRed # if state.old: col = MyColors.lightRed - + else: return QVariant() - + # Copy constructor col = QColor( col ) - - return col - + + return col -# ======================================================================================= + +# ======================================================================================= class TreeItemBase(object): """ Base class for common tree items with a ".contents" member.""" def __init__(self, contents, parentItem): @@ -118,7 +118,7 @@ def __init__(self, contents, parentItem): def appendChild(self, item): self.childItems.append(item) - + def clearChildren(self): self.childItems = [] @@ -128,26 +128,26 @@ def child(self, row): def childCount(self): return len(self.childItems) - #----------------------------------------------------------------------------------- + #----------------------------------------------------------------------------------- def parent(self): return self.parentItem - + def row(self): if self.parentItem: return self.parentItem.childItems.index(self) return 0 - + def background_color(self): """Return the background color for this item""" return get_background_color(self.contents.state) - - #----------------------------------------------------------------------------------- + + #----------------------------------------------------------------------------------- def data(self, column): if self.contents is None: if column == 0: return QtCore.QVariant(self.header) if column >= 1: - return QtCore.QVariant("") + return QtCore.QVariant("") else: if column == 0: return QtCore.QVariant(self.contents.name) @@ -155,17 +155,17 @@ def data(self, column): return QtCore.QVariant(self.contents.get_state_str()) if column == 2: return QtCore.QVariant( self.contents.runtime ) - if column == 3: + if column == 3: return QtCore.QVariant( format_time_elapsed(self.contents.lastrun) ) return QtCore.QVariant() -# ======================================================================================= +# ======================================================================================= class TreeItemProject(TreeItemBase): ''' A python object used to return row/column data, and keep note of it's parents and/or children. - + This one represents a TestProject ''' def __init__(self, project, parentItem): @@ -174,23 +174,23 @@ def __init__(self, project, parentItem): def columnCount(self): return 4 - #----------------------------------------------------------------------------------- + #----------------------------------------------------------------------------------- def is_checked(self): - return [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked][self.contents.get_selected()] - + return [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked][self.contents.get_selected()] + def set_checked(self, value): self.contents.selected = value for suite in self.contents.suites: suite.selected = value - -# ======================================================================================= + +# ======================================================================================= class TreeItemSuite(TreeItemBase): ''' A python object used to return row/column data, and keep note of it's parents and/or children. - + This one represents a TestSuite ''' def __init__(self, suite, parentItem): @@ -200,22 +200,22 @@ def __init__(self, suite, parentItem): def columnCount(self): """Column count of the children?""" return 4 - - #----------------------------------------------------------------------------------- + + #----------------------------------------------------------------------------------- def is_checked(self): - return [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked][self.contents.get_selected()] - + return [Qt.Unchecked, Qt.Checked, Qt.PartiallyChecked][self.contents.get_selected()] + def set_checked(self, value): self.contents.set_selected( value ) -# ======================================================================================= +# ======================================================================================= class TreeItemSingle(TreeItemBase): ''' A python object used to return row/column data, and keep note of it's parents and/or children. - + This one represents a TestSingle ''' def __init__(self, test, parentItem): @@ -224,11 +224,11 @@ def __init__(self, test, parentItem): def columnCount(self): return 4 - + def is_checked(self): """ Can't check at the single test level """ return QVariant() - + def set_checked(self, value): """ Can't check at the single test level """ pass @@ -238,7 +238,7 @@ def set_checked(self, value): -# ======================================================================================= +# ======================================================================================= class TestTreeModel(QtCore.QAbstractItemModel): ''' A tree model that displays a hierarchy of TestProject.TestSuite.TestSingle @@ -248,14 +248,14 @@ def __init__(self, parent=None): super(TestTreeModel, self).__init__(parent) # Make a root tree item self.rootItem = TreeItemProject(None, None) - # Dictionary with key = project name; value = the TreeItemProject + # Dictionary with key = project name; value = the TreeItemProject self.projects = {} - + self.setupModelData() self.setup_checks() - + # Now set up the checkability - + #---------------------------------------------------------------------------------- def flags(self, index): flag = Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsTristate @@ -283,18 +283,18 @@ def data(self, index, role): # Return the data to display in the item if role == QtCore.Qt.DisplayRole: return item.data(index.column()) - - # Return the checked state + + # Return the checked state if role == QtCore.Qt.CheckStateRole: if index.column() == 0: return item.is_checked() else: - return QVariant() - - # What background color? + return QVariant() + + # What background color? if role == Qt.BackgroundRole: return item.background_color(); - + #User role is used when directly querying the contents of the item if role == Qt.UserRole: if not item is None: @@ -313,7 +313,7 @@ def setData(self, index, value, role): item = index.internalPointer() if item is None: return False - + # Return the checked state if role == QtCore.Qt.CheckStateRole: item.set_checked( value==Qt.Checked ) @@ -321,9 +321,9 @@ def setData(self, index, value, role): self.update_project(item.contents.name) if isinstance(item, TreeItemSuite): self.update_project(item.contents.parent.name) - + return True - + return False # if index.column() == 0: # return Qt.Checked @@ -340,7 +340,7 @@ def get_project(self, project_name): project_indx = self.index(row, 0, QModelIndex()) return (project_indx, project_item) return (QModelIndex(), None) - + #---------------------------------------------------------------------------------- def update_project(self, project_name): """ Updates the data displayed in a specific project""" @@ -356,7 +356,7 @@ def update_all(self): topLeft = self.index(0, 0, QModelIndex()) bottomRight = self.index( self.rootItem.childCount()-1, 0, QModelIndex()) self.emit( QtCore.SIGNAL("dataChanged(const QModelIndex &, const QModelIndex &)"), topLeft, bottomRight) - + #---------------------------------------------------------------------------------- def update_suite(self, suite): """Updates the data for only the given suite. """ @@ -382,7 +382,7 @@ def update_suite(self, suite): suite_item.appendChild(test_item) self.endInsertRows() break - + else: # Just update the data for i in xrange(num_suites): @@ -422,7 +422,7 @@ def index(self, row, column, parent): else: return QtCore.QModelIndex() - #----------------------------------------------------------------------------------- + #----------------------------------------------------------------------------------- def parent(self, index): if not index.isValid(): return QtCore.QModelIndex() @@ -430,7 +430,7 @@ def parent(self, index): childItem = index.internalPointer() if not childItem: return QtCore.QModelIndex() - + parentItem = childItem.parent() if parentItem == self.rootItem: @@ -438,7 +438,7 @@ def parent(self, index): return self.createIndex(parentItem.row(), 0, parentItem) - #----------------------------------------------------------------------------------- + #----------------------------------------------------------------------------------- def rowCount(self, parent=QtCore.QModelIndex()): if parent.column() > 0: return 0 @@ -447,8 +447,8 @@ def rowCount(self, parent=QtCore.QModelIndex()): else: p_Item = parent.internalPointer() return p_Item.childCount() - - #----------------------------------------------------------------------------------- + + #----------------------------------------------------------------------------------- def setupModelData(self): for pj in test_info.all_tests.projects: # What's the corresponding TreeItemProject @@ -459,21 +459,21 @@ def setupModelData(self): # Make a new one pj_item = TreeItemProject(pj, self.rootItem) self.rootItem.appendChild(pj_item) - + # Now fill the suites if not pj_item is None: for suite in pj.suites: if not suite is None: suite_item = TreeItemSuite(suite, pj_item) pj_item.appendChild(suite_item) - + # Now lets fill the TestSingle's for test in suite.tests: test_item = TreeItemSingle(test, suite_item) suite_item.appendChild(test_item) - - - #----------------------------------------------------------------------------------- + + + #----------------------------------------------------------------------------------- def setup_checks(self): # Number of root projects rowcount = self.rowCount( QModelIndex() ) @@ -499,18 +499,18 @@ def __init__(self, parent=None): super(TreeFilterProxyModel, self).__init__(parent) self.failed_only = False self.selected_only = False - + #---------------------------------------------------------------------------------- def set_filter_failed_only(self, value): """ Do we filter to show only the failed tests? """ self.failed_only = value self.invalidateFilter() - + def set_filter_selected_only(self, value): """ Do we filter to show only the selected tests? """ self.selected_only = value self.invalidateFilter() - + #---------------------------------------------------------------------------------- def filterAcceptsColumn(self, source_col, parent_index): """ Always show all columns""" @@ -520,10 +520,10 @@ def filterAcceptsColumn(self, source_col, parent_index): def filterAcceptsRow(self, source_row, parent_index): """Return true if the row is accepted by the filter """ - # If we're not filtering by anything, return True + # If we're not filtering by anything, return True if not self.failed_only and not self.selected_only: return True - + source = self.sourceModel() # Get the index in the source model of this particular row index = source.index(source_row, 0, parent_index) @@ -538,19 +538,19 @@ def filterAcceptsRow(self, source_row, parent_index): else: # Don't filter out TestSingles based on selection (since they're all selected) return True - # Gets here if it passes through both filters - return True - + # Gets here if it passes through both filters + return True + return True - - + + def dumby(obj): print "DOUBLE CLICKED", obj -if __name__ == "__main__": +if __name__ == "__main__": app = QtGui.QApplication([]) - + test_info.all_tests.discover_CXX_projects("/home/8oz/Code/Mantid/Code/Mantid/bin/", "/home/8oz/Code/Mantid/Code/Mantid/Framework/") test_info.all_tests.make_fake_results() @@ -561,10 +561,10 @@ def dumby(obj): tv = QtGui.QTreeView(dialog) - + tv.setAlternatingRowColors(True) layout.addWidget(tv) - + model = TestTreeModel() proxy = TreeFilterProxyModel() proxy.setDynamicSortFilter(True) @@ -572,7 +572,7 @@ def dumby(obj): proxy.set_filter_failed_only(False) #proxy.setFilterWildcard("*G*") tv.setModel(proxy) - + dialog.show() app.exec_() #dialog.exec_() diff --git a/Code/Tools/VTKConverter/VTKConvert.py b/Code/Tools/VTKConverter/VTKConvert.py index f5d56297c1c9..161b2fe69d72 100644 --- a/Code/Tools/VTKConverter/VTKConvert.py +++ b/Code/Tools/VTKConverter/VTKConvert.py @@ -21,12 +21,12 @@ def convertToVTU(infile, outpath): planelist=[] planelist.append(numbers) npoints += 1 - + # Append last set datalist.append(planelist) datafile.close() - - ncells = len(datalist) + + ncells = len(datalist) doc = minidom.Document() vtkfile = doc.createElement("VTKFile") @@ -34,20 +34,20 @@ def convertToVTU(infile, outpath): vtkfile.setAttribute("type","UnstructuredGrid") vtkfile.setAttribute("version","0.1") vtkfile.setAttribute("byte_order", "LittleEndian") - + ugrid = doc.createElement("UnstructuredGrid") vtkfile.appendChild(ugrid) piece = doc.createElement("Piece") ugrid.appendChild(piece) - + piece.setAttribute( "NumberOfPoints", str(npoints)) piece.setAttribute( "NumberOfCells", str(ncells)) - + # First the PointData element point_data = doc.createElement("PointData") piece.appendChild(point_data) point_data.setAttribute("Scalars", "Intensity") - + data_array = doc.createElement("DataArray") point_data.appendChild(data_array) data_array.setAttribute("type", "Float32") @@ -62,7 +62,7 @@ def convertToVTU(infile, outpath): # Now the Points element points = doc.createElement("Points") piece.appendChild(points) - + data_array = doc.createElement("DataArray") points.appendChild(data_array) data_array.setAttribute("type", "Float32") @@ -94,13 +94,13 @@ def convertToVTU(infile, outpath): data_array.setAttribute("type", "Int32") data_array.setAttribute("Name", "offsets") data_array.setAttribute("format","ascii") - + i = 0 for plane in datalist: i += len(plane) txt = doc.createTextNode(str(i)) data_array.appendChild(txt) - + data_array = doc.createElement("DataArray") cells.appendChild(data_array) data_array.setAttribute("type", "Int32") @@ -117,13 +117,13 @@ def convertToVTU(infile, outpath): file = open(name,'w') doc.writexml(file, newl="\n") file.close() - + del datalist del planelist del doc def writeParallelVTU(files, prefix): - + doc = minidom.Document() vtkfile = doc.createElement("VTKFile") @@ -135,7 +135,7 @@ def writeParallelVTU(files, prefix): pugrid = doc.createElement("PUnstructuredGrid") vtkfile.appendChild(pugrid) pugrid.setAttribute("GhostLevel", "0") - + ppointdata = doc.createElement("PPointData") pugrid.appendChild(ppointdata) ppointdata.setAttribute("Scalars","Intensity") @@ -156,7 +156,7 @@ def writeParallelVTU(files, prefix): piece = doc.createElement("Piece") pugrid.appendChild(piece) piece.setAttribute("Source",name + ".vtu") - + # print doc.toprettyxml(newl="\n") filename = prefix + files[0].split('.')[0] + ".pvtu" # print filename diff --git a/Code/Tools/VTKConverter/processISISData.py b/Code/Tools/VTKConverter/processISISData.py index 7ed6fb4716be..7d00849ca3f3 100644 --- a/Code/Tools/VTKConverter/processISISData.py +++ b/Code/Tools/VTKConverter/processISISData.py @@ -6,7 +6,7 @@ if( len(sys.argv) == 1 ): print "Usage: processISISData file-name1 file-name2 ...\n processISISDATA dir-name" exit(1) - + names=[] is_dir = os.path.isdir(sys.argv[1]) if( is_dir ): diff --git a/Code/Tools/scripts/AddAlgorithmWikiLinksToText.py b/Code/Tools/scripts/AddAlgorithmWikiLinksToText.py index fafd7ee3bd1e..e372fe01a338 100644 --- a/Code/Tools/scripts/AddAlgorithmWikiLinksToText.py +++ b/Code/Tools/scripts/AddAlgorithmWikiLinksToText.py @@ -13,5 +13,5 @@ algs = AlgorithmFactory.getRegisteredAlgorithms(True) for alg in algs: - text = re.sub(r'\b' + alg+ r'\b',r'[http://docs.mantidproject.org/algorithms/' + alg + '.html ' + alg + '] ',text) + text = re.sub(r'\b' + alg+ r'\b',r'[http://docs.mantidproject.org/algorithms/' + alg + '.html ' + alg + '] ',text) print text \ No newline at end of file diff --git a/Code/Tools/scripts/ConvertBadAlgmLinks.py b/Code/Tools/scripts/ConvertBadAlgmLinks.py index b598ef44f6b7..4d7d71e86989 100644 --- a/Code/Tools/scripts/ConvertBadAlgmLinks.py +++ b/Code/Tools/scripts/ConvertBadAlgmLinks.py @@ -23,11 +23,11 @@ def grep(patt,lines): regexs[alg] = re.compile(r'`%s\s+<[\w\:\/\.]+\/%s>`_' % (alg,alg)) -# Example use +# Example use dir = r"C:\Mantid\Code\Mantid\docs\source\algorithms" files = glob.glob(os.path.join(dir, '*.rst')) for filename in files: - + #print os.path.basename(filename)[:-4] with open(filename) as file: lines = file.readlines() diff --git a/Code/Tools/scripts/CorrectConceptLinksinAlgPages.py b/Code/Tools/scripts/CorrectConceptLinksinAlgPages.py index 0cb7836d03b5..700472f05294 100644 --- a/Code/Tools/scripts/CorrectConceptLinksinAlgPages.py +++ b/Code/Tools/scripts/CorrectConceptLinksinAlgPages.py @@ -61,18 +61,18 @@ def outputError(alg, algVersion, description, notes=""): fileFound = False filename = os.path.join(rstdir,alg + "-v" + str(algVersion) + ".rst") if os.path.exists(filename): - algText = "" - with open (filename, "r") as algRst: - fileFound = True - algText = algRst.read() - for concept in concepts: - regex = conceptsPattern[concept] - while (regex.search(algText) != None): - outputError(alg, algVersion, "found", concept) - algText = regex.sub(r":ref:`\1 <\2>`",algText) - with open (filename, "w") as algRst: - algRst.write(algText) - + algText = "" + with open (filename, "r") as algRst: + fileFound = True + algText = algRst.read() + for concept in concepts: + regex = conceptsPattern[concept] + while (regex.search(algText) != None): + outputError(alg, algVersion, "found", concept) + algText = regex.sub(r":ref:`\1 <\2>`",algText) + with open (filename, "w") as algRst: + algRst.write(algText) + if fileFound==False: outputError(alg, algVersion, "File not found") - + diff --git a/Code/Tools/scripts/FindIncompleteAlgRSTPages.py b/Code/Tools/scripts/FindIncompleteAlgRSTPages.py index 33139d28057d..27cd76c148f5 100644 --- a/Code/Tools/scripts/FindIncompleteAlgRSTPages.py +++ b/Code/Tools/scripts/FindIncompleteAlgRSTPages.py @@ -8,15 +8,15 @@ def readWebPage(url): aResp =urllib2.urlopen(url) web_pg = aResp.read(); return web_pg - + def ticketExists(alg, ticketHash): retVal = "" algPattern = re.compile(alg, re.IGNORECASE) for ticket in ticketHash: - ticketText = ticketHash[ticket] - if algPattern.search(ticketText): - retVal = str(ticket) - break + ticketText = ticketHash[ticket] + if algPattern.search(ticketText): + retVal = str(ticket) + break return retVal def outputError(alg, algVersion, description, notes=""): @@ -27,7 +27,7 @@ def outputError(alg, algVersion, description, notes=""): ticketHash = {} for ticket in ticketList: - ticketHash[ticket] = readWebPage( r"http://trac.mantidproject.org/mantid/ticket/" + str(ticket)) + ticketHash[ticket] = readWebPage( r"http://trac.mantidproject.org/mantid/ticket/" + str(ticket)) usagePattern = re.compile('Usage', re.IGNORECASE) excusesPattern = re.compile('(rarely called directly|designed to work with other algorithms|only used for testing|deprecated)', re.IGNORECASE) @@ -35,17 +35,17 @@ def outputError(alg, algVersion, description, notes=""): algs = AlgorithmFactory.getRegisteredAlgorithms(True) for alg in algs: - algVersion = algs[alg][0] - fileFound = False - filename = os.path.join(rstdir,alg + "-v" + str(algVersion) + ".rst") - if os.path.exists(filename): - with open (filename, "r") as algRst: - fileFound = True - algText = algRst.read() - if (usagePattern.search(algText) == None) and (excusesPattern.search(algText) == None): - #check if already in a ticket - usageTicket = ticketExists(alg,ticketHash) - outputError(alg, algVersion, "No usage section", usageTicket) - if fileFound==False: - outputError(alg, algVersion, "File not found") - + algVersion = algs[alg][0] + fileFound = False + filename = os.path.join(rstdir,alg + "-v" + str(algVersion) + ".rst") + if os.path.exists(filename): + with open (filename, "r") as algRst: + fileFound = True + algText = algRst.read() + if (usagePattern.search(algText) == None) and (excusesPattern.search(algText) == None): + #check if already in a ticket + usageTicket = ticketExists(alg,ticketHash) + outputError(alg, algVersion, "No usage section", usageTicket) + if fileFound==False: + outputError(alg, algVersion, "File not found") +