# Path: libcloud_rest/api/parser.py
# XHEADERS_TO_ARGS_DICT = {
#     'x-auth-user': 'key',
#     'x-api-key': 'secret',
#     'x-provider-path': 'path',
#     'x-provider-port': 'port',
#     'x-provider-host': 'host',
#     'x-dummy-creds': 'creds',  # FIXME: for tests only
#     'x-provider-key': 'key',
#     'x-provider-uri': 'uri',
#     'x-provider-api-version': 'api_version',
#     'x-provider-secure': 'secure',
#     'x-provider-datacenter': 'datacenter',
# }
# ARGS_TO_XHEADERS_DICT = dict(
#     ([k, v] for v, k in XHEADERS_TO_ARGS_DICT.items()))
# _SUPPORTED_FIELDS = set([
#     '@param',
#     '@type',
#     '@keyword',
#     '@rtype:',
#     '@inherits:',
#     '@return:',
# ])
# def parse_request_headers(headers):
# def get_method_docstring(cls, method_name):
# def _parse_docstring_field(field_lines):
# def _find_parent_cls(cls, cls_name):
# def _parse_inherit(cls, inherits):
# def _ignored_field(field_str):
# def split_docstring(docstring):
# def _check_arguments_dict(arguments):
# def parse_docstring(docstring, cls=None):
# def parse_args(method):


import unittest2
from libcloud_rest.api import parser
from libcloud_rest.errors import MethodParsingException
        Return a Zone instance.
        Second line docsting.

        @type zone_id: C{str}
        @param zone_id: Required zone id (required)

        @keyword    auth:   Initial authentication information for the node
                            (optional)
        @type       auth:   L{NodeAuthSSHKey} or L{NodeAuthPassword}

        @return:    instance
        @rtype:     L{Zone} or L{Node}
        """
        result = parser.parse_docstring(docstring)
        description = result['description']
        args = result['arguments']
        return_type = result['return']['type_name']
        return_description = result['return']['description']
        self.assertTrue(description.startswith('Return'))
        self.assertTrue('Second line' in description)
        self.assertEqual(args['zone_id']['type_name'], 'C{str}')
        self.assertEqual(args['zone_id']['required'], True)
        self.assertItemsEqual(args['auth']['type_name'],
                              'L{NodeAuthSSHKey} or L{NodeAuthPassword}')
        self.assertEqual(args['auth']['required'], False)
        self.assertEqual(return_type, 'L{Zone} or L{Node}')
        self.assertEqual(return_description, 'instance')

    def test_parse_docstring_fails(self):
        docstring = """

# Path: libcloud_rest/api/parser.py
# XHEADERS_TO_ARGS_DICT = {
#     'x-auth-user': 'key',
#     'x-api-key': 'secret',
#     'x-provider-path': 'path',
#     'x-provider-port': 'port',
#     'x-provider-host': 'host',
#     'x-dummy-creds': 'creds',  # FIXME: for tests only
#     'x-provider-key': 'key',
#     'x-provider-uri': 'uri',
#     'x-provider-api-version': 'api_version',
#     'x-provider-secure': 'secure',
#     'x-provider-datacenter': 'datacenter',
# }
# ARGS_TO_XHEADERS_DICT = dict(
#     ([k, v] for v, k in XHEADERS_TO_ARGS_DICT.items()))
# _SUPPORTED_FIELDS = set([
#     '@param',
#     '@type',
#     '@keyword',
#     '@rtype:',
#     '@inherits:',
#     '@return:',
# ])
# def parse_request_headers(headers):
# def get_method_docstring(cls, method_name):
# def _parse_docstring_field(field_lines):
# def _find_parent_cls(cls, cls_name):
# def _parse_inherit(cls, inherits):
# def _ignored_field(field_str):
# def split_docstring(docstring):
# def _check_arguments_dict(arguments):
# def parse_docstring(docstring, cls=None):
# def parse_args(method):


# Path: tests/test_parser.py
import unittest2
from libcloud_rest.api import parser
from libcloud_rest.errors import MethodParsingException

        Return a Zone instance.
        Second line docsting.

        @type zone_id: C{str}
        @param zone_id: Required zone id (required)

        @keyword    auth:   Initial authentication information for the node
                            (optional)
        @type       auth:   L{NodeAuthSSHKey} or L{NodeAuthPassword}

        @return:    instance
        @rtype:     L{Zone} or L{Node}
        """
        result = parser.parse_docstring(docstring)
        description = result['description']
        args = result['arguments']
        return_type = result['return']['type_name']
        return_description = result['return']['description']
        self.assertTrue(description.startswith('Return'))
        self.assertTrue('Second line' in description)
        self.assertEqual(args['zone_id']['type_name'], 'C{str}')
        self.assertEqual(args['zone_id']['required'], True)
        self.assertItemsEqual(args['auth']['type_name'],
                              'L{NodeAuthSSHKey} or L{NodeAuthPassword}')
        self.assertEqual(args['auth']['required'], False)
        self.assertEqual(return_type, 'L{Zone} or L{Node}')
        self.assertEqual(return_description, 'instance')

    def test_parse_docstring_fails(self):
        docstring = """

        Return a Zone instance.