|
4 | 4 | # NScD Oak Ridge National Laboratory, European Spallation Source,
|
5 | 5 | # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
|
6 | 6 | # SPDX - License - Identifier: GPL - 3.0 +
|
| 7 | +import os |
7 | 8 | import unittest
|
8 | 9 | from unittest import mock
|
9 | 10 | from mantidqt.utils.qt.testing import start_qapplication
|
@@ -393,11 +394,40 @@ def test_periods_button_data_missing_added_successfully(self):
|
393 | 394 | self.assertEqual(1, self.presenter.period_info_widget.show.call_count)
|
394 | 395 |
|
395 | 396 | def test_check_and_get_filename_empty_filename(self):
|
396 |
| - # self.view.show_question_dialog = mock.MagicMock(return_value=True) |
397 | 397 | filename = self.presenter._check_and_get_filename("")
|
398 |
| - |
399 | 398 | self.assertEqual(filename, "")
|
400 | 399 |
|
| 400 | + def test_check_and_get_filename_with_xml_extension(self): |
| 401 | + expected_filename = "file.xml" |
| 402 | + filename = self.presenter._check_and_get_filename(expected_filename) |
| 403 | + self.assertEqual(filename, expected_filename) |
| 404 | + |
| 405 | + def _run_test_check_and_get_filename_without_xml_extension( |
| 406 | + self, |
| 407 | + expected_filename, |
| 408 | + given_filename, |
| 409 | + isfile=True, |
| 410 | + return_val=True, |
| 411 | + ): |
| 412 | + # Pretend file already exists. |
| 413 | + os.path.isfile = mock.MagicMock(return_value=isfile) |
| 414 | + # User selects "yes" to replace existing file |
| 415 | + self.view.show_question_dialog = mock.MagicMock(return_value=return_val) |
| 416 | + |
| 417 | + filename = self.presenter._check_and_get_filename(given_filename) |
| 418 | + self.assertEqual(filename, expected_filename) |
| 419 | + |
| 420 | + def test_check_and_get_filename_without_xml_extension_if_xml_file_exists(self): |
| 421 | + self._run_test_check_and_get_filename_without_xml_extension("file.xml", "file.txt") |
| 422 | + |
| 423 | + def test_check_and_get_filename_without_xml_extension_if_xml_file_exists_no_overwrite( |
| 424 | + self, |
| 425 | + ): |
| 426 | + self._run_test_check_and_get_filename_without_xml_extension("", "file.txt") |
| 427 | + |
| 428 | + def test_check_and_get_filename_without_xml_extension_if_xml_file_not_exists(self): |
| 429 | + self._run_test_check_and_get_filename_without_xml_extension("file.xml", "file.txt", isfile=False, return_val=False) |
| 430 | + |
401 | 431 |
|
402 | 432 | if __name__ == "__main__":
|
403 | 433 | unittest.main(buffer=False, verbosity=2)
|
0 commit comments