1 | import sys |
---|
2 | import unittest |
---|
3 | |
---|
4 | from PyQt5 import QtGui, QtWidgets |
---|
5 | |
---|
6 | # set up import paths |
---|
7 | import sas.qtgui.path_prepare |
---|
8 | |
---|
9 | # Local |
---|
10 | from sas.qtgui.Plotting.ScaleProperties import ScaleProperties |
---|
11 | |
---|
12 | if not QtWidgets.QApplication.instance(): |
---|
13 | app = QtWidgets.QApplication(sys.argv) |
---|
14 | |
---|
15 | class ScalePropertiesTest(unittest.TestCase): |
---|
16 | '''Test the ScaleProperties''' |
---|
17 | def setUp(self): |
---|
18 | '''Create the ScaleProperties''' |
---|
19 | |
---|
20 | self.widget = ScaleProperties(None) |
---|
21 | |
---|
22 | def tearDown(self): |
---|
23 | '''Destroy the GUI''' |
---|
24 | self.widget.close() |
---|
25 | self.widget = None |
---|
26 | |
---|
27 | def testDefaults(self): |
---|
28 | '''Test the GUI in its default state''' |
---|
29 | self.assertIsInstance(self.widget, QtWidgets.QDialog) |
---|
30 | self.assertEqual(self.widget.windowTitle(), "Scale Properties") |
---|
31 | self.assertEqual(self.widget.cbX.count(), 6) |
---|
32 | self.assertEqual(self.widget.cbY.count(), 12) |
---|
33 | self.assertEqual(self.widget.cbView.count(), 7) |
---|
34 | |
---|
35 | def testGetValues(self): |
---|
36 | '''Test the values returned''' |
---|
37 | self.assertEqual(self.widget.getValues(), ("x", "y")) |
---|
38 | self.widget.cbX.setCurrentIndex(2) |
---|
39 | self.widget.cbY.setCurrentIndex(4) |
---|
40 | self.assertEqual(self.widget.getValues(), ("x^(4)", "y*x^(2)")) |
---|
41 | |
---|
42 | def testSettingView(self): |
---|
43 | '''Test various settings of view''' |
---|
44 | self.widget.cbView.setCurrentIndex(1) |
---|
45 | self.assertEqual(self.widget.getValues(), ("x", "y")) |
---|
46 | self.widget.cbView.setCurrentIndex(6) |
---|
47 | self.assertEqual(self.widget.getValues(), ("x", "y*x^(2)")) |
---|
48 | |
---|
49 | # Assure the View combobox resets on the x index changes |
---|
50 | self.assertNotEqual(self.widget.cbView.currentIndex(), 0) |
---|
51 | self.widget.cbX.setCurrentIndex(2) |
---|
52 | self.assertEqual(self.widget.cbView.currentIndex(), 0) |
---|
53 | |
---|
54 | # Same for Y |
---|
55 | self.widget.cbView.setCurrentIndex(6) |
---|
56 | self.assertNotEqual(self.widget.cbView.currentIndex(), 0) |
---|
57 | self.widget.cbY.setCurrentIndex(2) |
---|
58 | self.assertEqual(self.widget.cbView.currentIndex(), 0) |
---|
59 | |
---|
60 | if __name__ == "__main__": |
---|
61 | unittest.main() |
---|