How to use the darglint.utils.CykNodeUtils.contains 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
'    """foobar',
            '',
            '    Args:',
            '        foo: foobar',
            '',
            '    Returns:',
            '        bar',
            '',
            '    """',
            '    return "bar"',
        ])
        function = ast.parse(contents).body[0]
        docstring = ast.get_docstring(function)
        tokens = condense(lex(docstring))
        node = parse(tokens)
        self.assertTrue(CykNodeUtils.contains(node, 'short-description'))
        self.assertTrue(CykNodeUtils.contains(node, 'returns-section'))
        self.assertTrue(CykNodeUtils.contains(node, 'arguments-section'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_noqa_with_target_and_argument(self):
        """Make sure we can target specific args in a noqa."""
        node = parse(condense(lex('# noqa: I101 arg1, arg2\n')))
        self.assertTrue(CykNodeUtils.contains(node, 'noqa'), str(node))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_parse_sole_argument_with_two_lines_indent_error(self):
        docstring = '\n'.join([
            'Short.',
            '',
            'Args:',
            '    x: Something something something.',
            '    Something something.',
            '    Something, something, something.',
            '',
            'Returns:',
            '    A value.',
        ])
        tokens = condense(lex(docstring))
        node = parse(tokens)
        self.assertTrue(CykNodeUtils.contains(node, 'arguments-section'))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
'    SomethingException: Randomly.',
            '',
            'Non-Standard:'
            '    Everything about this.',
            '',
            'Yields:',
            '    Values to analyze.',
        ]))))
        for symbol in [
            'short-description',
            'long-description',
            'arguments-section',
            'raises-section',
            'yields-section',
        ]:
            self.assertTrue(CykNodeUtils.contains(node, symbol))
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_type_is_type(self):
        docstring = '\n'.join([
            'Takes a class and returns an instance.',
            '',
            'Args:',
            '    klass (type): A class to instantiate.',
            '    args (List[int]): The initial arguments to pass to it.',
            '',
        ])
        node = parse(condense(lex(docstring)))
        self.assertTrue(CykNodeUtils.contains(node, 'type-section-parens'))
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_sphinx_parser.py View on Github external
def test_parse_vartype_item_cyk(self):
        """Ensure we can parse a variable type description."""
        node = parse(condense(lex(
            'short\n\n:vartype foo: Dict[str][str]'
        )))
        self.assertTrue(
            CykNodeUtils.contains(node, 'variable-type-section'),
            node,
        )
github terrencepreilly / darglint / tests / test_sphinx_parser.py View on Github external
],
            'argument-type-section': ['type'],
            'variable-type-section': ['vartype'],
            'raises-section': ['raises'],
            # 'returns-section': ['returns'],
            # 'return-type-section': ['rtype'],
            'yields-section': ['yield', 'yields'],
        }
        for keyword_section in keywords:
            for keyword in keywords[keyword_section]:
                docstring = 'Short description.\n\n:{} a: something'.format(
                    keyword,
                )
                node = parse(condense(lex(docstring)))
                self.assertTrue(
                    CykNodeUtils.contains(node, keyword_section),
                    '{}: {}'.format(keyword_section, node)
                )
github terrencepreilly / darglint / tests / test_long_description_parse.py View on Github external
def test_noqa_always_on_left(self):
        raw = '\n'.join([
            '# noqa',
            'b',
        ])
        node = self.parse_string(raw)
        for noqa in self.get_identifiers(node, NoqaIdentifier):
            self.assertFalse(
                CykNodeUtils.contains(noqa, 'long-description'),
                'The noqa should be on its own, but was not:\n{}'.format(
                    noqa
                )
github terrencepreilly / darglint / tests / test_parser.py View on Github external
def test_no_blank_line_swallows_sections(self):
        """Make sure there must be a blank line after the short description."""
        node = parse(condense(lex('\n'.join([
            'Should not have a raises section.',
            'Args:',
            '    x: The divisor.',
            '    y: The dividend.',
            '',
        ]))))
        self.assertFalse(
            CykNodeUtils.contains(node, 'arguments-section'),
            'The arguments section should have been eaten -- that way the '
            'user gets a signal that they should separate the sections.'