Ejemplo n.º 1
0
 def test_can_compute_python_line_parts(self):
     python_lexer = lexers.get_lexer_by_name('python')
     self.assertEqual(list(analysis._line_parts(python_lexer, '#')),
                      [set('d')])
     self.assertEqual(
         list(analysis._line_parts(python_lexer, "s = 'x'  # x")),
         [set('cds')])
Ejemplo n.º 2
0
 def test_can_compute_python_line_parts(self):
     python_lexer = lexers.get_lexer_by_name('python')
     self.assertEqual(
         list(analysis._line_parts(python_lexer, '#')),
         [set('d')]
     )
     self.assertEqual(
         list(analysis._line_parts(python_lexer, "s = 'x'  # x")),
         [set('cds')]
     )
Ejemplo n.º 3
0
 def test_can_detect_white_text(self):
     python_lexer = lexers.get_lexer_by_name('python')
     self.assertEqual(
         list(analysis._line_parts(python_lexer, '{[()]};')),
         [set()]
     )
     self.assertEqual(
         list(analysis._line_parts(python_lexer, 'pass')),
         [set()]
     )
Ejemplo n.º 4
0
 def test_can_detect_white_text(self):
     python_lexer = lexers.get_lexer_by_name('python')
     self.assertEqual(
         list(analysis._line_parts(python_lexer, '{[()]};')),
         [set()]
     )
     self.assertEqual(
         list(analysis._line_parts(python_lexer, 'pass')),
         [set()]
     )
Ejemplo n.º 5
0
 def test_can_analyze_python(self):
     source_code = (
         '"Some tool."\n' "#!/bin/python\n" "#(C) by me\n" "def x():\n" '    "Some function"\n' '    return "abc"\n'
     )
     python_lexer = lexers.get_lexer_by_name("python")
     actual_line_parts = list(analysis._line_parts(python_lexer, source_code))
     expected_line_parts = [{"d"}, {"d"}, {"d"}, {"c"}, {"d"}, {"c", "s"}]
     assert actual_line_parts == expected_line_parts
Ejemplo n.º 6
0
 def test_can_analyze_python(self):
     source_code = \
         '"Some tool."\n' \
         '#!/bin/python\n' \
         '#(C) by me\n' \
         'def x():\n' \
         '    "Some function"\n' \
         '    return "abc"\n'
     python_lexer = lexers.get_lexer_by_name('python')
     actual_line_parts = list(analysis._line_parts(python_lexer, source_code))
     expected_line_parts = [{'d'}, {'d'}, {'d'}, {'c'}, {'d'}, {'c', 's'}]
     self.assertEqual(actual_line_parts, expected_line_parts)
Ejemplo n.º 7
0
 def test_can_analyze_python(self):
     source_code = \
         '"Some tool."\n' \
         '#!/bin/python\n' \
         '#(C) by me\n' \
         'def x():\n' \
         '    "Some function"\n' \
         '    return "abc"\n'
     python_lexer = lexers.get_lexer_by_name('python')
     actual_line_parts = list(analysis._line_parts(python_lexer, source_code))
     expected_line_parts = [{'d'}, {'d'}, {'d'}, {'c'}, {'d'}, {'c', 's'}]
     self.assertEqual(actual_line_parts, expected_line_parts)
Ejemplo n.º 8
0
 def test_can_compute_python_line_parts(self):
     python_lexer = lexers.get_lexer_by_name("python")
     assert list(analysis._line_parts(python_lexer, "#")) == [set("d")]
     assert list(analysis._line_parts(python_lexer,
                                      "s = 'x'  # x")) == [set("cds")]
Ejemplo n.º 9
0
 def test_can_detect_white_text(self):
     python_lexer = lexers.get_lexer_by_name("python")
     assert list(analysis._line_parts(python_lexer, "{[()]};")) == [set()]
     assert list(analysis._line_parts(python_lexer, "pass")) == [set()]
Ejemplo n.º 10
0
 def _line_parts(lexer_name: str,
                 source_lines: List[str]) -> List[Set[str]]:
     lexer = lexers.get_lexer_by_name(lexer_name)
     source_code = "\n".join(source_lines)
     return list(analysis._line_parts(lexer, source_code))