Exemple #1
0
 def test_parse_line_with_parentheses(self):
     """Make sure lines can have parentheses in them."""
     node = parse_line(
         Peaker(lex('This is a (parenthis-containing) line.\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
Exemple #2
0
 def test_parse_empty_line(self):
     """Make sure we can parse a line with just an indent."""
     node = parse_line(Peaker(lex(' ' * 4 + '\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(
         child_types,
         [NodeType.INDENT, NodeType.LINE],
     )
Exemple #3
0
 def test_parse_line_without_indent(self):
     """Make sure lines don't need to have indents."""
     node = parse_line(Peaker(lex('word word\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(
         child_types,
         [NodeType.WORD, NodeType.WORD, NodeType.LINE],
     )
Exemple #4
0
 def test_parse_line_with_colons(self):
     """Make sure lines with colons can be parsed."""
     node = parse_line(Peaker(lex('    ::\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(child_types, [
         NodeType.INDENT,
         NodeType.COLON,
         NodeType.COLON,
         NodeType.LINE,
     ])
Exemple #5
0
 def test_parse_line_with_multiple_indents(self):
     """Make sure code snippets are okay."""
     node = parse_line(Peaker(lex('        word.\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(child_types, [
         NodeType.INDENT,
         NodeType.INDENT,
         NodeType.WORD,
         NodeType.LINE,
     ])
Exemple #6
0
 def test_parse_inline_noqa_statements(self):
     """Make sure we can parse noqa statements."""
     node = parse_line(Peaker(lex('Something something.  # noqa: I201\n')))
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(child_types, [
         NodeType.WORD,
         NodeType.WORD,
         NodeType.HASH,
         NodeType.WORD,
         NodeType.NOQA_HEAD,
         NodeType.COLON,
         NodeType.WORD,
         NodeType.NOQA_BODY,
         NodeType.NOQA,
         NodeType.LINE,
     ])
Exemple #7
0
 def test_parse_line_which_looks_like_definition(self):
     """Make sure a line which looks like a definition can be parsed."""
     node = parse_line(Peaker(lex('    Returns: Some value.\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(child_types, [
         NodeType.INDENT,
         NodeType.RETURNS,
         NodeType.COLON,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.LINE,
     ])
Exemple #8
0
 def test_parse_line_with_words(self):
     """Make sure we can parse a line with words."""
     node = parse_line(Peaker(lex('    this is a line with words\n')))
     self.assertEqual(
         node.node_type,
         NodeType.LINE,
     )
     child_types = [x.node_type for x in node.walk()]
     self.assertEqual(child_types, [
         NodeType.INDENT,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.WORD,
         NodeType.LINE,
     ])