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

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 9f25bce was 3bdbfcc, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Reimplementation of the slicer functionality

  • Property mode set to 100755
File size: 2.2 KB
Line 
1import sys
2import unittest
3from mock import MagicMock
4
5from PyQt4 import QtGui
6from PyQt4 import QtCore
7
8# set up import paths
9import path_prepare
10
11# Local
12from SlicerModel import SlicerModel
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.