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')])
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')] )
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()] )
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
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)
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")]
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()]
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))