[a281ab8] | 1 | import sys |
---|
| 2 | import unittest |
---|
| 3 | |
---|
| 4 | # Tested module |
---|
| 5 | from GuiUtils import * |
---|
| 6 | |
---|
| 7 | class GuiUtilsTest(unittest.TestCase): |
---|
| 8 | '''Test the GUI Utilities methods''' |
---|
| 9 | def setUp(self): |
---|
| 10 | '''Empty''' |
---|
| 11 | pass |
---|
| 12 | |
---|
| 13 | def tearDown(self): |
---|
| 14 | '''empty''' |
---|
| 15 | pass |
---|
| 16 | |
---|
| 17 | def testDefaults(self): |
---|
| 18 | """ |
---|
| 19 | Test all the global constants defined in the file. |
---|
| 20 | """ |
---|
| 21 | # Should probably test the constants in the file, |
---|
| 22 | # but this will done after trimming down GuiUtils |
---|
| 23 | # and retaining only necessary variables. |
---|
| 24 | pass |
---|
| 25 | |
---|
| 26 | def testGetAppDir(self): |
---|
| 27 | """ |
---|
| 28 | """ |
---|
| 29 | pass |
---|
| 30 | |
---|
| 31 | def testGetUserDirectory(self): |
---|
| 32 | """ |
---|
| 33 | Simple test of user directory getter |
---|
| 34 | """ |
---|
| 35 | home_dir = os.path.expanduser("~") |
---|
| 36 | self.assertIn(home_dir, get_user_directory()) |
---|
| 37 | |
---|
| 38 | def testCommunicate(self): |
---|
| 39 | """ |
---|
| 40 | Test the container class with signal definitions |
---|
| 41 | """ |
---|
| 42 | com = Communicate() |
---|
| 43 | |
---|
| 44 | # All defined signals |
---|
| 45 | list_of_signals = [ |
---|
| 46 | 'fileReadSignal', |
---|
| 47 | 'fileDataReceivedSignal', |
---|
| 48 | 'statusBarUpdateSignal', |
---|
| 49 | 'updatePerspectiveWithDataSignal', |
---|
| 50 | 'updateModelFromPerspectiveSignal' |
---|
| 51 | ] |
---|
| 52 | |
---|
| 53 | # Assure all signals are defined. |
---|
| 54 | for signal in list_of_signals: |
---|
| 55 | self.assertIn(signal, dir(com)) |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | def testUpdateModelItem(self): |
---|
| 59 | """ |
---|
| 60 | Test the QModelItem update method |
---|
| 61 | """ |
---|
| 62 | test_item = QtGui.QStandardItem() |
---|
| 63 | test_list = ['aa','11'] |
---|
| 64 | update_data = QtCore.QVariant(test_list) |
---|
| 65 | name = "Black Sabbath" |
---|
| 66 | |
---|
| 67 | # update the item |
---|
| 68 | updateModelItem(test_item, update_data, name) |
---|
| 69 | |
---|
| 70 | # Make sure test_item got all data added |
---|
| 71 | self.assertEqual(test_item.child(0).text(), name) |
---|
| 72 | self.assertTrue(test_item.child(0).isCheckable()) |
---|
| 73 | list_from_item = test_item.child(0).child(0).data().toPyObject() |
---|
| 74 | self.assertIsInstance(list_from_item, list) |
---|
| 75 | self.assertEqual(str(list_from_item[0]), test_list[0]) |
---|
| 76 | self.assertEqual(str(list_from_item[1]), test_list[1]) |
---|
| 77 | |
---|
| 78 | if __name__ == "__main__": |
---|
| 79 | unittest.main() |
---|
| 80 | |
---|