Beispiel #1
0
def _parse_file(file_path):
    """Parse the specified configuration file, returning a nested dict
    of key/value pairs by section.

    :param str file_path: The path of the file to read.
    :rtype: dict

    """
    file_path = path.abspath(path.expanduser(path.expandvars(file_path)))
    LOGGER.debug('Reading file: %s', file_path)
    if not path.exists(file_path):
        raise exceptions.ConfigNotFound(path=file_path)

    parser = configparser.RawConfigParser()
    try:
        parser.read(file_path)
    except configparser.Error as error:
        LOGGER.error('Error reading file: %s', error)
        raise exceptions.ConfigParserError(path=file_path)

    config = {}
    for section in parser.sections():
        config[section] = {}
        for option in parser.options(section):
            config[section][option] = parser.get(section, option)
    return config
Beispiel #2
0
 def test_raises_config_parser_error(self):
     with mock.patch('tornado_aws.client.AsyncAWSClient.fetch') as fetch:
         fetch.side_effect = aws_exceptions.ConfigParserError(path='/test')
         with self.assertRaises(exceptions.ConfigParserError):
             yield self.client.create_table(self.generic_table_definition())
Beispiel #3
0
 def test_raises_config_parser_error(self):
     self.create_table_expecting_raise(
         dynamodb.ConfigParserError,
         aws_exceptions.ConfigParserError(path='/test'))