1"""Test class for vtgui.py""" 2 3import pytest 4 5from qtpy import QtCore 6from qtpy import QtWidgets 7 8import vitables.logger as logger 9 10 11@pytest.mark.usefixtures('launcher') 12class TestVTGui(object): 13 def test_dockWidget(self, launcher): 14 logger_dock = launcher.gui.findChild(QtWidgets.QDockWidget, 15 'LoggerDockWidget') 16 # Does the dock widget exist? 17 assert logger_dock 18 # Is it docked to the proper area? 19 assert (launcher.gui.dockWidgetArea(logger_dock) == 20 QtCore.Qt.BottomDockWidgetArea) 21 # Does it have the required features? 22 assert (logger_dock.features() == 23 QtWidgets.QDockWidget.DockWidgetClosable 24 | QtWidgets.QDockWidget.DockWidgetMovable 25 | QtWidgets.QDockWidget.DockWidgetFloatable) 26 # Is the logger widget properly set? 27 assert isinstance(logger_dock.widget(), logger.Logger) 28 29 def test_hsplitter(self, launcher): 30 hsplitter = launcher.gui.centralWidget().findChild(QtWidgets.QSplitter, 31 'hsplitter') 32 assert hsplitter 33 assert hsplitter.count() == 2 34 assert hsplitter.indexOf(launcher.gui.dbs_tree_view) == 0 35 assert hsplitter.indexOf(launcher.gui.workspace) == 1 36 37 def test_actions(self, launcher): 38 gui_actions = launcher.gui.gui_actions.keys() 39 expected_actions = \ 40 ['fileNew', 'fileOpen', 'fileOpenRO', 'fileClose', 'fileCloseAll', 41 'fileSaveAs', 'fileExit', 'nodeOpen', 'nodeClose', 42 'nodeProperties', 'nodeNew', 'nodeRename', 'nodeCut', 'nodeCopy', 43 'nodePaste', 'nodeDelete', 'queryNew', 'queryDeleteAll', 44 'settingsPreferences', 'windowCascade', 'windowTile', 45 'windowRestoreAll', 'windowMinimizeAll', 'windowClose', 46 'windowCloseAll', 'windowSeparator', 'mdiTabbed', 47 'helpUsersGuide', 'helpAbout', 'helpAboutQt', 'helpVersions', 48 'calculate'] 49 assert sorted(gui_actions) == sorted(expected_actions) 50 51 def test_fileToolBar(self, launcher): 52 file_tb = launcher.gui.findChild(QtWidgets.QToolBar, 'File toolbar') 53 assert file_tb 54 55 tb_actions = [a.objectName() for a in file_tb.actions()] 56 expected_actions = ['fileNew', 'fileOpen', 'fileClose', 'fileSaveAs'] 57 assert sorted(tb_actions) == sorted(expected_actions) 58 59 def test_nodeToolBar(self, launcher): 60 node_tb = launcher.gui.findChild(QtWidgets.QToolBar, 'Node toolbar') 61 assert node_tb 62 63 tb_actions = [a.objectName() for a in node_tb.actions()] 64 expected_actions = ['nodeNew', 'nodeCut', 'nodeCopy', 'nodePaste', 65 'nodeDelete'] 66 assert sorted(tb_actions) == sorted(expected_actions) 67 68 def test_queryToolBar(self, launcher): 69 query_tb = launcher.gui.findChild(QtWidgets.QToolBar, 'Query toolbar') 70 assert query_tb 71 72 tb_actions = [a.objectName() for a in query_tb.actions()] 73 expected_actions = ['queryNew', 'queryDeleteAll'] 74 assert sorted(tb_actions) == sorted(expected_actions) 75 76 def test_helpToolBar(self, launcher): 77 help_tb = launcher.gui.findChild(QtWidgets.QToolBar, 'Help toolbar') 78 assert help_tb 79 80 tb_actions = [a.objectName() for a in help_tb.actions()] 81 expected_actions = ['helpUsersGuide', 'whatis_help_toolbar'] 82 assert sorted(tb_actions) == sorted(expected_actions) 83 84 def test_statusBarWidget(self, launcher): 85 sbw = launcher.gui.statusBar().findChild(QtWidgets.QLabel, 86 'status bar widget') 87 assert sbw 88 sbw_sp = sbw.sizePolicy() 89 hsp, vsp = sbw_sp.horizontalPolicy(), sbw_sp.verticalPolicy() 90 assert hsp == QtWidgets.QSizePolicy.MinimumExpanding 91 assert vsp == QtWidgets.QSizePolicy.Minimum 92 93 @pytest.fixture() 94 def menuBar(self, launcher): 95 return launcher.gui.menuBar() 96 97 def test_menus(self, menuBar): 98 assert len(menuBar.actions()) == 6 99 100 def test_fileMenu(self, menuBar): 101 menu = menuBar.findChild(QtWidgets.QMenu, 'file_menu') 102 menu_actions = menu.actions() 103 assert menu 104 105 actions = [a.objectName() for a in menu_actions 106 if not (a.isSeparator() or a.menu())] 107 expected_actions = ['fileNew', 'fileOpen', 'fileOpenRO', 'fileClose', 108 'fileCloseAll', 'fileSaveAs', 'fileExit'] 109 assert sorted(actions) == sorted(expected_actions) 110 111 menus = [a.menu().objectName() for a in menu_actions if a.menu()] 112 assert sorted(menus) == ['import_csv_submenu', 'open_recent_submenu'] 113 114 separators = [a for a in menu_actions if a.isSeparator()] 115 assert len(separators) == 4 116 117 def test_nodeMenu(self, menuBar): 118 menu = menuBar.findChild(QtWidgets.QMenu, 'node_menu') 119 menu_actions = menu.actions() 120 assert menu 121 122 actions = [a.objectName() for a in menu_actions 123 if not (a.isSeparator() or a.menu())] 124 expected_actions = ['nodeOpen', 'nodeClose', 'nodeProperties', 125 'nodeNew', 'nodeRename', 'nodeCut', 'nodeCopy', 126 'nodePaste', 'nodeDelete'] 127 assert sorted(actions) == sorted(expected_actions) 128 129 separators = [a for a in menu_actions if a.isSeparator()] 130 assert len(separators) == 1 131 132 def test_datasetMenu(self, menuBar): 133 menu = menuBar.findChild(QtWidgets.QMenu, 'dataset_menu') 134 menu_actions = menu.actions() 135 assert menu 136 137 actions = [a.objectName() for a in menu_actions 138 if not (a.isSeparator() or a.menu())] 139 expected_actions = ['queryNew', 'calculate', 'export_csv'] 140 assert sorted(actions) == sorted(expected_actions) 141 142 separators = [a for a in menu_actions if a.isSeparator()] 143 assert len(separators) == 1 144 145 def test_settingsMenu(self, menuBar): 146 menu = menuBar.findChild(QtWidgets.QMenu, 'settings_menu') 147 menu_actions = menu.actions() 148 assert menu 149 150 actions = [a.objectName() for a in menu_actions 151 if not (a.isSeparator() or a.menu())] 152 expected_actions = ['settingsPreferences'] 153 assert sorted(actions) == sorted(expected_actions) 154 155 menus = [a.menu().objectName() for a in menu_actions if a.menu()] 156 assert sorted(menus) == ['settings_toolbars_submenu'] 157 158 separators = [a for a in menu_actions if a.isSeparator()] 159 assert len(separators) == 1 160 161 def test_windowMenu(self, menuBar): 162 menu = menuBar.findChild(QtWidgets.QMenu, 'window_menu') 163 menu_actions = menu.actions() 164 assert menu 165 166 actions = [a.objectName() for a in menu_actions 167 if not (a.isSeparator() or a.menu())] 168 expected_actions = ['windowCascade', 'windowTile', 169 'windowRestoreAll', 'windowMinimizeAll', 170 'windowClose', 'windowCloseAll', 'mdiTabbed'] 171 assert sorted(actions) == sorted(expected_actions) 172 173 separators = [a for a in menu_actions if a.isSeparator()] 174 assert len(separators) == 2 175 176 def test_helpMenu(self, menuBar): 177 menu = menuBar.findChild(QtWidgets.QMenu, 'help_menu') 178 menu_actions = menu.actions() 179 assert menu 180 181 actions = [a.objectName() for a in menu_actions 182 if not (a.isSeparator() or a.menu())] 183 expected_actions = ['helpUsersGuide', 'helpAbout', 'helpAboutQt', 184 'helpVersions', 'whatis_help_menu'] 185 assert sorted(actions) == sorted(expected_actions) 186 187 separators = [a for a in menu_actions if a.isSeparator()] 188 assert len(separators) == 2 189 190 def test_viewCM(self, launcher): 191 menu = launcher.gui.findChild(QtWidgets.QMenu, 'view_cm') 192 menu_actions = menu.actions() 193 assert menu 194 195 actions = [a.objectName() for a in menu_actions 196 if not (a.isSeparator() or a.menu())] 197 expected_actions = ['fileNew', 'fileOpen', 'fileOpenRO', 'fileClose', 198 'fileCloseAll', 'fileSaveAs', 'fileExit'] 199 assert sorted(actions) == sorted(expected_actions) 200 201 menus = [a.menu().objectName() for a in menu_actions if a.menu()] 202 assert sorted(menus) == ['import_csv_submenu', 'open_recent_submenu'] 203 204 separators = [a for a in menu_actions if a.isSeparator()] 205 assert len(separators) == 4 206 207 def test_rootNodeCM(self, launcher): 208 menu = launcher.gui.findChild(QtWidgets.QMenu, 'root_node_cm') 209 menu_actions = menu.actions() 210 assert menu 211 212 actions = [a.objectName() for a in menu_actions 213 if not (a.isSeparator() or a.menu())] 214 expected_actions = ['fileClose', 'fileSaveAs', 'nodeProperties', 215 'nodeNew', 'nodeCopy', 'nodePaste', 216 'queryDeleteAll'] 217 assert sorted(actions) == sorted(expected_actions) 218 219 separators = [a for a in menu_actions if a.isSeparator()] 220 assert len(separators) == 3 221 222 def test_groupNodeCM(self, launcher): 223 menu = launcher.gui.findChild(QtWidgets.QMenu, 'group_node_cm') 224 menu_actions = menu.actions() 225 assert menu 226 227 actions = [a.objectName() for a in menu_actions 228 if not (a.isSeparator() or a.menu())] 229 expected_actions = ['nodeProperties', 'nodeNew', 'nodeRename', 230 'nodeCut', 'nodeCopy', 'nodePaste', 'nodeDelete'] 231 assert sorted(actions) == sorted(expected_actions) 232 233 separators = [a for a in menu_actions if a.isSeparator()] 234 assert len(separators) == 1 235 236 def test_leafNodeCM(self, launcher): 237 menu = launcher.gui.findChild(QtWidgets.QMenu, 'leaf_node_cm') 238 menu_actions = menu.actions() 239 assert menu 240 241 actions = [a.objectName() for a in menu_actions 242 if not (a.isSeparator() or a.menu())] 243 expected_actions = ['nodeOpen', 'nodeClose', 'nodeProperties', 244 'nodeRename', 'nodeCut', 'nodeCopy', 'nodePaste', 245 'nodeDelete', 'queryNew', 'export_csv'] 246 assert sorted(actions) == sorted(expected_actions) 247 248 separators = [a for a in menu_actions if a.isSeparator()] 249 assert len(separators) == 4 250 251 def test_mdiCM(self, launcher): 252 menu = launcher.gui.findChild(QtWidgets.QMenu, 'mdi_cm') 253 menu_actions = menu.actions() 254 assert menu 255 256 menus = [a.menu().objectName() for a in menu_actions if a.menu()] 257 assert sorted(menus) == ['window_menu'] 258