Team Ai
Modelpublic

niishantth/codegraph

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_parser.py43 linesDownload Raw Back to tests
1"""Unit tests for the parser module."""2 3from codegraph.parser import SourceParser, CodebaseScanner4from codegraph.models import EntityType5 6 7def test_parse_python_function():8    source = """9def foo(x):10    return x + 111"""12    parser = SourceParser("/tmp/test.py", source)13    entities = parser.parse()14    funcs = [e for e in entities if e.type == EntityType.FUNCTION]15    assert len(funcs) == 116    assert funcs[0].name == "foo"17    assert funcs[0].span.start.line == 218 19 20def test_parse_python_class_with_method():21    source = """22class Bar:23    def baz(self):24        pass25"""26    parser = SourceParser("/tmp/test.py", source)27    entities = parser.parse()28    classes = [e for e in entities if e.type == EntityType.CLASS]29    methods = [e for e in entities if e.type == EntityType.METHOD]30    assert len(classes) == 131    assert classes[0].name == "Bar"32    assert len(methods) == 133    assert methods[0].name == "baz"34 35 36def test_scan_directory():37    scanner = CodebaseScanner("/app/sample_project")38    entities = scanner.scan()39    assert len(entities) > 040    names = {e.name for e in entities}41    assert "DataProcessor" in names42    assert "helper_a" in names43