Exemple #1
0
 def _parse_toml(file_path, file_information):
     parser = TomlParser()
     try:
         return parser.parse_toml_file(file_path,
                                       file_information=file_information)
     except KeyError as e:
         raise UserFileLoadException(f"The following key is missing: {e}")
     except (NotImplementedError, ValueError) as e:
         raise UserFileLoadException(e)
    def test_parse_toml_file_calls_get_all_states(self):
        test_dict = {"toml_file_version": 0}

        parser = TomlParser(toml_reader=self.get_mocked_reader(test_dict))
        with mock.patch("sans.user_file.toml_parsers.toml_parser.TomlV1Parser"
                        ) as mocked_parser:
            parsed = parser.parse_toml_file(mock.NonCallableMock,
                                            file_information=None)
            mocked_parser.return_value.get_all_states.assert_called_once()
            self.assertEqual(
                mocked_parser.return_value.get_all_states.return_value, parsed)
Exemple #3
0
    def _process_user_file(self, command, file_information):
        """
        Processes a user file and retain the parased tags

        @param command: the command with the user file path
        """
        file_name = command.values[0]

        if file_name.casefold().endswith(".toml".casefold()):
            toml_file_reader = TomlParser()
            new_state_entries = toml_file_reader.parse_toml_file(
                toml_file_path=file_name, file_information=file_information)
        else:
            # Now comes the fun part where we try to coerce this to put out a State* object
            user_file_reader = UserFileReader(file_name)
            old_param_mapping = user_file_reader.read_user_file()
            command_adapter = CommandInterfaceAdapter(
                processed_state=old_param_mapping,
                file_information=file_information)
            new_state_entries = command_adapter.get_all_states(
                file_information=file_information)

        new_state_entries.data = self._data_info
        return new_state_entries