Changeset 6d05e1d in sasview for src/sas/qtgui/UnitTesting
- Timestamp:
- Dec 6, 2016 3:39:24 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 55d89f8
- Parents:
- b94889a
- git-author:
- Piotr Rozyczko <rozyczko@…> (12/06/16 03:38:55)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (12/06/16 03:39:24)
- Location:
- src/sas/qtgui/UnitTesting
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/DataExplorerTest.py
r31c5b58 r6d05e1d 506 506 self.assertTrue(self.form.manager.add_data.called) 507 507 508 def testNewPlot (self):508 def testNewPlot1D(self): 509 509 """ 510 510 Creating new plots from Data1D/2D … … 521 521 # get Data1D 522 522 p_file="cyl_400_20.txt" 523 output_object = loader.load(p_file) 524 new_data = [manager.create_gui_data(output_object, p_file)] 525 526 # Mask retrieval of the data 527 self.form.plotsFromCheckedItems = MagicMock(return_value=new_data) 528 529 # Mask plotting 530 self.form.parent.workspace = MagicMock() 531 532 # Call the plotting method 533 self.form.newPlot() 534 535 # The plot was registered 536 self.assertEqual(len(PlotHelper.currentPlots()), 1) 537 538 self.assertTrue(self.form.cbgraph.isEnabled()) 539 self.assertTrue(self.form.cmdAppend.isEnabled()) 540 541 def testNewPlot2D(self): 542 """ 543 Creating new plots from Data1D/2D 544 """ 545 loader = Loader() 546 manager = DataManager() 547 PlotHelper.clear() 548 self.form.enableGraphCombo(None) 549 550 # Make sure the controls are disabled 551 self.assertFalse(self.form.cbgraph.isEnabled()) 552 self.assertFalse(self.form.cmdAppend.isEnabled()) 553 554 # get Data2D 555 p_file="Dec07031.ASC" 523 556 output_object = loader.load(p_file) 524 557 new_data = [manager.create_gui_data(output_object, p_file)] -
src/sas/qtgui/UnitTesting/PlotterTest.py
- Property mode changed from 100755 to 100644
rf721030 r6d05e1d 1 import sys 2 import unittest 3 4 from PyQt4 import QtGui 5 from PyQt4 import QtCore 6 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 7 from mock import MagicMock 8 9 ####### TEMP 10 import LocalSetup 11 ####### 12 from sas.sasgui.guiframe.dataFitting import Data1D 13 from sas.sasgui.guiframe.dataFitting import Data2D 14 from UnitTesting.TestUtils import QtSignalSpy 15 16 # Tested module 17 import sas.qtgui.Plotter as Plotter 18 19 app = QtGui.QApplication(sys.argv) 20 21 class PlotterTest(unittest.TestCase): 22 '''Test the Plotter 1D class''' 23 def setUp(self): 24 '''create''' 25 self.plotter = Plotter.Plotter(None, quickplot=True) 26 self.data = Data1D(x=[1.0, 2.0, 3.0], 27 y=[10.0, 11.0, 12.0], 28 dx=[0.1, 0.2, 0.3], 29 dy=[0.1, 0.2, 0.3]) 30 self.data.title="Test data" 31 self.data.id = 1 32 33 def tearDown(self): 34 '''destroy''' 35 self.plotter = None 36 37 def testDataProperty(self): 38 """ Adding data """ 39 self.plotter.data = self.data 40 41 self.assertEqual(self.plotter.data, self.data) 42 self.assertEqual(self.plotter._title, self.data.title) 43 self.assertEqual(self.plotter.xLabel, "$()$") 44 self.assertEqual(self.plotter.yLabel, "$()$") 45 46 def testPlot(self): 47 """ Look at the plotting """ 48 self.plotter.data = self.data 49 self.plotter.show() 50 FigureCanvas.draw = MagicMock() 51 52 self.plotter.plot() 53 54 self.assertTrue(FigureCanvas.draw.called) 55 56 def testContextMenuQuickPlot(self): 57 """ Test the right click menu """ 58 actions = self.plotter.contextMenu.actions() 59 self.assertEqual(len(actions), 7) 60 61 # Trigger Save Image and make sure the method is called 62 self.assertEqual(actions[0].text(), "Save Image") 63 self.plotter.toolbar.save_figure = MagicMock() 64 actions[0].trigger() 65 self.assertTrue(self.plotter.toolbar.save_figure.called) 66 67 # Trigger Print Image and make sure the method is called 68 self.assertEqual(actions[1].text(), "Print Image") 69 QtGui.QPrintDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 70 actions[1].trigger() 71 self.assertTrue(QtGui.QPrintDialog.exec_.called) 72 73 # Trigger Copy to Clipboard and make sure the method is called 74 self.assertEqual(actions[2].text(), "Copy to Clipboard") 75 76 # Spy on cliboard's dataChanged() signal 77 self.clipboard_called = False 78 def done(): 79 self.clipboard_called = True 80 QtCore.QObject.connect(app.clipboard(), QtCore.SIGNAL("dataChanged()"), done) 81 actions[2].trigger() 82 QtGui.qApp.processEvents() 83 # Make sure clipboard got updated. 84 self.assertTrue(self.clipboard_called) 85 86 # Trigger Toggle Grid and make sure the method is called 87 self.assertEqual(actions[4].text(), "Toggle Grid On/Off") 88 self.plotter.ax.grid = MagicMock() 89 actions[4].trigger() 90 self.assertTrue(self.plotter.ax.grid.called) 91 92 # Trigger Change Scale and make sure the method is called 93 self.assertEqual(actions[6].text(), "Change Scale") 94 self.plotter.properties.exec_ = MagicMock(return_value=QtGui.QDialog.Rejected) 95 actions[6].trigger() 96 self.assertTrue(self.plotter.properties.exec_.called) 97 98 def testXYTransform(self): 99 """ Assure the unit/legend transformation is correct""" 100 self.plotter.data = self.data 101 102 self.plotter.xyTransform(xLabel="ln(x)", yLabel="ln(y)") 103 self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 104 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 105 106 self.plotter.xyTransform(xLabel="ln(x)", yLabel="ln(y)") 107 self.assertEqual(self.plotter.ax.get_xlabel(), "$\\ln{()}()$") 108 self.assertEqual(self.plotter.ax.get_ylabel(), "$\\ln{()}()$") 109 110 self.plotter.xyTransform(xLabel="x^(2)", yLabel="1/sqrt(y)") 111 self.assertEqual(self.plotter.ax.get_xlabel(), "$^{2}(()^{2})$") 112 self.assertEqual(self.plotter.ax.get_ylabel(), "$1/\\sqrt{}(()^{-0.5})$") 113 114 if __name__ == "__main__": 115 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.