From c7fbd8216922e43d11d19cf44753f97b514853ff Mon Sep 17 00:00:00 2001 From: Joseph Torsney <joseph.torsney@stfc.ac.uk> Date: Mon, 1 Mar 2021 14:14:47 +0000 Subject: [PATCH] Add tests for workbench.util.io --- .../workbench/workbench/utils/test/test_io.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 qt/applications/workbench/workbench/utils/test/test_io.py diff --git a/qt/applications/workbench/workbench/utils/test/test_io.py b/qt/applications/workbench/workbench/utils/test/test_io.py new file mode 100644 index 00000000000..ebfe74c7db9 --- /dev/null +++ b/qt/applications/workbench/workbench/utils/test/test_io.py @@ -0,0 +1,43 @@ +# Mantid Repository : https://github.com/mantidproject/mantid +# +# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI, +# NScD Oak Ridge National Laboratory, European Spallation Source, +# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +# SPDX - License - Identifier: GPL - 3.0 + +# This file is part of the mantidworkbench package +from unittest import TestCase +from unittest.mock import patch + +from PyQt5.QtWidgets import QInputDialog +from workbench.utils.io import input_qinputdialog + + +class IOTest(TestCase): + + @patch('workbench.utils.io.QInputDialog') + def test_input_qinputdialog_setup_is_correct(self, mock_QInputDialogClass): + mock_QInputDialogClass.TextInput = QInputDialog.TextInput + mock_QInputDialog = mock_QInputDialogClass() + + _ = input_qinputdialog("prompt") + + mock_QInputDialog.setInputMode.assert_called_with(QInputDialog.TextInput) + mock_QInputDialog.setLabelText.assert_called_with("prompt") + + @patch('workbench.utils.io.QInputDialog') + def test_input_qinputdialog_return_value_is_correct_when_dialog_accepted(self, mock_QInputDialogClass): + mock_QInputDialog = mock_QInputDialogClass() + mock_QInputDialog.exec_.return_value = True + mock_QInputDialog.textValue.return_value = "their input" + + user_input = input_qinputdialog() + + self.assertEqual(user_input, "their input") + + @patch('workbench.utils.io.QInputDialog') + def test_input_qinputdialog_raises_RuntimeError_when_input_cancelled(self, mock_QInputDialogClass): + mock_QInputDialog = mock_QInputDialogClass() + mock_QInputDialog.exec_.return_value = False + + self.assertRaises(RuntimeError, input_qinputdialog) + -- GitLab