source: sasview/src/sas/qtgui/Plotting/UnitTesting/SlicerModelTest.py @ 67642f7

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 67642f7 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

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