def test_view(simple_workflow_with_intents, qtbot): # Tests ingesting an internally run workflow, projecting it, storing it in a model # and using a CanvasView to display it @live_plugin('PlotMixinPlugin') class PlotMixinTest(PlotWidget): def __init__(self, *args, **kwargs): super(PlotMixinTest, self).__init__(*args, background='g', **kwargs) @live_plugin('ImageMixinPlugin') class ImageMixinTest(ImageView): def __init__(self, *args, **kwargs): super(ImageMixinTest, self).__init__(*args, **kwargs) self.setStyleSheet('* {background-color:green;}') execution.executor = LocalExecutor() ensemble_model = EnsembleModel() intents_model = IntentsModel() intents_model.setSourceModel(ensemble_model) data_selector_view = DataSelectorView() data_selector_view.setModel(ensemble_model) stacked_canvas_view = StackedCanvasView() stacked_canvas_view.setModel(intents_model) widget = QWidget() layout = QHBoxLayout() layout.addWidget(stacked_canvas_view) layout.addWidget(data_selector_view) widget.setLayout(layout) def showResult(*result): ensemble = Ensemble() doc_generator = ingest_result_set(simple_workflow_with_intents, result) documents = list(doc_generator) catalog = BlueskyInMemoryCatalog() catalog.upsert(documents[0][1], documents[-1][1], ingest_result_set, [simple_workflow_with_intents, result], {}) catalog = catalog[-1] ensemble.append_catalog(catalog) ensemble_model.add_ensemble(ensemble, project_intents) qtbot.wait(1000) root = ensemble_model.index(0, 0, QModelIndex()) ensemble_model.setData(root.child(0, 0), True, Qt.CheckStateRole) widget.setMinimumSize(800, 600) widget.show() qtbot.addWidget(widget) workflow_editor = WorkflowEditor(simple_workflow_with_intents, callback_slot=showResult) workflow_editor.run_workflow() qtbot.wait(3000)
def test_blend(qtbot, plot_data): # Ensure non-BetterLayout and BetterLayout mixins are compatible # TODO: upgrade from smoke test (assert that Log button AND curve labels work) class BlendClass(CurveLabels, LogButtons): ... widget = BlendClass() widget.plot(x=plot_data[0], y=plot_data[1]) widget.show() qtbot.wait(5000)
def test_menu(qtbot): workflow_editor = WorkflowEditor(Workflow()) workflow_editor.show() qtbot.addWidget(workflow_editor) manager.qt_is_safe = True manager.initialize_types() manager.collect_plugins() qtbot.wait(10000)
def showResult(*result): ensemble = Ensemble() doc_generator = ingest_result_set(simple_workflow_with_intents, result) documents = list(doc_generator) catalog = BlueskyInMemoryCatalog() catalog.upsert(documents[0][1], documents[-1][1], ingest_result_set, [simple_workflow_with_intents, result], {}) catalog = catalog[-1] ensemble.append_catalog(catalog) ensemble_model.add_ensemble(ensemble, project_intents) qtbot.wait(1000) root = ensemble_model.index(0, 0, QModelIndex()) ensemble_model.setData(root.child(0, 0), True, Qt.CheckStateRole)
def test_profile_and_display_results(qtbot, tmpdir, monkeypatch): """Run profiler on simple script and check that results are okay.""" os.chdir(tmpdir.strpath) testfilename = tmpdir.join('test_foo.py').strpath with open(testfilename, 'w') as f: f.write(TEST_SCRIPT) MockQMessageBox = Mock() monkeypatch.setattr( 'spyder_line_profiler.widgets.lineprofiler.QMessageBox', MockQMessageBox) widget = LineProfilerWidget(None) qtbot.addWidget(widget) widget.analyze(testfilename) qtbot.wait(2000) # wait for tests to run MockQMessageBox.assert_not_called() dt = widget.datatree assert dt.topLevelItemCount() == 1 # number of functions profiled top = dt.topLevelItem(0) assert top.data(0, Qt.DisplayRole).startswith('foo ') assert top.childCount() == 6 for i in range(6): assert top.child(i).data(0, Qt.DisplayRole) == i + 2 # line no assert top.child(2).data(1, Qt.DisplayRole) == '1' # hits assert top.child(3).data(1, Qt.DisplayRole) == '1' assert top.child(4).data(1, Qt.DisplayRole) == '101' assert top.child(5).data(1, Qt.DisplayRole) == '100' assert float(top.child(2).data(2, Qt.DisplayRole)) >= 900 # time (ms) assert float(top.child(2).data(2, Qt.DisplayRole)) <= 1200 assert float(top.child(3).data(2, Qt.DisplayRole)) <= 100 assert float(top.child(4).data(2, Qt.DisplayRole)) <= 100 assert float(top.child(5).data(2, Qt.DisplayRole)) <= 100
def test_profile_and_display_results(qtbot, tmpdir, monkeypatch): """Run profiler on simple script and check that results are okay.""" os.chdir(tmpdir.strpath) testfilename = tmpdir.join('test_foo.py').strpath with open(testfilename, 'w') as f: f.write(TEST_SCRIPT) MockQMessageBox = Mock() monkeypatch.setattr( 'spyder_memory_profiler.widgets.memoryprofiler.QMessageBox', MockQMessageBox) widget = MemoryProfilerWidget(None) qtbot.addWidget(widget) widget.analyze(testfilename) qtbot.wait(2000) # wait for tests to run MockQMessageBox.assert_not_called() dt = widget.datatree assert dt.topLevelItemCount() == 1 # number of functions profiled top = dt.topLevelItem(0) assert top.data(0, Qt.DisplayRole).startswith('foo ') assert top.childCount() == 6 for i in range(6): assert top.child(i).data(0, Qt.DisplayRole) == i + 1 # line no # column 2 has increment (in Mib); displayed as 'xxx MiB' so need to strip # last 4 characters assert float(top.child(2).data( 2, Qt.DisplayRole)[:-4]) >= 7 # increment (MiB) assert float(top.child(2).data(2, Qt.DisplayRole)[:-4]) <= 8 assert float(top.child(3).data(2, Qt.DisplayRole)[:-4]) >= 150 assert float(top.child(3).data(2, Qt.DisplayRole)[:-4]) <= 160 assert float(top.child(4).data(2, Qt.DisplayRole)[:-4]) >= -160 assert float(top.child(4).data(2, Qt.DisplayRole)[:-4]) <= -150 assert float(top.child(5).data(2, Qt.DisplayRole)[:-4]) == 0
def test_application(qtbot): sys.argv = sys.argv[:1] main_window = _main([], exec=False) qtbot.addWidget(main_window) qtbot.wait(6000) # give it time to finish loading qtbot.waitForWindowShown(main_window)
def test_view(simple_workflow_with_intents, qtbot): # Tests ingesting an internally run workflow, projecting it, storing it in a model # and using a CanvasView to display it plugin_manager.qt_is_safe = True plugin_manager.initialize_types() plugin_manager.collect_plugins() pc = next( filter(lambda task: task.name == 'plot_canvas', plugin_manager._tasks)) plugin_manager._load_plugin(pc) plugin_manager._instantiate_plugin(pc) ic = next( filter(lambda task: task.name == 'image_canvas', plugin_manager._tasks)) plugin_manager._load_plugin(ic) plugin_manager._instantiate_plugin(ic) plot_intent_task = next( filter(lambda task: task.name == 'PlotIntent', plugin_manager._tasks)) plugin_manager._load_plugin(plot_intent_task) plugin_manager._instantiate_plugin(plot_intent_task) image_intent_task = next( filter(lambda task: task.name == 'ImageIntent', plugin_manager._tasks)) plugin_manager._load_plugin(image_intent_task) plugin_manager._instantiate_plugin(image_intent_task) execution.executor = LocalExecutor() ensemble_model = EnsembleModel() intents_model = IntentsModel() intents_model.setSourceModel(ensemble_model) data_selector_view = DataSelectorView() data_selector_view.setModel(ensemble_model) stacked_canvas_view = StackedCanvasView() stacked_canvas_view.setModel(intents_model) widget = QWidget() layout = QHBoxLayout() layout.addWidget(stacked_canvas_view) layout.addWidget(data_selector_view) widget.setLayout(layout) def showResult(*result): ensemble = Ensemble() doc_generator = ingest_result_set(simple_workflow_with_intents, result) documents = list(doc_generator) catalog = BlueskyInMemoryCatalog() catalog.upsert(documents[0][1], documents[-1][1], ingest_result_set, [simple_workflow_with_intents, result], {}) catalog = catalog[-1] ensemble.append_catalog(catalog) ensemble_model.add_ensemble(ensemble, project_intents) qtbot.wait(1000) root = ensemble_model.index(0, 0, QModelIndex()) ensemble_model.setData(root.child(0, 0), True, Qt.CheckStateRole) widget.setMinimumSize(800, 600) widget.show() qtbot.addWidget(widget) workflow_editor = WorkflowEditor(simple_workflow_with_intents, callback_slot=showResult) workflow_editor.run_workflow() qtbot.wait(7000)