How to use the darglint.parse.google.parse function in darglint

To help you get started, we’ve selected a few darglint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_bare_noqa_can_be_parsed(self):
        docstring = '\n'.join([
            'The first line may have something, but others are missing.',
            '',
            '# noqa'
        ])
        node = parse(condense(lex(docstring)))
        self.assertTrue(CykNodeUtils.contains(node, 'noqa'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_raises(self):
        docstring = '\n'.join([
            'This has a problem.',
            '',
            'Raises:',
            '    Exception: An exception for generic reasons.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'raises-section')
        self.assertContains(tree, 'exception')
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_whole_description(self):
        """Make sure we can handle descriptions of multiple lines."""
        node = parse(condense(lex(
            'Short description\n'
            '\n'
            'Long : (description)\n'
            '\n'
            '    <code></code>\n'
            '\n'
        )))
        self.assertTrue(node)
        self.assertTrue(CykNodeUtils.contains(node, 'short-description'))
        self.assertTrue(CykNodeUtils.contains(node, 'long-description'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_line_with_parentheses(self):
        docstring = 'A short (description) with parentheses.'
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
github terrencepreilly / darglint / tests / test_parser.py View on Github external
"""
        # Should raise exception if not valid.  The ast module
        # handles line continuation in docstrings, surprisingly.
        # So, it just ends up looking like indents in random places.
        # Probably, indents shouldn't have been lexed except
        # immediately after newlines.
        docstring = '\n'.join([
            'Do something with complex array types.',
            '',
            'Args:',
            '    item (AVeryLongTypeDefinitionWhichMustBeSplit,',
            '       AcrossMultipleLines): Actually quite simple.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'type-section-parens')
github terrencepreilly / darglint / tests / test_parser.py View on Github external
verbosity: An integer in the set {1,2}, where 1 is a more
                terse message, and 2 includes a general description.
            raises: True if it should raise an exception.

        Raises:
            Exception: If the verbosity level is not recognized.

        Returns:
            An error message.

        """
        pass
''')
        docstring = ast.get_docstring(ast.parse(program).body[0].body[0])
        tokens = condense(lex(docstring))
        node = parse(tokens)
        self.assertTrue(CykNodeUtils.contains(node, 'arguments-section'))
        annotation_lookup = self.get_annotation_lookup(node)
        self.assertEqual(len(annotation_lookup[ArgumentIdentifier]), 2)
        values = {
            ArgumentIdentifier.extract(x)
            for x in annotation_lookup[ArgumentIdentifier]
        }
        self.assertEqual(
            values,
            {'verbosity', 'raises'},
        )
github terrencepreilly / darglint / tests / test_parser.py View on Github external
'The __init__ method may be documented in either the class level',
            'docstring, or as a docstring on the __init__ method itself.',
            '',
            'Either form is acceptable, but the two should not be mixed. Choose one',  # noqa: E501
            'convention to document the __init__ method and be consistent with it.',  # noqa: E501
            '',
            'Note:',
            '    Do not include the `self` parameter in the ``Args`` section.',
            '',
            'Args:',
            '    param1: Description of `param1`.',
            '    param2: Description of `param2`. Multiple',  # noqa: E501
            '        lines are supported.',
            '    param3: Description of `param3`.',
        ])
        node = parse(condense(lex(docstring)))
        self.assertTrue(CykNodeUtils.contains(node, 'arguments-section'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_line_with_multiple_indents(self):
        docstring = '\n'.join([
            'The short description.',
            '',
            '            The long description.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'long-description')
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_underindented_raises_section(self):
        docstring = '\n'.join([
            'Iterates through the records.',
            '',
            'Args:',
            '    address: The address of the database.',
            '',
            'Raises:',
            '    StopIteration:  Once there are no more records,',
            '    or possible if there were never any records.',
            '',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        annotation_lookup = self.get_annotation_lookup(tree)
        self.assertEqual(
            len(annotation_lookup[IndentError]),
            1
        )
        values = {
            ExceptionIdentifier.extract(x)
            for x in annotation_lookup[ExceptionIdentifier]
        }
        self.assertEqual(
            values,
            {'StopIteration'},
        )
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_star_arguments(self):
        docstring = '\n'.join([
            'Negate a function which returns a boolean.',
            '',
            'Args:',
            '    *fns (int): Functions which returns a boolean.',
            '',
            'Returns:',
            '    int: A function which returns fallse when any of the'
            '        callables return true, and true will all of the ',
            '        callables return false.',
        ])
        tokens = condense(lex(docstring))
        tree = parse(tokens)
        self.assertTrue(tree is not None)
        self.assertContains(tree, 'arguments')