Exemplo n.º 1
0
    def test_wraps_exceptions_toml(self):
        expected_wrapped = [KeyError(), NotImplementedError(), ValueError()]

        for known_exception in expected_wrapped:
            with mock.patch("sans.gui_logic.models.file_loading.TomlParser"
                            ) as mocked_module:
                mocked_parser = mock.Mock()
                mocked_module.return_value = mocked_parser

                mocked_parser.parse_toml_file.side_effect = known_exception
                with self.assertRaises(UserFileLoadException):
                    FileLoading.load_user_file(mock.Mock(), None)

        not_wrapped = [KeyboardInterrupt(), SystemExit(), RuntimeError()]
        for unexpected_exception in not_wrapped:
            with mock.patch("sans.gui_logic.models.file_loading.TomlParser"
                            ) as mocked_module:
                mocked_parser = mock.Mock()
                mocked_module.return_value = mocked_parser
                mocked_parser.parse_toml_file.side_effect = unexpected_exception
                with self.assertRaises(type(unexpected_exception)):
                    FileLoading.load_user_file(mock.Mock(), None)
Exemplo n.º 2
0
    def test_can_parse_toml_file(self):
        mock_path = mock.NonCallableMock()
        with mock.patch("sans.gui_logic.models.file_loading.TomlParser"
                        ) as mocked_module:
            mocked_parser = mock.Mock()
            mocked_module.return_value = mocked_parser

            file_info = mock.NonCallableMock()
            result = FileLoading.load_user_file(file_path=mock_path,
                                                file_information=file_info)
            mocked_parser.parse_toml_file.assert_called_once_with(
                mock_path, file_information=file_info)
            self.assertEqual(result,
                             mocked_parser.parse_toml_file.return_value)
Exemplo n.º 3
0
    def test_wraps_legacy_exceptions(self):
        expected_wrapped = [RuntimeError(), ValueError()]

        for known_exception in expected_wrapped:
            with mock.patch(
                    "sans.gui_logic.models.file_loading.UserFileReaderAdapter"
            ) as mocked_module:
                mocked_parser = mock.Mock()
                mocked_module.return_value = mocked_parser

                mocked_parser.get_all_states.side_effect = known_exception
                with self.assertRaises(UserFileLoadException):
                    FileLoading.load_user_file('legacy.txt', None)

        not_wrapped = [KeyboardInterrupt(), SystemExit()]
        for unexpected_exception in not_wrapped:
            with mock.patch(
                    "sans.gui_logic.models.file_loading.UserFileReaderAdapter"
            ) as mocked_module:
                mocked_parser = mock.Mock()
                mocked_module.return_value = mocked_parser
                mocked_parser.get_all_states.side_effect = unexpected_exception
                with self.assertRaises(type(unexpected_exception)):
                    FileLoading.load_user_file('legacy.txt', None)
Exemplo n.º 4
0
 def _load_current_state(self, file_information, row_user_file):
     if row_user_file:
         # Has a custom user file so ignore any settings from GUI
         user_file_path = FileFinder.getFullPath(row_user_file)
         if not os.path.exists(user_file_path):
             raise ValueError(
                 f"The user path {user_file_path}\n"
                 " does not exist. Make sure a valid user file has been specified."
             )
         state = FileLoading.load_user_file(
             user_file_path, file_information=file_information)
         gui_state = StateGuiModel(state)
     else:
         # We want to copy our master GUI state to set any row options (see prototype pattern)
         gui_state = copy.deepcopy(self._state_gui_model)
     return gui_state