source: sasview/src/sas/qtgui/Plotting/UnitTesting/SlicerModelTest.py @ 9d266d2

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 9d266d2 was 83eb5208, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Putting files in more ordered fashion

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[3bdbfcc]1import sys
2import unittest
3from mock import MagicMock
4
5from PyQt4 import QtGui
6from PyQt4 import QtCore
7
8# set up import paths
[83eb5208]9import sas.qtgui.path_prepare
[3bdbfcc]10
11# Local
[83eb5208]12from sas.qtgui.Plotting.SlicerModel import SlicerModel
[3bdbfcc]13
14app = QtGui.QApplication(sys.argv)
15
16class SlicerModelTest(unittest.TestCase):
17    '''Test the SlicerModel'''
18    def setUp(self):
19        '''Create the SlicerModel'''
20        class SModel(SlicerModel):
21            params = {"a":1, "b":2}
22            def __init__(self):
23                SlicerModel.__init__(self)
24            def getParams(self):
25                return self.params
26            def setParams(self, par):
27                self.params = par
28        self.model = SModel()
29
30    def tearDown(self):
31        '''Destroy the model'''
32        self.model = None
33
34    def testBaseClass(self):
35        '''Assure that SlicerModel contains pure virtuals'''
36        model = SlicerModel()
37        with self.assertRaises(NotImplementedError):
38            model.setParams()
39        with self.assertRaises(NotImplementedError):
40            model.setModelFromParams()
41
42    def testDefaults(self):
43        '''Test the GUI in its default state'''
44        self.assertIsInstance(self.model.model(), QtGui.QStandardItemModel)
45
46    def testSetModelFromParams(self):
47        '''Test the model update'''
48        # Add a row to params
49        new_dict = self.model.getParams()
50        new_dict["c"] = 3
51        self.model.setParams(new_dict)
52
53        # Call the update
54        self.model.setModelFromParams()
55
56        # Check the new model.
57        self.assertEqual(self.model.model().rowCount(), 3)
58        self.assertEqual(self.model.model().columnCount(), 2)
59
60    def testSetParamsFromModel(self):
61        ''' Test the parameters update'''
62        # First - the default model
63        self.model.setModelFromParams()
64        self.assertEqual(self.model.model().rowCount(), 2)
65        self.assertEqual(self.model.model().columnCount(), 2)
66
67        # Add a row
68        item1 = QtGui.QStandardItem("c")
69        item2 = QtGui.QStandardItem(3)
70        self.model.model().appendRow([item1, item2])
71        # Check the new model. The update should be automatic
72        self.assertEqual(self.model.model().rowCount(), 3)
73        self.assertEqual(self.model.model().columnCount(), 2)
74
75
76if __name__ == "__main__":
77    unittest.main()
Note: See TracBrowser for help on using the repository browser.