class _MainTester(unittest.TestCase):
    def setUp(self):
        self.mainGui = MainWindow()

    def initializeData(self, dataNumber):
        test_folder = testData[dataNumber]
        self.rawVectorData, self.omf_header, self.odtData, self.stages = MultiprocessingParse.readFolder(
            test_folder)

    def test_initialGui(self):
        self.assertEqual(self.mainGui.windowTitle(),
                         "ESE - Early Spins Enviroment")
        self.assertTrue(self.mainGui.width() > 200)
        self.assertTrue(self.mainGui.height() > 100)
        self.assertTrue(len(self.mainGui.panes) == 4)
        self.assertTrue(self.mainGui.panes[0].isVisible())
        self.assertFalse(self.mainGui.panes[1].isVisible())
        self.assertFalse(self.mainGui.panes[2].isVisible())
        self.assertFalse(self.mainGui.panes[3].isVisible())

    '''def test_loadDirectory(self):
        self.initializeData()
        print(self.mainGui.children())
        self.mainGui.actionLoad_Directory.trigger()
        self.assertTrue(len(self.mainGui.odt_data) > 0)
    '''

    def test_ViewListeners(self):
        self.mainGui.action2_Windows_Grid.trigger()
        self.assertTrue(self.mainGui.panes[0].isVisible())
        self.assertTrue(self.mainGui.panes[1].isVisible())
        self.assertFalse(self.mainGui.panes[2].isVisible())
        self.assertFalse(self.mainGui.panes[3].isVisible())

        self.mainGui.action4_Windows_Grid.trigger()
        self.assertTrue(self.mainGui.panes[0].isVisible())
        self.assertTrue(self.mainGui.panes[1].isVisible())
        self.assertTrue(self.mainGui.panes[2].isVisible())
        self.assertTrue(self.mainGui.panes[3].isVisible())

        self.mainGui.action2_Windows_Grid.trigger()
        self.assertTrue(self.mainGui.panes[0].isVisible())
        self.assertTrue(self.mainGui.panes[1].isVisible())
        self.assertFalse(self.mainGui.panes[2].isVisible())
        self.assertFalse(self.mainGui.panes[3].isVisible())

        self.mainGui.action1_Window_Grid.trigger()
        self.assertTrue(self.mainGui.panes[0].isVisible())
        self.assertFalse(self.mainGui.panes[1].isVisible())
        self.assertFalse(self.mainGui.panes[2].isVisible())
        self.assertFalse(self.mainGui.panes[3].isVisible())

    def test_PlotSettingsNoData(self):
        self.mainGui.actionPlot.trigger()
        label = self.mainGui.plotSettingsWindow.findChild(
            QtWidgets.QLabel, "textLabel")
        self.assertEqual(
            label.text(),
            "There is no data to show. Load data with File > Load Directory")
        accept = self.mainGui.plotSettingsWindow.buttonBox.children()[1]
        QTest.mouseClick(accept, Qt.LeftButton)

    def test_PlotSettingsDataLoaded(self):
        '''tests scenario when data is selected and plot settings clicked. There should be message that no plot has been selected'''
        self.initializeData(0)
        self.mainGui.rawVectorData = self.rawVectorData
        self.mainGui.omf_header = self.omf_header
        self.mainGui.odt_data = self.odtData
        self.mainGui.stages = self.stages

        self.mainGui.actionPlot.trigger()
        label = self.mainGui.plotSettingsWindow.findChild(
            QtWidgets.QLabel, "textLabel")
        self.assertEqual(
            label.text(),
            "No plot pane selected, Go to MainWindow and select pane type meant to show plot."
        )
        accept = self.mainGui.plotSettingsWindow.buttonBox.children()[1]
        QTest.mouseClick(accept, Qt.LeftButton)

    def test_Widgets(self):
        for i in range(4):
            QTest.mouseClick(self.mainGui.panes[i].button, Qt.LeftButton)
            self.mainGui.new.list.setCurrentRow(1)  #Plot2D
            QTest.mouseClick(self.mainGui.new.addButton, Qt.LeftButton)
            self.assertEqual(type(self.mainGui.panes[i].widget), Canvas)

        #this one is problem because of threading - program is not endig after tests completed because of threads in background
    def test_plotSettingsProperData(self):
        for i, _ in enumerate(testData):
            self.initializeData(i)
            self.mainGui.rawVectorData = self.rawVectorData
            self.mainGui.omf_header = self.omf_header
            self.mainGui.odt_data = self.odtData
            self.mainGui.stages = self.stages

            #add 2D plot Widget
            QTest.mouseClick(self.mainGui.panes[0].button, Qt.LeftButton)
            self.mainGui.new.list.setCurrentRow(1)  #createPlot2D
            QTest.mouseClick(self.mainGui.new.addButton, Qt.LeftButton)

            self.assertEqual(type(self.mainGui.panes[0].widget), Canvas)
            self.assertNotEqual(type(self.mainGui.panes[0].widget),
                                CanvasLayer)

            self.mainGui.actionPlot.trigger()
            #print(self.mainGui.plotSettingsWindow.children()[0].children()[2].children()[1])
            self.mainGui.plotSettingsWindow.comboBox[0].setCurrentIndex(5)
            #self.mainGui.plotSettingsWindow.radioButton[1].setChecked(True)

            print(
                self.mainGui.plotSettingsWindow.buttonBox.children()[1].text())
            QTest.mouseClick(
                self.mainGui.plotSettingsWindow.buttonBox.children()[1],
                Qt.LeftButton)

    def test_AnimationSettings(self):
        '''checking if Gui is disabled when there is no data'''
        self.mainGui.showAnimationSettings()

        for element in self.mainGui.playerWindow.gui.elements:
            self.assertFalse(element.isEnabled())

        #GUI still should be disabled
        self.mainGui._LOADED_FLAG_ = True
        for element in self.mainGui.playerWindow.gui.elements:
            self.assertFalse(element.isEnabled())

        self.initializeData(0)
        self.mainGui.rawVectorData = self.rawVectorData
        self.mainGui.omf_header = self.omf_header
        self.mainGui.odt_data = self.odtData
        self.mainGui.stages = self.stages

        # add 2D plot Widget
        QTest.mouseClick(self.mainGui.panes[0].button, Qt.LeftButton)
        self.mainGui.new.list.setCurrentRow(1)  # createPlot2D
        QTest.mouseClick(self.mainGui.new.addButton, Qt.LeftButton)

        self.mainGui.playerWindow.reloadGui()

        for element in self.mainGui.playerWindow.gui.elements:
            self.assertTrue(element.isEnabled())

    def test_PlayerWindow_sliderSpeed(self):
        self.initializeData(0)
        self.mainGui.rawVectorData = self.rawVectorData
        self.mainGui.omf_header = self.omf_header
        self.mainGui.odt_data = self.odtData
        self.mainGui.stages = self.stages
        self.mainGui._LOADED_FLAG_ = True

        QTest.mouseClick(self.mainGui.panes[0].button, Qt.LeftButton)
        self.mainGui.new.list.setCurrentRow(1)  # createPlot2D
        QTest.mouseClick(self.mainGui.new.addButton, Qt.LeftButton)

        self.mainGui.showAnimationSettings()
        x = self.mainGui.playerWindow.gui.slider_speed
        x.setValue(x.minimum())
        self.assertEqual(self.mainGui.playerWindow.gui.speedLabel.text(),
                         "Animation Speed: 0.1")
        x.setValue(x.maximum())
        self.assertEqual(self.mainGui.playerWindow.gui.speedLabel.text(),
                         "Animation Speed: 10.0")
Exemple #2
0
class MainWindowTest(unittest.TestCase):
    def setUp(self):
        self.gui = MainWindow()
        self.gui.load_video('video.mp4')

    def test_window_title(self):
        self.assertEqual(self.gui.windowTitle(), 'HonorableTag')

    def test_frame_slider_values(self):
        # Frame slider max value should be the length of the frame_array
        self.assertEqual(len(self.gui.FrameView.DrawScene.frame_array),
                         self.gui.FrameSlider.maximum())

    def test_get_frame_retrieves_correct_frame(self):
        # get_scene retrieves the correct frame and sets current_Frame
        self.gui.FrameView.DrawScene.get_frame(5)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 5)

    def test_step_forward_btn_increments_one_frame(self):
        # Step forward takes the user forward one frame
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)
        QTest.mouseClick(self.gui.StepForwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 1)

    def test_step_backward_btn_increments_one_frame(self):
        # Step backward takes the user back one frame
        self.gui.FrameView.DrawScene.get_frame(5)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 5)
        QTest.mouseClick(self.gui.StepBackwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 4)

    def test_big_step_forward_btn_increments_five_frames(self):
        # Big step forward takes  the user foraward 5 frames
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)
        QTest.mouseClick(self.gui.BigStepForwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 5)

    def test_big_step_backward_btn_increments_five_frames(self):
        # Big step backward takes the user back 5 frames
        self.gui.FrameView.DrawScene.get_frame(5)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 5)
        QTest.mouseClick(self.gui.BigStepBackwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)

    def test_cannot_step_foward_out_of_index(self):
        # User cannot step forward out of index of frame_array
        self.gui.FrameView.DrawScene.get_frame(
            len(self.gui.FrameView.DrawScene.frame_array) - 1)
        last_frame = self.gui.FrameView.DrawScene.current_frame
        QTest.mouseClick(self.gui.StepForwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame,
                         last_frame)
        QTest.mouseClick(self.gui.BigStepForwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame,
                         last_frame)

    def test_cannot_step_backward_out_index(self):
        # User cannot step backward out of index of frame_array
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)
        QTest.mouseClick(self.gui.StepBackwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)
        QTest.mouseClick(self.gui.BigStepBackwardButton, Qt.LeftButton)
        self.assertEqual(self.gui.FrameView.DrawScene.current_frame, 0)

    def test_load_class_labels_loads_correct_number_of_labels(self):
        # User loads test.names which contains 3 classes
        self.gui.ClassLabelList.clear()
        self.assertEqual(self.gui.ClassLabelList.count(), 0)
        self.gui.load_classes('test.names')
        self.assertEqual(self.gui.ClassLabelList.count(), 3)

    def test_load_class_labels_are_random_colors(self):
        # Colors loaded are random and do not match
        self.gui.load_classes('test.names')
        self.assertNotEqual(
            self.gui.ClassLabelList.item(0).color,
            self.gui.ClassLabelList.item(1).color)
        self.assertNotEqual(
            self.gui.ClassLabelList.item(0).color,
            self.gui.ClassLabelList.item(2).color)
        self.assertNotEqual(
            self.gui.ClassLabelList.item(1).color,
            self.gui.ClassLabelList.item(2).color)

    def test_load_classes_sets_selected_class(self):
        # Gui auto selects class upon loading class labels
        self.assertIsNone(self.gui.FrameView.selected_class)
        self.gui.load_classes('test.names')
        self.assertIsNotNone(self.gui.FrameView.selected_class)

    def test_select_class_changes_selected_class(self):
        # Tests selecting class label changes selected_class
        self.gui.load_classes('test.names')
        self.assertEqual(self.gui.FrameView.selected_class[0], 'honorable')
        # Get the visual rect for clicking
        rect = self.gui.ClassLabelList.visualItemRect(
            self.gui.ClassLabelList.item(1))
        QTest.mouseClick(self.gui.ClassLabelList.viewport(), Qt.LeftButton,
                         Qt.NoModifier, rect.center())
        self.assertEqual(self.gui.FrameView.selected_class[0], 'tag')