Example #1
0
    def setUp(self):
        # avoid popup messages
        patch = mock.patch('Interface.ui.drill.view.DrillView.QMessageBox')
        self.mMessageBox = patch.start()
        self.addCleanup(patch.stop)
        patch = mock.patch("Interface.ui.drill.presenter.DrillPresenter"
                           ".QMessageBox")
        self.mMessageBoxP = patch.start()
        self.addCleanup(patch.stop)
        # mock the controller
        patch = mock.patch(
            'Interface.ui.drill.model.DrillModel.DrillParameterController')
        self.mController = patch.start()
        self.addCleanup(patch.stop)
        # mock logger
        patch = mock.patch('Interface.ui.drill.model.DrillModel.logger')
        self.mLogger = patch.start()
        self.addCleanup(patch.stop)

        self.view = DrillView()
        self.presenter = self.view._presenter
        self.model = self.presenter.model

        # mock popup
        self.presenter._saveDataQuestion = mock.Mock()

        # shown window
        self.view.isHidden = mock.Mock()
        self.view.isHidden.return_value = False

        self.facility = config['default.facility']
        self.instrument = config['default.instrument']
        config['default.facility'] = "ILL"
        config['default.instrument'] = "D11"
Example #2
0
    def setUp(self):
        patch = mock.patch('Interface.ui.drill.view.DrillView.QMessageBox')
        self.mMsgBox = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch(
            'Interface.ui.drill.view.DrillView.manageuserdirectories')
        self.mUserDir = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch('Interface.ui.drill.view.DrillView.DrillPresenter')
        self.mPresenter = patch.start()
        self.addCleanup(patch.stop)

        self.view = DrillView()
        self.view.table = mock.Mock()
Example #3
0
    def setUp(self):
        self.facility = config['default.facility']
        config['default.facility'] = "ILL"
        # avoid popup messages
        patch = mock.patch('Interface.ui.drill.view.DrillView.QMessageBox')
        self.mMessageBox = patch.start()
        self.addCleanup(patch.stop)
        # mock the controller
        patch = mock.patch(
                'Interface.ui.drill.model.DrillModel.DrillParameterController')
        self.mController = patch.start()
        self.addCleanup(patch.stop)

        self.view = DrillView()
        self.presenter = self.view._presenter
        self.model = self.presenter.model
Example #4
0
class DrillViewTest(unittest.TestCase):
    def setUp(self):
        patch = mock.patch('Interface.ui.drill.view.DrillView.QFileDialog')
        self.mFileDialog = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch('Interface.ui.drill.view.DrillView.QMessageBox')
        self.mMsgBox = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch(
            'Interface.ui.drill.view.DrillView.manageuserdirectories')
        self.mUserDir = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch('Interface.ui.drill.view.DrillView.DrillPresenter')
        self.mPresenter = patch.start()
        self.addCleanup(patch.stop)

        self.view = DrillView()
        self.view.table = mock.Mock()

    def test_closeEvent(self):
        self.view.findChildren = mock.Mock()
        c1 = mock.Mock()
        c2 = mock.Mock()
        c3 = mock.Mock()
        self.view.findChildren.return_value = [c1, c2]
        self.view.closeEvent(QCloseEvent())
        c1.close.assert_called_once()
        c2.close.assert_called_once()
        c3.close.assert_not_called()

    def test_getSelectionShape(self):
        # no selection
        selection = []
        shape = self.view._getSelectionShape(selection)
        self.assertEqual(shape, (0, 0))

        # valid selection
        selection = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)]
        shape = self.view._getSelectionShape(selection)
        self.assertEqual(shape, (2, 3))
        selection = [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)]
        shape = self.view._getSelectionShape(selection)
        self.assertEqual(shape, (3, 2))

        # invalid selection
        selection = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1)]
        shape = self.view._getSelectionShape(selection)
        self.assertEqual(shape, (0, 0))
        selection = [(0, 0), (0, 1), (10, 10)]
        shape = self.view._getSelectionShape(selection)
        self.assertEqual(shape, (0, 0))

    def test_copySelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.copySelectedCells()
        self.assertEqual(self.view.buffer, [])
        self.assertEqual(self.view.bufferShape, ())
        self.view.table.getCellContents.assert_not_called()

        # valid selection
        self.view.table.getSelectedCells.return_value = [(0, 0)]
        self.view.table.getCellContents.return_value = "test"
        self.view.copySelectedCells()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getCellContents.return_value = "test"
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_called()
        self.assertEqual(self.view.buffer, ["test", "test", "test", "test"])
        self.assertEqual(self.view.bufferShape, (2, 2))

        # invalid selection
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (10, 10)]
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_not_called()

        # empty values
        self.view.table.reset_mock()
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getCellContents.return_value = ""
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_called()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))

    def test_cutSelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, [])
        self.assertEqual(self.view.bufferShape, ())
        self.view.table.getCellContents.assert_not_called()

        # valid selection
        self.view.table.getSelectedCells.return_value = [(0, 0)]
        self.view.table.getCellContents.return_value = "test"
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))
        self.view.table.eraseCell.assert_called_once_with(0, 0)

        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getCellContents.return_value = "test"
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, ["test", "test", "test", "test"])
        self.assertEqual(self.view.bufferShape, (2, 2))
        calls = [
            mock.call(0, 0),
            mock.call(0, 1),
            mock.call(1, 0),
            mock.call(1, 1)
        ]
        self.view.table.eraseCell.assert_has_calls(calls)

        # invalid selection
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (10, 10)]
        self.view.table.getCellContents.assert_not_called()
        self.view.table.eraseCell.assert_not_called()

    def test_pasteCells(self):
        # no selection
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.getSelectedCells.return_value = []
        self.view.pasteCells()
        self.view.table.setCellContents.assert_not_called()

        # empty buffer
        self.view.table.reset_mock()
        self.view.buffer = []
        self.view.bufferShape = ()
        self.view.pasteCells()
        self.view.table.setCellContents.assert_not_called()

        # valid selection
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(1, 1)]
        self.view.pasteCells()
        self.view.table.setCellContents.assert_called_once()

        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.pasteCells()
        calls = [
            mock.call(0, 0, "test"),
            mock.call(0, 1, "test"),
            mock.call(1, 0, "test"),
            mock.call(1, 1, "test")
        ]
        self.view.table.setCellContents.assert_has_calls(calls)

        self.view.buffer = ["test00", "test01", "test10", "test11"]
        self.view.bufferShape = (2, 2)
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.pasteCells()
        calls = [
            mock.call(0, 0, "test00"),
            mock.call(0, 1, "test01"),
            mock.call(1, 0, "test10"),
            mock.call(1, 1, "test11")
        ]
        self.view.table.setCellContents.assert_has_calls(calls)

    def test_eraseSelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.eraseSelectedCells()
        self.view.table.eraseCell.assert_not_called()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (2, 1)]
        # selection
        self.view.eraseSelectedCells()
        calls = [mock.call(0, 0), mock.call(0, 1), mock.call(2, 1)]
        self.view.table.eraseCell.assert_has_calls(calls)

    def test_addRowAfter(self):
        # add one row (defautlt value)
        self.view.table.getLastSelectedRow.return_value = 0
        self.view.add_row_after()
        self.view.table.getLastRow.assert_not_called()
        self.view.table.addRow.assert_called_once_with(1)

        self.view.table.reset_mock()
        self.view.table.getLastSelectedRow.return_value = -1
        self.view.table.getLastRow.return_value = 0
        self.view.add_row_after()
        self.view.table.getLastSelectedRow.assert_called_once()
        self.view.table.getLastRow.assert_called_once()
        self.view.table.addRow.assert_called_once_with(1)

        # add many rows
        self.view.table.reset_mock()
        self.view.nrows = mock.Mock()
        self.view.nrows.value.return_value = 15
        self.view.table.getLastSelectedRow.return_value = 0
        self.view.add_row_after()
        calls = [mock.call(n) for n in range(1, 16)]
        self.view.table.addRow.assert_has_calls(calls)

    def test_delSelectedRows(self):
        # no selection
        self.view.table.getSelectedRows.return_value = []
        self.view.del_selected_rows()
        self.view.table.deleteRow.assert_not_called()
        # selction
        self.view.table.getSelectedRows.return_value = [0, 1, 2]
        self.view.del_selected_rows()
        calls = [mock.call(2), mock.call(1), mock.call(0)]
        self.view.table.deleteRow.assert_has_calls(calls)

    def test_processSelectedRows(self):
        self.view.process = mock.Mock()
        # no selection
        self.view.table.getSelectedRows.return_value = []
        self.view.table.getRowsFromSelectedCells.return_value = []
        self.view.process_selected_rows()
        self.view.table.process.emit.assert_not_called()
        # rows selection
        self.view.table.getSelectedRows.return_value = [0, 2]
        self.view.process_selected_rows()
        calls = [mock.call([0, 2])]
        self.view.process.emit.assert_has_calls(calls)
        # cells selection
        self.view.process.reset_mock()
        self.view.table.getSelectedRows.return_value = []
        self.view.table.getRowsFromSelectedCells.return_value = [1, 3]
        self.view.process_selected_rows()
        calls = [mock.call([1, 3])]
        self.view.process.emit.assert_has_calls(calls)

    def test_processAllRows(self):
        self.view.process = mock.Mock()
        # empty table
        self.view.table.getAllRows.return_value = []
        self.view.process_all_rows()
        self.view.table.process.emit.assert_not_called()
        # not empty
        self.view.table.getAllRows.return_value = [0, 1, 2]
        self.view.process_all_rows()
        calls = [mock.call([0, 1, 2])]
        self.view.process.emit.assert_has_calls(calls)

    def test_loadRundex(self):
        self.view.rundexLoaded = mock.Mock()
        self.mFileDialog.getOpenFileName.return_value = ("test", "test")
        self.view.load_rundex()
        self.view.rundexLoaded.emit.assert_called_once_with("test")

    def test_saveRundexAs(self):
        self.view.rundexSaved = mock.Mock()
        self.mFileDialog.getSaveFileName.return_value = ("test", "test")
        self.view.saveRundexAs()
        self.view.rundexSaved.emit.assert_called_once_with("test")

    def test_saveRundex(self):
        self.view.rundexSaved = mock.Mock()
        self.view.rundexFile = "test"
        self.view.saveRundex()
        self.view.rundexSaved.emit.assert_called_once_with("test")
        self.mFileDialog.getSaveFileName.assert_not_called()

    def test_automaticFilling(self):
        self.view.increment = mock.Mock()
        # positive increment
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1)]
        self.view.table.getCellContents.return_value = "1000,2000,3000"
        self.view.increment.value.return_value = 1
        self.view.automatic_filling()
        calls = [mock.call(0, 1, "1001,2001,3001")]
        self.view.table.setCellContents.assert_has_calls(calls)

        # negative increment
        self.view.table.setCellContents.reset_mock()
        self.view.increment.value.return_value = -1
        self.view.automatic_filling()
        calls = [mock.call(0, 1, "999,1999,2999")]
        self.view.table.setCellContents.assert_has_calls(calls)

        # ranges
        self.view.table.setCellContents.reset_mock()
        self.view.table.getCellContents.return_value = "1000-2000,2000:3000,3000"
        self.view.increment.value.return_value = 1
        self.view.automatic_filling()
        calls = [mock.call(0, 1, "2001-3001,3001:4001,3001")]
        self.view.table.setCellContents.assert_has_calls(calls)

    def test_keyPressEvent(self):
        self.view.copySelectedCells = mock.Mock()
        self.view.cutSelectedCells = mock.Mock()
        self.view.pasteCells = mock.Mock()
        self.view.eraseSelectedCells = mock.Mock()

        QTest.keyClick(self.view, Qt.Key_C, Qt.ControlModifier)
        self.view.copySelectedCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_X, Qt.ControlModifier)
        self.view.cutSelectedCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_V, Qt.ControlModifier)
        self.view.pasteCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_Delete, Qt.NoModifier)
        self.view.eraseSelectedCells.assert_called_once()

    def test_showDirectoryManager(self):
        self.view.show_directory_manager()
        self.mUserDir.ManageUserDirectories.assert_called_once()

    def test_setAvailableInstruments(self):
        self.view.instrumentselector = mock.Mock()
        self.view.set_available_instruments("test")
        self.view.instrumentselector.setTechniques.assert_called_once_with(
            "test")

    def test_setAvailableModes(self):
        self.view.modeSelector = mock.Mock()
        self.view.set_available_modes(["test", "test"])
        self.view.modeSelector.clear.assert_called_once()
        self.view.modeSelector.addItems.assert_called_once_with(
            ["test", "test"])

    def test_setAcquisitionMode(self):
        self.view.modeSelector = mock.Mock()
        self.view.set_acquisition_mode("test")
        self.view.modeSelector.setCurrentText.assert_called_once_with("test")

    def test_setCycleAndExperiment(self):
        self.view.setCycleAndExperiment("test1", "test2")
        self.assertEqual(self.view.cycleNumber.text(), "test1")
        self.assertEqual(self.view.experimentId.text(), "test2")

    def test_setTable(self):
        self.view.set_table(["test", "test"])
        self.view.table.setColumnCount.assert_called_once_with(2)

    def test_fillTable(self):
        # empty contents
        self.view.fill_table([])
        self.view.table.addRow.assert_called_once()
        # contents
        self.view.table.reset_mock()
        self.view.fill_table([["test", "test"], ["test", "test"]])
        self.view.table.addRow.assert_not_called()
        self.view.table.setRowCount.assert_called_once()
        calls = [
            mock.call(0, ["test", "test"]),
            mock.call(1, ["test", "test"])
        ]
        self.view.table.setRowContents.assert_has_calls(calls)

    def test_setProgress(self):
        self.view.set_progress(0, 100)
        self.assertEqual(self.view.progressBar.maximum(), 100)
        self.assertEqual(self.view.progressBar.value(), 0)
        self.view.set_progress(100, 0)
        self.assertEqual(self.view.progressBar.maximum(), 0)
        self.assertEqual(self.view.progressBar.value(), 100)

    def test_setDisabled(self):
        # only visual. here we just go through the function
        self.view.set_disabled(True)
        self.view.set_disabled(False)

    def test_setRowProcessing(self):
        self.view.set_row_processing(0)
        self.view.table.setRowBackground.assert_called_once()

    def test_setRowDone(self):
        self.view.set_row_done(0)
        self.view.table.setRowBackground.assert_called_once()

    def test_setRowError(self):
        self.view.set_row_error(0)
        self.view.table.setRowBackground.assert_called_once()

    def test_setCellOk(self):
        self.view.table.rowCount.return_value = 1
        self.view.columns = ["test"]
        self.view.set_cell_ok(1, "test1")
        self.view.table.removeCellBackground.assert_not_called()
        self.view.set_cell_ok(0, "test")
        self.view.table.removeCellBackground.assert_called_once()

    def test_setCellError(self):
        self.view.table.rowCount.return_value = 1
        self.view.columns = ["test"]
        self.view.set_cell_error(1, "test1", "")
        self.view.table.setCellBackground.assert_not_called()
        self.view.set_cell_error(0, "test", "")
        self.view.table.setCellBackground.assert_called_once()

    def test_setVisualSettings(self):
        self.view.columns = ["test"]
        self.view.setVisualSettings(dict())
        self.view.table.setHeaderFoldingState.assert_not_called()
        self.view.setVisualSettings({"FoldedColumns": {}})
        self.view.table.setHeaderFoldingState.assert_called_once_with([False])
        self.view.table.reset_mock()
        self.view.setVisualSettings({"FoldedColumns": {"test": True}})
        self.view.table.setHeaderFoldingState.assert_called_once_with([True])
        self.view.table.reset_mock()
        self.view.setVisualSettings({"FoldedColumns": {"test1": True}})
        self.view.table.setHeaderFoldingState.assert_called_once_with([False])

    def test_getVisualSettings(self):
        self.view.columns = ["test1", "test2", "test3"]
        self.view.table.getHeaderFoldingState.return_value = [
            True, False, True
        ]
        d = {"FoldedColumns": {"test1": True, "test3": True}}
        self.assertDictEqual(self.view.getVisualSettings(), d)
Example #5
0
class DrillViewTest(unittest.TestCase):
    def setUp(self):
        patch = mock.patch('Interface.ui.drill.view.DrillView.QMessageBox')
        self.mMsgBox = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch(
            'Interface.ui.drill.view.DrillView.manageuserdirectories')
        self.mUserDir = patch.start()
        self.addCleanup(patch.stop)

        patch = mock.patch('Interface.ui.drill.view.DrillView.DrillPresenter')
        self.mPresenter = patch.start()
        self.addCleanup(patch.stop)

        self.view = DrillView()
        self.view.table = mock.Mock()

    def test_closeEvent(self):
        self.view.findChildren = mock.Mock()
        c1 = mock.Mock()
        c2 = mock.Mock()
        c3 = mock.Mock()
        self.view.findChildren.return_value = [c1, c2]
        self.view.closeEvent(QCloseEvent())
        c1.close.assert_called_once()
        c2.close.assert_called_once()
        c3.close.assert_not_called()
        self.mPresenter.return_value.onClose.assert_called_once()

    def test_changeCycleOrExperiment(self):
        self.view.cycleAndExperimentChanged = mock.Mock()
        self.view.cycleNumber = mock.Mock()
        self.view.cycleNumber.text.return_value = "cycle1"
        self.view.experimentId = mock.Mock()
        self.view.experimentId.text.return_value = ""
        self.view._changeCycleOrExperiment()
        self.view.cycleAndExperimentChanged.assert_not_called()
        self.view.experimentId.text.return_value = "exp1"
        self.view._changeCycleOrExperiment()
        self.view.cycleAndExperimentChanged.emit \
            .assert_called_once_with("cycle1", "exp1")

    def test_copySelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.copySelectedCells()
        self.assertEqual(self.view.buffer, [])
        self.assertEqual(self.view.bufferShape, ())
        self.view.table.getCellContents.assert_not_called()

        # valid selection
        self.view.table.getSelectedCells.return_value = [(0, 0)]
        self.view.table.getSelectionShape.return_value = (1, 1)
        self.view.table.getCellContents.return_value = "test"
        self.view.copySelectedCells()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getSelectionShape.return_value = (2, 2)
        self.view.table.getCellContents.return_value = "test"
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_called()
        self.assertEqual(self.view.buffer, ["test", "test", "test", "test"])
        self.assertEqual(self.view.bufferShape, (2, 2))

        # invalid selection
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (10, 10)]
        self.view.table.getSelectionShape.return_value = (0, 0)
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_not_called()

        # empty values
        self.view.table.reset_mock()
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getSelectionShape.return_value = (1, 1)
        self.view.table.getCellContents.return_value = ""
        self.view.copySelectedCells()
        self.view.table.getCellContents.assert_called()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))

    def test_cutSelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.table.getSelectionShape.return_value = (0, 0)
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, [])
        self.assertEqual(self.view.bufferShape, ())
        self.view.table.getCellContents.assert_not_called()

        # valid selection
        self.view.table.getSelectedCells.return_value = [(0, 0)]
        self.view.table.getSelectionShape.return_value = (1, 1)
        self.view.table.getCellContents.return_value = "test"
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, ["test"])
        self.assertEqual(self.view.bufferShape, (1, 1))
        self.view.table.eraseCell.assert_called_once_with(0, 0)

        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getSelectionShape.return_value = (2, 2)
        self.view.table.getCellContents.return_value = "test"
        self.view.cutSelectedCells()
        self.assertEqual(self.view.buffer, ["test", "test", "test", "test"])
        self.assertEqual(self.view.bufferShape, (2, 2))
        calls = [
            mock.call(0, 0),
            mock.call(0, 1),
            mock.call(1, 0),
            mock.call(1, 1)
        ]
        self.view.table.eraseCell.assert_has_calls(calls)

        # invalid selection
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (10, 10)]
        self.view.table.getSelectionShape.return_value = (0, 0)
        self.view.table.getCellContents.assert_not_called()
        self.view.table.eraseCell.assert_not_called()

    def test_pasteCells(self):
        # no selection
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.getSelectedCells.return_value = []
        self.view.table.getSelectionShape.return_value = (0, 0)
        self.view.pasteCells()
        self.view.table.setCellContents.assert_not_called()

        # empty buffer
        self.view.table.reset_mock()
        self.view.buffer = []
        self.view.bufferShape = ()
        self.view.pasteCells()
        self.view.table.setCellContents.assert_not_called()

        # valid selection
        self.view.buffer = ["test"]
        self.view.bufferShape = (1, 1)
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(1, 1)]
        self.view.table.getSelectionShape.return_value = (1, 1)
        self.view.pasteCells()
        self.view.table.setCellContents.assert_called_once()

        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getSelectionShape.return_value = (2, 2)
        self.view.pasteCells()
        calls = [
            mock.call(0, 0, "test"),
            mock.call(0, 1, "test"),
            mock.call(1, 0, "test"),
            mock.call(1, 1, "test")
        ]
        self.view.table.setCellContents.assert_has_calls(calls)

        self.view.buffer = ["test00", "test01", "test10", "test11"]
        self.view.bufferShape = (2, 2)
        self.view.table.reset_mock()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (1, 0), (1, 1)]
        self.view.table.getSelectionShape.return_value = (2, 2)
        self.view.pasteCells()
        calls = [
            mock.call(0, 0, "test00"),
            mock.call(0, 1, "test01"),
            mock.call(1, 0, "test10"),
            mock.call(1, 1, "test11")
        ]
        self.view.table.setCellContents.assert_has_calls(calls)

    def test_eraseSelectedCells(self):
        # no selection
        self.view.table.getSelectedCells.return_value = []
        self.view.eraseSelectedCells()
        self.view.table.eraseCell.assert_not_called()
        self.view.table.getSelectedCells.return_value = [(0, 0), (0, 1),
                                                         (2, 1)]
        # selection
        self.view.eraseSelectedCells()
        calls = [mock.call(0, 0), mock.call(0, 1), mock.call(2, 1)]
        self.view.table.eraseCell.assert_has_calls(calls)

    def test_addRowAfter(self):
        self.view.table.getLastSelectedRow.return_value = 0
        self.view.addRowAfter()
        self.mPresenter.return_value.onRowAdded.assert_called_once_with(1)

    def test_addRowsAdter(self):
        self.view.table.getLastSelectedRow.return_value = 0
        self.view.nrows = mock.Mock()
        self.view.nrows.value.return_value = 10
        self.view.addRowsAfter()
        self.mPresenter.assert_called()

    def test_delSelectedRows(self):
        # no selection
        self.view.table.getSelectedRows.return_value = []
        self.view.del_selected_rows()
        self.view.table.deleteRow.assert_not_called()
        # selction
        self.view.table.getSelectedRows.return_value = [0, 1, 2]
        self.view.del_selected_rows()
        calls = [mock.call(2), mock.call(1), mock.call(0)]
        self.view.table.deleteRow.assert_has_calls(calls)

    def test_keyPressEvent(self):
        self.view.copySelectedCells = mock.Mock()
        self.view.cutSelectedCells = mock.Mock()
        self.view.pasteCells = mock.Mock()
        self.view.eraseSelectedCells = mock.Mock()
        self.view.ungroupSelectedRows = mock.Mock()
        self.view.groupSelectedRows = mock.Mock()
        self.view.setMasterRow = mock.Mock()
        self.view.table.getRowsFromSelectedCells.return_value = [1]

        QTest.keyClick(self.view, Qt.Key_C, Qt.ControlModifier)
        self.view.copySelectedCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_X, Qt.ControlModifier)
        self.view.cutSelectedCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_V, Qt.ControlModifier)
        self.view.pasteCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_Delete, Qt.NoModifier)
        self.view.eraseSelectedCells.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_G, Qt.ControlModifier)
        self.view.groupSelectedRows.emit.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_G,
                       Qt.ControlModifier | Qt.ShiftModifier)
        self.view.ungroupSelectedRows.emit.assert_called_once()
        QTest.keyClick(self.view, Qt.Key_M, Qt.ControlModifier)
        self.view.setMasterRow.emit.assert_called_once()

    def test_showDirectoryManager(self):
        self.view.show_directory_manager()
        self.mUserDir.ManageUserDirectories.assert_called_once()

    def test_setInstrument(self):
        self.view.instrumentselector = mock.Mock()
        self.view.setInstrument("i1")
        self.view.instrumentselector.setCurrentText \
            .assert_called_once_with("i1")

    def test_setAvailableModes(self):
        self.view.modeSelector = mock.Mock()
        self.view.set_available_modes(["test", "test"])
        self.view.modeSelector.clear.assert_called_once()
        self.view.modeSelector.addItems.assert_called_once_with(
            ["test", "test"])

    def test_setAcquisitionMode(self):
        self.view.modeSelector = mock.Mock()
        self.view.set_acquisition_mode("test")
        self.view.modeSelector.setCurrentText.assert_called_once_with("test")

    def test_getAcquisitionMode(self):
        self.view.modeSelector = mock.Mock()
        self.view.modeSelector.currentText.return_value = "mode"
        mode = self.view.getAcquisitionMode()
        self.assertEqual(mode, "mode")

    def test_setCycleAndExperiment(self):
        self.view.setCycleAndExperiment("test1", "test2")
        self.assertEqual(self.view.cycleNumber.text(), "test1")
        self.assertEqual(self.view.experimentId.text(), "test2")

    def test_setTable(self):
        self.view.set_table(["test", "test"])
        self.view.table.setColumnCount.assert_called_with(2)

    def test_setProgress(self):
        self.view.set_progress(0, 100)
        self.assertEqual(self.view.progressBar.maximum(), 100)
        self.assertEqual(self.view.progressBar.value(), 0)
        self.view.set_progress(100, 0)
        self.assertEqual(self.view.progressBar.maximum(), 0)
        self.assertEqual(self.view.progressBar.value(), 100)

    def test_setDisabled(self):
        # only visual. here we just go through the function
        self.view.set_disabled(True)
        self.view.set_disabled(False)

    def test_setVisualSettings(self):
        self.view.columns = ["test"]
        self.view.setVisualSettings(dict())
        self.view.table.setFoldedColumns.assert_not_called()
        self.view.setVisualSettings({"FoldedColumns": {}})
        self.view.table.setFoldedColumns.assert_called_once_with([])
        self.view.table.reset_mock()
        self.view.setVisualSettings({"FoldedColumns": {"test": True}})
        self.view.table.setFoldedColumns.assert_called_once_with(["test"])
        self.view.table.reset_mock()
        self.view.setVisualSettings({"FoldedColumns": {"test1": True}})
        self.view.table.setFoldedColumns.assert_called_once_with(["test1"])
        self.view.table.reset_mock()
        self.view.setVisualSettings({"FoldedColumns": ["test"]})
        self.view.table.setFoldedColumns.assert_called_once_with(["test"])

    def test_getVisualSettings(self):
        self.view.columns = ["test1", "test2", "test3"]
        self.view.table.getFoldedColumns.return_value = ["test1", "test3"]
        self.view.table.getHiddenColumns.return_value = ["test1", "test2"]
        self.view.table.getColumnsOrder.return_value = [
            "test1", "test2", "test3"
        ]
        d = {
            "FoldedColumns": ["test1", "test3"],
            "HiddenColumns": ["test1", "test2"],
            "ColumnsOrder": ["test1", "test2", "test3"]
        }
        self.assertDictEqual(self.view.getVisualSettings(), d)