Changeset 2e3e959 in sasview for src/sas/qtgui/UnitTesting
- Timestamp:
- Jan 13, 2017 4:28:30 AM (8 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:
- 239214f
- Parents:
- db5cd8d
- Location:
- src/sas/qtgui/UnitTesting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/UnitTesting/LinearFitTest.py
rb46f285 r2e3e959 4 4 5 5 from PyQt4 import QtGui 6 from PyQt4 import QtCore7 6 from mock import MagicMock 8 7 … … 10 9 import path_prepare 11 10 12 from UnitTesting.TestUtils import QtSignalSpy13 11 from sas.sasgui.guiframe.dataFitting import Data1D 14 12 import sas.qtgui.Plotter as Plotter … … 61 59 # Compare 62 60 self.assertItemsEqual(return_values[0], [1.0, 3.0]) 63 self.assertItemsEqual(return_values[1], [10.004054329087303, 12.030439848443539]) 61 self.assertAlmostEqual(return_values[1][0], 10.004054329, 6) 62 self.assertAlmostEqual(return_values[1][1], 12.030439848, 6) 64 63 65 64 # Set the log scale … … 69 68 # Compare 70 69 self.assertItemsEqual(return_values[0], [1.0, 3.0]) 71 self.assertItemsEqual(return_values[1], [9.9877329376711437, 11.843650824649025]) 70 self.assertAlmostEqual(return_values[1][0], 9.987732937, 6) 71 self.assertAlmostEqual(return_values[1][1], 11.84365082, 6) 72 72 73 73 def testOrigData(self): … … 81 81 82 82 self.assertItemsEqual(x, orig_x) 83 self.assertItemsEqual(y, orig_y) 84 self.assertItemsEqual(dy, orig_dy) 83 self.assertEqual(y[0], orig_y[0]) 84 self.assertAlmostEqual(y[1], orig_y[1], 8) 85 self.assertAlmostEqual(y[2], orig_y[2], 8) 86 self.assertEqual(dy[0], orig_dy[0]) 87 self.assertAlmostEqual(dy[1], orig_dy[1], 8) 88 self.assertAlmostEqual(dy[2], orig_dy[2], 8) 85 89 86 90 # x, y … … 107 111 108 112 self.assertItemsEqual(x, orig_x) 109 self.assertItemsEqual(y, orig_y) 110 self.assertItemsEqual(dy, orig_dy) 113 self.assertEqual(y[0], orig_y[0]) 114 self.assertAlmostEqual(y[1], orig_y[1], 8) 115 self.assertAlmostEqual(y[2], orig_y[2], 8) 116 self.assertEqual(dy[0], orig_dy[0]) 117 self.assertAlmostEqual(dy[1], orig_dy[1], 8) 118 self.assertAlmostEqual(dy[2], orig_dy[2], 8) 111 119 112 120 def testCheckFitValues(self): … … 114 122 # Good values 115 123 self.assertTrue(self.widget.checkFitValues(self.widget.txtFitRangeMin)) 116 self.assertEqual(self.widget.txtFitRangeMin.palette().color(10).name(), "#f0f0f0") 124 # Colors platform dependent 125 #self.assertEqual(self.widget.txtFitRangeMin.palette().color(10).name(), "#f0f0f0") 117 126 # Bad values 118 127 self.widget.x_is_log = True -
src/sas/qtgui/UnitTesting/PlotterTest.py
rdb5cd8d r2e3e959 14 14 from sas.sasgui.guiframe.dataFitting import Data2D 15 15 from UnitTesting.TestUtils import WarningTestNotImplemented 16 from sas.qtgui.LinearFit import LinearFit 17 from sas.qtgui.PlotProperties import PlotProperties 16 18 17 19 # Tested module … … 224 226 def testOnLinearFit(self): 225 227 """ Checks the response to LinearFit call """ 226 WarningTestNotImplemented() 228 self.plotter.plot(self.data) 229 self.plotter.show() 230 QtGui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 231 232 # Just this one plot 233 self.assertEqual(len(self.plotter.plot_dict.keys()), 1) 234 self.plotter.onLinearFit(1) 235 236 # Check that exec_ got called 237 self.assertTrue(QtGui.QDialog.exec_.called) 227 238 228 239 def testOnRemovePlot(self): 229 240 """ Assure plots get removed when requested """ 230 WarningTestNotImplemented() 241 # Add two plots 242 self.plotter.show() 243 self.plotter.plot(self.data) 244 data2 = Data1D(x=[1.0, 2.0, 3.0], 245 y=[11.0, 12.0, 13.0], 246 dx=[0.1, 0.2, 0.3], 247 dy=[0.1, 0.2, 0.3]) 248 data2.title="Test data 2" 249 data2.name="Test name 2" 250 data2.id = 2 251 self.plotter.plot(data2) 252 253 # Assure the plotter window is visible 254 self.assertTrue(self.plotter.isVisible()) 255 256 # Assure we have two sets 257 self.assertEqual(len(self.plotter.plot_dict.keys()), 2) 258 259 # Delete one set 260 self.plotter.onRemovePlot(2) 261 # Assure we have two sets 262 self.assertEqual(len(self.plotter.plot_dict.keys()), 1) 263 264 self.plotter.manager = MagicMock() 265 266 # Delete the remaining set 267 self.plotter.onRemovePlot(1) 268 # Assure we have no plots 269 self.assertEqual(len(self.plotter.plot_dict.keys()), 0) 270 # Assure the plotter window is closed 271 self.assertFalse(self.plotter.isVisible()) 272 231 273 232 274 def testRemovePlot(self): 233 275 """ Test plot removal """ 234 WarningTestNotImplemented() 276 # Add two plots 277 self.plotter.show() 278 self.plotter.plot(self.data) 279 data2 = Data1D(x=[1.0, 2.0, 3.0], 280 y=[11.0, 12.0, 13.0], 281 dx=[0.1, 0.2, 0.3], 282 dy=[0.1, 0.2, 0.3]) 283 data2.title="Test data 2" 284 data2.name="Test name 2" 285 data2.id = 2 286 data2._xaxis = "XAXIS" 287 data2._xunit = "furlong*fortnight^{-1}" 288 data2._yaxis = "YAXIS" 289 data2._yunit = "cake" 290 data2.hide_error = True 291 self.plotter.plot(data2) 292 293 # delete plot 1 294 self.plotter.removePlot(1) 295 296 # See that the labels didn't change 297 xl = self.plotter.ax.xaxis.label.get_text() 298 yl = self.plotter.ax.yaxis.label.get_text() 299 self.assertEqual(xl, "$XAXIS(furlong*fortnight^{-1})$") 300 self.assertEqual(yl, "$YAXIS(cake)$") 301 # The hide_error flag should also remain 302 self.assertTrue(self.plotter.plot_dict[2].hide_error) 235 303 236 304 def testOnToggleHideError(self): 237 305 """ Test the error bar toggle on plots """ 238 WarningTestNotImplemented() 306 # Add two plots 307 self.plotter.show() 308 self.plotter.plot(self.data) 309 data2 = Data1D(x=[1.0, 2.0, 3.0], 310 y=[11.0, 12.0, 13.0], 311 dx=[0.1, 0.2, 0.3], 312 dy=[0.1, 0.2, 0.3]) 313 data2.title="Test data 2" 314 data2.name="Test name 2" 315 data2.id = 2 316 data2._xaxis = "XAXIS" 317 data2._xunit = "furlong*fortnight^{-1}" 318 data2._yaxis = "YAXIS" 319 data2._yunit = "cake" 320 error_status = True 321 data2.hide_error = error_status 322 self.plotter.plot(data2) 323 324 # Reverse the toggle 325 self.plotter.onToggleHideError(2) 326 # See that the labels didn't change 327 xl = self.plotter.ax.xaxis.label.get_text() 328 yl = self.plotter.ax.yaxis.label.get_text() 329 self.assertEqual(xl, "$XAXIS(furlong*fortnight^{-1})$") 330 self.assertEqual(yl, "$YAXIS(cake)$") 331 # The hide_error flag should toggle 332 self.assertEqual(self.plotter.plot_dict[2].hide_error, not error_status) 239 333 240 334 def testOnFitDisplay(self): 241 335 """ Test the fit line display on the chart """ 242 WarningTestNotImplemented() 336 self.assertIsInstance(self.plotter.fit_result, Data1D) 337 self.assertEqual(self.plotter.fit_result.symbol, 13) 338 self.assertEqual(self.plotter.fit_result.name, "Fit") 339 340 # fudge some init data 341 fit_data = [[0.0,0.0], [5.0,5.0]] 342 # Call the method 343 self.plotter.plot = MagicMock() 344 self.plotter.onFitDisplay(fit_data) 345 self.assertTrue(self.plotter.plot.called) 346 # Look at arguments passed to .plot() 347 self.plotter.plot.assert_called_with(data=self.plotter.fit_result, 348 hide_error=True, marker='-') 243 349 244 350 def testReplacePlot(self): 245 351 """ Test the plot refresh functionality """ 246 WarningTestNotImplemented() 247 248 def testReplacePlot(self): 249 """ Test the plot refresh functionality """ 250 WarningTestNotImplemented(sys._getframe().f_code.co_name) 352 # Add original data 353 self.plotter.show() 354 self.plotter.plot(self.data) 355 # See the default labels 356 xl = self.plotter.ax.xaxis.label.get_text() 357 yl = self.plotter.ax.yaxis.label.get_text() 358 self.assertEqual(xl, "$()$") 359 self.assertEqual(yl, "$()$") 360 361 # Prepare new data 362 data2 = Data1D(x=[1.0, 2.0, 3.0], 363 y=[11.0, 12.0, 13.0], 364 dx=[0.1, 0.2, 0.3], 365 dy=[0.1, 0.2, 0.3]) 366 data2.title="Test data 2" 367 data2.name="Test name 2" 368 data2.id = 2 369 data2._xaxis = "XAXIS" 370 data2._xunit = "furlong*fortnight^{-1}" 371 data2._yaxis = "YAXIS" 372 data2._yunit = "cake" 373 error_status = True 374 data2.hide_error = error_status 375 376 # Replace data in plot 377 self.plotter.replacePlot(1, data2) 378 379 # See that the labels changed 380 xl = self.plotter.ax.xaxis.label.get_text() 381 yl = self.plotter.ax.yaxis.label.get_text() 382 self.assertEqual(xl, "$XAXIS(furlong*fortnight^{-1})$") 383 self.assertEqual(yl, "$YAXIS(cake)$") 384 # The hide_error flag should be as set 385 self.assertEqual(self.plotter.plot_dict[2].hide_error, error_status) 251 386 252 387 def testOnModifyPlot(self): 253 388 """ Test the functionality for changing plot properties """ 254 WarningTestNotImplemented() 389 # Prepare new data 390 data2 = Data1D(x=[1.0, 2.0, 3.0], 391 y=[11.0, 12.0, 13.0], 392 dx=[0.1, 0.2, 0.3], 393 dy=[0.1, 0.2, 0.3]) 394 data2.title="Test data 2" 395 data2.name="Test name 2" 396 data2.id = 2 397 data2.custom_color = None 398 data2.symbol = 1 399 data2.markersize = 11 400 401 self.plotter.plot(data2) 402 403 with patch('PlotProperties.PlotProperties') as mock: 404 instance = mock.return_value 405 QtGui.QDialog.exec_ = MagicMock(return_value=QtGui.QDialog.Accepted) 406 instance.symbol.return_value = 7 407 408 self.plotter.onModifyPlot(2) 409 410 #print self.plotter.plot_dict[2].symbol 411 255 412 256 413 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.