def test_cyk_noqa_matches(self): for raw in [ '# noqa', '# noqa: I102', '# noqa: I301 E102 I320', 'random words # noqa', 'random words # noqa: I102', 'random words # noqa: I301 E102 I320', # FIXME: These should parse with Cyk... # '# noqa\n', # '# noqa: I102\n', # '# noqa: I301 E102 I320\n', ]: recursive_node = self.parse_string(raw) recursive_noqa = self.get_identifier( recursive_node, NoqaIdentifier ) self.assertTrue(recursive_noqa) cyk_node = cyk_parse(LongDescriptionGrammar, condense(lex(raw))) cyk_noqa = self.get_identifier(cyk_node, NoqaIdentifier) self.assertTrue(cyk_noqa) self.assertNodesEqual( cyk_noqa, recursive_noqa, repr(raw) )
def test_specific(self): tokens = [ Token( token_type=TokenType.LPAREN, value='', line_number=0, ), Token( token_type=TokenType.ARGUMENTS, value='', line_number=0, ), Token( token_type=TokenType.NEWLINE, value='', line_number=0, ), ] grammar = lookup(tokens)[0] self.assertTrue(grammar is not None) if inspect.isclass(grammar): parsed = cyk_parse(grammar, tokens) else: parsed = grammar(tokens) self.assertTrue(parsed is not None)
def test_lookup_tries_return_section_before_long_description(self): section = condense(lex('\n'.join([ 'Returns:', ' x: A number.', ]))) grammars = lookup(section) node = None for grammar in grammars: node = cyk_parse(grammar, section) if node: break self.assertTrue(node) self.assertEqual( node.symbol, 'returns-section', str(node), )