source: sasview/src/sas/qtgui/UnitTesting/DataExplorerTest.py @ ba0dc71

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since ba0dc71 was 39551a68, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

More context menu functionality + tests

  • Property mode set to 100755
File size: 25.0 KB
Line 
1import sys
2import unittest
3
4from PyQt4.QtGui import *
5from PyQt4.QtTest import QTest
6from PyQt4.QtCore import *
7from mock import MagicMock
8
9# Local
10from sas.sasgui.guiframe.dataFitting import Data1D
11from sas.sascalc.dataloader.loader import Loader
12from sas.sasgui.guiframe.data_manager import DataManager
13
14from DataExplorer import DataExplorerWindow
15from GuiManager import GuiManager
16from GuiUtils import *
17from UnitTesting.TestUtils import QtSignalSpy
18from Plotter import Plotter
19import PlotHelper
20
21app = QApplication(sys.argv)
22
23class DataExplorerTest(unittest.TestCase):
24    '''Test the Data Explorer GUI'''
25    def setUp(self):
26        '''Create the GUI'''
27        class MyPerspective(object):
28            def communicator(self):
29                return Communicate()
30            def allowBatch(self):
31                return False
32            def setData(self, data_item=None):
33                return None
34            def title(self):
35                return "Dummy Perspective"
36
37        class dummy_manager(object):
38            def communicator(self):
39                return Communicate()
40            def perspective(self):
41                return MyPerspective()
42            def workspace(self):
43                return None
44
45        self.form = DataExplorerWindow(None, dummy_manager())
46
47    def tearDown(self):
48        '''Destroy the GUI'''
49        self.form.close()
50        self.form = None
51
52    def testDefaults(self):
53        '''Test the GUI in its default state'''
54        # Tab widget
55        self.assertIsInstance(self.form, QTabWidget)
56        self.assertEqual(self.form.count(), 2)
57
58        # Buttons - data tab
59        self.assertEqual(self.form.cmdLoad.text(), "Load")
60        self.assertEqual(self.form.cmdDeleteData.text(), "Delete")
61        self.assertEqual(self.form.cmdDeleteTheory.text(), "Delete")
62        self.assertEqual(self.form.cmdFreeze.text(), "Freeze Theory")
63        self.assertEqual(self.form.cmdSendTo.text(), "...")
64        self.assertEqual(self.form.cmdSendTo.iconSize(), QSize(32, 32))
65        self.assertIsInstance(self.form.cmdSendTo.icon(), QIcon)
66        self.assertEqual(self.form.chkBatch.text(), "Batch mode")
67        self.assertFalse(self.form.chkBatch.isChecked())
68
69        # Buttons - theory tab
70
71        # Combo boxes
72        self.assertEqual(self.form.cbSelect.count(), 6)
73        self.assertEqual(self.form.cbSelect.currentIndex(), 0)
74
75        # Models - data
76        self.assertIsInstance(self.form.model, QStandardItemModel)
77        self.assertEqual(self.form.treeView.model().rowCount(), 0)
78        self.assertEqual(self.form.treeView.model().columnCount(), 0)
79        self.assertEqual(self.form.model.rowCount(), 0)
80        self.assertEqual(self.form.model.columnCount(), 0)
81        self.assertIsInstance(self.form.data_proxy, QSortFilterProxyModel)
82        self.assertEqual(self.form.data_proxy.sourceModel(), self.form.model)
83        self.assertEqual("[^()]", str(self.form.data_proxy.filterRegExp().pattern()))
84        self.assertIsInstance(self.form.treeView, QTreeView)
85
86        # Models - theory
87        self.assertIsInstance(self.form.theory_model, QStandardItemModel)
88        self.assertEqual(self.form.freezeView.model().rowCount(), 0)
89        self.assertEqual(self.form.freezeView.model().columnCount(), 0)
90        self.assertEqual(self.form.theory_model.rowCount(), 0)
91        self.assertEqual(self.form.theory_model.columnCount(), 0)
92        self.assertIsInstance(self.form.theory_proxy, QSortFilterProxyModel)
93        self.assertEqual(self.form.theory_proxy.sourceModel(), self.form.theory_model)
94        self.assertEqual("[^()]", str(self.form.theory_proxy.filterRegExp().pattern()))
95        self.assertIsInstance(self.form.freezeView, QTreeView)
96
97    def testWidgets(self):
98        """
99        Test if all required widgets got added
100        """
101    def testLoadButton(self):
102        loadButton = self.form.cmdLoad
103
104        filename = "cyl_400_20.txt"
105        # Initialize signal spy instances
106        spy_file_read = QtSignalSpy(self.form, self.form.communicator.fileReadSignal)
107
108        # Return no files.
109        QtGui.QFileDialog.getOpenFileNames = MagicMock(return_value=None)
110
111        # Click on the Load button
112        QTest.mouseClick(loadButton, Qt.LeftButton)
113
114        # Test the getOpenFileName() dialog called once
115        self.assertTrue(QtGui.QFileDialog.getOpenFileNames.called)
116        QtGui.QFileDialog.getOpenFileNames.assert_called_once()
117
118        # Make sure the signal has not been emitted
119        self.assertEqual(spy_file_read.count(), 0)
120
121        # Now, return a single file
122        QtGui.QFileDialog.getOpenFileNames = MagicMock(return_value=filename)
123
124        # Click on the Load button
125        QTest.mouseClick(loadButton, Qt.LeftButton)
126        QtGui.qApp.processEvents()
127
128        # Test the getOpenFileName() dialog called once
129        self.assertTrue(QtGui.QFileDialog.getOpenFileNames.called)
130        QtGui.QFileDialog.getOpenFileNames.assert_called_once()
131
132        # Expected one spy instance
133        #self.assertEqual(spy_file_read.count(), 1)
134        #self.assertIn(filename, str(spy_file_read.called()[0]['args'][0]))
135
136    def testLoadFiles(self):
137        """
138        Test progress bar update while loading of multiple files
139        """
140        # Set up the spy on progress bar update signal
141        spy_progress_bar_update = QtSignalSpy(self.form,
142            self.form.communicator.progressBarUpdateSignal)
143
144        # Populate the model
145        filename = ["cyl_400_20.txt", "Dec07031.ASC", "cyl_400_20.txt"]
146        self.form.readData(filename)
147
148        # 0, 0, 33, 66, -1 -> 5 signals reaching progressBar
149        self.assertEqual(spy_progress_bar_update.count(), 5)
150
151        expected_list = [0, 0, 33, 66, -1]
152        spied_list = [spy_progress_bar_update.called()[i]['args'][0] for i in xrange(5)]
153        self.assertEqual(expected_list, spied_list)
154       
155    def testDeleteButton(self):
156        """
157        Functionality of the delete button
158        """
159        deleteButton = self.form.cmdDeleteData
160
161        # Mock the confirmation dialog with return=No
162        QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)
163
164        # Populate the model
165        filename = ["cyl_400_20.txt", "Dec07031.ASC", "cyl_400_20.txt"]
166        self.form.readData(filename)
167
168        # Assure the model contains three items
169        self.assertEqual(self.form.model.rowCount(), 3)
170
171        # Assure the checkboxes are on
172        item1 = self.form.model.item(0)
173        item2 = self.form.model.item(1)
174        item3 = self.form.model.item(2)
175        self.assertTrue(item1.checkState() == QtCore.Qt.Checked)
176        self.assertTrue(item2.checkState() == QtCore.Qt.Checked)
177        self.assertTrue(item3.checkState() == QtCore.Qt.Checked)
178
179        # Click on the delete  button
180        QTest.mouseClick(deleteButton, Qt.LeftButton)
181
182        # Test the warning dialog called once
183        self.assertTrue(QtGui.QMessageBox.question.called)
184
185        # Assure the model still contains the items
186        self.assertEqual(self.form.model.rowCount(), 3)
187
188        # Now, mock the confirmation dialog with return=Yes
189        QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)
190
191        # Click on the delete  button
192        QTest.mouseClick(deleteButton, Qt.LeftButton)
193
194        # Test the warning dialog called once
195        self.assertTrue(QtGui.QMessageBox.question.called)
196
197        # Assure the model contains no items
198        self.assertEqual(self.form.model.rowCount(), 0)
199
200        # Click delete once again to assure no nasty behaviour on empty model
201        QTest.mouseClick(deleteButton, Qt.LeftButton)
202
203    def testDeleteTheory(self):
204        """
205        Test that clicking "Delete" in theories tab removes selected indices
206        """
207        deleteButton = self.form.cmdDeleteTheory
208
209        # Mock the confirmation dialog with return=No
210        QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.No)
211
212        # Populate the model
213        item1 = QtGui.QStandardItem(True)
214        item1.setCheckable(True)
215        item1.setCheckState(QtCore.Qt.Checked)
216        item1.setText("item 1")
217        self.form.theory_model.appendRow(item1)
218        item2 = QtGui.QStandardItem(True)
219        item2.setCheckable(True)
220        item2.setCheckState(QtCore.Qt.Unchecked)
221        item2.setText("item 2")
222        self.form.theory_model.appendRow(item2)
223
224        # Assure the model contains two items
225        self.assertEqual(self.form.theory_model.rowCount(), 2)
226
227        # Assure the checkboxes are on
228        self.assertTrue(item1.checkState() == QtCore.Qt.Checked)
229        self.assertTrue(item2.checkState() == QtCore.Qt.Unchecked)
230
231        # Click on the delete  button
232        QTest.mouseClick(deleteButton, Qt.LeftButton)
233
234        # Test the warning dialog called once
235        self.assertTrue(QtGui.QMessageBox.question.called)
236
237        # Assure the model still contains the items
238        self.assertEqual(self.form.theory_model.rowCount(), 2)
239
240        # Now, mock the confirmation dialog with return=Yes
241        QtGui.QMessageBox.question = MagicMock(return_value=QtGui.QMessageBox.Yes)
242
243        # Click on the delete  button
244        QTest.mouseClick(deleteButton, Qt.LeftButton)
245
246        # Test the warning dialog called once
247        self.assertTrue(QtGui.QMessageBox.question.called)
248
249        # Assure the model contains 1 item
250        self.assertEqual(self.form.theory_model.rowCount(), 1)
251
252        # Set the remaining item to checked
253        self.form.theory_model.item(0).setCheckState(QtCore.Qt.Checked)
254
255        # Click on the delete button again
256        QTest.mouseClick(deleteButton, Qt.LeftButton)
257
258        # Assure the model contains no items
259        self.assertEqual(self.form.theory_model.rowCount(), 0)
260
261        # Click delete once again to assure no nasty behaviour on empty model
262        QTest.mouseClick(deleteButton, Qt.LeftButton)
263
264
265    def testSendToButton(self):
266        """
267        Test that clicking the Send To button sends checked data to a perspective
268        """
269        # Send empty data
270        mocked_perspective = self.form.parent.perspective()
271        mocked_perspective.setData = MagicMock()
272
273        # Click on the Send To  button
274        QTest.mouseClick(self.form.cmdSendTo, Qt.LeftButton)
275
276        # The set_data method not called
277        self.assertFalse(mocked_perspective.setData.called)
278               
279        # Populate the model
280        filename = ["cyl_400_20.txt"]
281        self.form.readData(filename)
282
283        # setData is the method we want to see called
284        mocked_perspective = self.form.parent.perspective()
285        mocked_perspective.setData = MagicMock(filename)
286
287        # Assure the checkbox is on
288        self.form.cbSelect.setCurrentIndex(0)
289
290        # Click on the Send To  button
291        QTest.mouseClick(self.form.cmdSendTo, Qt.LeftButton)
292
293        # Test the set_data method called once
294        #self.assertTrue(mocked_perspective.setData.called)
295
296        # open another file
297        filename = ["cyl_400_20.txt"]
298        self.form.readData(filename)
299
300        # Mock the warning message
301        QtGui.QMessageBox = MagicMock()
302
303        # Click on the button
304        QTest.mouseClick(self.form.cmdSendTo, Qt.LeftButton)
305
306        # Assure the message box popped up
307        QtGui.QMessageBox.assert_called_once()
308
309    def testDataSelection(self):
310        """
311        Tests the functionality of the Selection Option combobox
312        """
313        # Populate the model with 1d and 2d data
314        filename = ["cyl_400_20.txt", "Dec07031.ASC"]
315        self.form.readData(filename)
316
317        # Unselect all data
318        self.form.cbSelect.setCurrentIndex(1)
319
320        # Test the current selection
321        item1D = self.form.model.item(0)
322        item2D = self.form.model.item(1)
323        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked)
324        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)       
325
326        # Select all data
327        self.form.cbSelect.setCurrentIndex(0)
328
329        # Test the current selection
330        self.assertTrue(item1D.checkState() == QtCore.Qt.Checked)
331        self.assertTrue(item2D.checkState() == QtCore.Qt.Checked)       
332
333        # select 1d data
334        self.form.cbSelect.setCurrentIndex(2)
335
336        # Test the current selection
337        self.assertTrue(item1D.checkState() == QtCore.Qt.Checked)
338        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)       
339
340        # unselect 1d data
341        self.form.cbSelect.setCurrentIndex(3)
342
343        # Test the current selection
344        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked)
345        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)       
346
347        # select 2d data
348        self.form.cbSelect.setCurrentIndex(4)
349
350        # Test the current selection
351        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked)
352        self.assertTrue(item2D.checkState() == QtCore.Qt.Checked)       
353
354        # unselect 2d data
355        self.form.cbSelect.setCurrentIndex(5)
356
357        # Test the current selection
358        self.assertTrue(item1D.checkState() == QtCore.Qt.Unchecked)
359        self.assertTrue(item2D.checkState() == QtCore.Qt.Unchecked)       
360
361        # choose impossible index and assure the code raises
362        #with self.assertRaises(Exception):
363        #    self.form.cbSelect.setCurrentIndex(6)
364
365    def testFreezeTheory(self):
366        """
367        Assure theory freeze functionality works
368        """
369        # Not yet tested - agree on design first.
370        pass
371
372    def testRecursivelyCloneItem(self):
373        """
374        Test the rescursive QAbstractItem/QStandardItem clone
375        """
376        # Create an item with several branches
377        item1 = QtGui.QStandardItem()
378        item2 = QtGui.QStandardItem()
379        item3 = QtGui.QStandardItem()
380        item4 = QtGui.QStandardItem()
381        item5 = QtGui.QStandardItem()
382        item6 = QtGui.QStandardItem()
383
384        item4.appendRow(item5)
385        item2.appendRow(item4)
386        item2.appendRow(item6)
387        item1.appendRow(item2)
388        item1.appendRow(item3)
389
390        # Clone
391        new_item = self.form.recursivelyCloneItem(item1)
392
393        # assure the trees look identical
394        self.assertEqual(item1.rowCount(), new_item.rowCount())
395        self.assertEqual(item1.child(0).rowCount(), new_item.child(0).rowCount())
396        self.assertEqual(item1.child(1).rowCount(), new_item.child(1).rowCount())
397        self.assertEqual(item1.child(0).child(0).rowCount(), new_item.child(0).child(0).rowCount())
398
399    def testReadData(self):
400        """
401        Test the low level readData() method
402        """
403        filename = ["cyl_400_20.txt"]
404        self.form.manager.add_data = MagicMock()
405
406        # Initialize signal spy instances
407        spy_status_update = QtSignalSpy(self.form, self.form.communicator.statusBarUpdateSignal)
408        spy_data_received = QtSignalSpy(self.form, self.form.communicator.fileDataReceivedSignal)
409
410        # Read in the file
411        self.form.readData(filename)
412
413        # Expected two status bar updates
414        self.assertEqual(spy_status_update.count(), 1)
415        self.assertIn(filename[0], str(spy_status_update.called()[0]['args'][0]))
416
417
418        # Check that the model contains the item
419        self.assertEqual(self.form.model.rowCount(), 1)
420        self.assertEqual(self.form.model.columnCount(), 1)
421
422        # The 0th item header should be the name of the file
423        model_item = self.form.model.index(0,0)
424        model_name = str(self.form.model.data(model_item).toString())
425        self.assertEqual(model_name, filename[0])
426
427    def testDisplayHelp(self):
428        """
429        Test that the Help window gets shown correctly
430        """
431        partial_url = "sasgui/guiframe/data_explorer_help.html"
432        button1 = self.form.cmdHelp
433        button2 = self.form.cmdHelp_2
434
435        # Click on the Help button
436        QTest.mouseClick(button1, Qt.LeftButton)
437        qApp.processEvents()
438
439        # Check the browser
440        self.assertIn(partial_url, str(self.form._helpView.url()))
441        # Close the browser
442        self.form._helpView.close()
443
444        # Click on the Help_2 button
445        QTest.mouseClick(button2, Qt.LeftButton)
446        qApp.processEvents()
447        # Check the browser
448        self.assertIn(partial_url, str(self.form._helpView.url()))
449
450    def testLoadFile(self):
451        """
452        Test the threaded call to readData()
453        """
454        #self.form.loadFile()
455        pass
456
457    def testGetWList(self):
458        """
459        Test the list of known extensions
460        """
461        w_list = self.form.getWlist()
462
463        defaults = 'All (*.*);;canSAS files (*.xml);;SESANS files' +\
464            ' (*.ses);;ASCII files (*.txt);;IGOR 2D files (*.asc);;' +\
465            'IGOR/DAT 2D Q_map files (*.dat);;IGOR 1D files (*.abs);;'+\
466            'HFIR 1D files (*.d1d);;DANSE files (*.sans);;NXS files (*.nxs)'
467        default_list = defaults.split(';;')
468
469        for def_format in default_list:
470            self.assertIn(def_format, w_list)
471       
472    def testLoadComplete(self):
473        """
474        Test the callback method updating the data object
475        """
476        message="Loading Data Complete"
477        data_dict = {"a1":Data1D()}
478        output_data = (data_dict, message)
479
480        self.form.manager.add_data = MagicMock()
481
482        # Initialize signal spy instances
483        spy_status_update = QtSignalSpy(self.form, self.form.communicator.statusBarUpdateSignal)
484        spy_data_received = QtSignalSpy(self.form, self.form.communicator.fileDataReceivedSignal)
485
486        # Read in the file
487        self.form.loadComplete(output_data)
488
489        # "Loading data complete" no longer sent in LoadFile but in callback
490        self.assertIn("Loading Data Complete", str(spy_status_update.called()[0]['args'][0]))
491
492        # Expect one Data Received signal
493        self.assertEqual(spy_data_received.count(), 1)
494
495        # Assure returned dictionary has correct data
496        # We don't know the data ID, so need to iterate over dict
497        data_dict = spy_data_received.called()[0]['args'][0]
498        for data_key, data_value in data_dict.iteritems():
499            self.assertIsInstance(data_value, Data1D)
500
501        # Assure add_data on data_manager was called (last call)
502        self.assertTrue(self.form.manager.add_data.called)
503
504    def testNewPlot(self):
505        """
506        Creating new plots from Data1D/2D
507        """
508        loader = Loader()
509        manager = DataManager()
510        PlotHelper.clear()
511        self.form.enableGraphCombo(None)
512
513        # Make sure the controls are disabled
514        self.assertFalse(self.form.cbgraph.isEnabled())
515        self.assertFalse(self.form.cmdAppend.isEnabled())
516
517        # get Data1D
518        p_file="cyl_400_20.txt"
519        output_object = loader.load(p_file)
520        new_data = [manager.create_gui_data(output_object, p_file)]
521
522        # Mask the plot show call
523        Plotter.show = MagicMock()
524
525        # Mask retrieval of the data
526        self.form.plotsFromCheckedItems = MagicMock(return_value=new_data)
527
528        # Mask plotting
529        self.form.parent.workspace = MagicMock()
530
531        # Call the plotting method
532        self.form.newPlot()
533
534        # The plot was displayed
535        self.assertTrue(Plotter.show.called)
536
537        # The plot was registered
538        self.assertEqual(len(PlotHelper.currentPlots()), 1)
539
540        self.assertTrue(self.form.cbgraph.isEnabled())
541        self.assertTrue(self.form.cmdAppend.isEnabled())
542
543    def testAppendPlot(self):
544        """
545        Creating new plots from Data1D/2D
546        """
547        loader = Loader()
548        manager = DataManager()
549
550        PlotHelper.clear()
551        self.form.enableGraphCombo(None)
552
553        # Make sure the controls are disabled
554        self.assertFalse(self.form.cbgraph.isEnabled())
555        self.assertFalse(self.form.cmdAppend.isEnabled())
556
557        # get Data1D
558        p_file="cyl_400_20.txt"
559        output_object = loader.load(p_file)
560        new_data = [manager.create_gui_data(output_object, p_file)]
561
562        # Mask plotting
563        self.form.parent.workspace = MagicMock()
564
565        # Mask the plot show call
566        Plotter.show = MagicMock()
567
568        # Mask retrieval of the data
569        self.form.plotsFromCheckedItems = MagicMock(return_value=new_data)
570
571        # Call the plotting method
572        self.form.newPlot()
573
574        # Call the plotting method again, so we have 2 graphs
575        self.form.newPlot()
576
577        # See that we have two plots
578        self.assertEqual(len(PlotHelper.currentPlots()), 2)
579
580        # Add data to plot #1
581        self.form.cbgraph.setCurrentIndex(1)
582        self.form.appendPlot()
583
584        # See that we still have two plots
585        self.assertEqual(len(PlotHelper.currentPlots()), 2)
586
587    def testUpdateGraphCombo(self):
588        """
589        Test the combo box update
590        """
591        PlotHelper.clear()
592
593        graph_list=[1,2,3]
594        self.form.updateGraphCombo(graph_list)
595
596        self.assertEqual(self.form.cbgraph.count(), 3)
597        self.assertEqual(self.form.cbgraph.currentText(), 'Graph1')
598
599        graph_list=[]
600        self.form.updateGraphCombo(graph_list)
601        self.assertEqual(self.form.cbgraph.count(), 0)
602
603    def testUpdateModelFromPerspective(self):
604        """
605        Assure the model update is correct
606        """
607        good_item = QtGui.QStandardItem()
608        bad_item = "I'm so bad"
609
610        self.form.model.reset = MagicMock()
611
612        self.form.updateModelFromPerspective(good_item)
613
614        # See that the model got reset
615        self.form.model.reset.assert_called_once()
616
617        # See that the bad item causes raise
618        with self.assertRaises(Exception):
619            self.form.updateModelFromPerspective(bad_item)
620
621    def testContextMenu(self):
622        """
623        See if the context menu is present
624        """
625        # get Data1D
626        p_file=["cyl_400_20.txt"]
627        # Read in the file
628        output, message = self.form.readData(p_file)
629        self.form.loadComplete((output, message))
630
631        # Pick up the treeview index corresponding to that file
632        index = self.form.treeView.indexAt(QtCore.QPoint(5,5))
633        self.form.show()
634
635        # Find out the center pointof the treeView row
636        rect = self.form.treeView.visualRect(index).center()
637
638        self.form.context_menu.exec_ = MagicMock()
639
640        # Move the mouse pointer to the first row
641        QTest.mouseMove(self.form.treeView.viewport(), pos=rect)
642
643        # This doesn't invoke the action/signal. Investigate why?
644        # QTest.mouseClick(self.form.treeView.viewport(), Qt.RightButton, pos=rect)
645
646        # Instead, send the signal directly
647        self.form.treeView.customContextMenuRequested.emit(rect)
648
649        # app.exec_() # debug
650
651        # See that the menu has been shown
652        self.form.context_menu.exec_.assert_called_once()
653
654    def testShowDataInfo(self):
655        """
656        Test of the showDataInfo method
657        """
658        # get Data1D
659        p_file=["cyl_400_20.txt"]
660        # Read in the file
661        output, message = self.form.readData(p_file)
662        self.form.loadComplete((output, message))
663
664        # select the data
665        self.form.treeView.selectAll()
666
667        # Call the tested method
668        self.form.showDataInfo()
669
670        # Test the properties
671        self.assertTrue(self.form.txt_widget.isReadOnly())
672        self.assertEqual(self.form.txt_widget.windowTitle(), "Data Info: cyl_400_20.txt")
673        self.assertIn("Waveln_max", self.form.txt_widget.toPlainText())
674
675        # Slider moved all the way up
676        self.assertEqual(self.form.txt_widget.verticalScrollBar().sliderPosition(), 0)
677
678    def testSaveDataAs(self):
679        """
680        Test the Save As context menu action
681        """
682        # get Data1D
683        p_file=["cyl_400_20.txt"]
684        # Read in the file
685        output, message = self.form.readData(p_file)
686        self.form.loadComplete((output, message))
687
688        # select the data
689        self.form.treeView.selectAll()
690
691        QFileDialog.getSaveFileName = MagicMock()
692
693        # Call the tested method
694        self.form.saveDataAs()
695        QFileDialog.getSaveFileName.assert_called_with(
696                                caption="Save As",
697                                directory='cyl_400_20_out.txt',
698                                filter='Text files (*.txt);;CanSAS 1D files(*.xml)',
699                                parent=None)
700        QFileDialog.getSaveFileName.assert_called_once()
701
702        # get Data2D
703        p_file=["Dec07031.ASC"]
704        # Read in the file
705        output, message = self.form.readData(p_file)
706        self.form.loadComplete((output, message))
707
708        # select the data
709        index = self.form.model.index(1, 0)
710        selmodel = self.form.treeView.selectionModel()
711        selmodel.setCurrentIndex(index, QItemSelectionModel.NoUpdate)
712        selmodel.select(index, QItemSelectionModel.Select|QItemSelectionModel.Rows)
713
714        QFileDialog.getSaveFileName = MagicMock()
715
716        # Call the tested method
717        self.form.saveDataAs()
718        QFileDialog.getSaveFileName.assert_called_with(
719                                caption="Save As",
720                                directory='Dec07031_out.dat',
721                                filter='IGOR/DAT 2D file in Q_map (*.dat)',
722                                parent=None)
723        QFileDialog.getSaveFileName.assert_called_once()
724
725    def testQuickDataPlot(self):
726        """
727        Quick data plot generation.
728
729        TODO: add content once plotting finalized
730        """
731        pass
732
733if __name__ == "__main__":
734    unittest.main()
Note: See TracBrowser for help on using the repository browser.