From 9e4e9c722f80d22d3d67da98200026f522a7a3a4 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 12:19:10 +0000 Subject: [PATCH] Initial commit: CodeMap v0.1.0 - CLI tool for code analysis and diagram generation --- tests/test_python_parser.py | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/test_python_parser.py diff --git a/tests/test_python_parser.py b/tests/test_python_parser.py new file mode 100644 index 0000000..efc4480 --- /dev/null +++ b/tests/test_python_parser.py @@ -0,0 +1,73 @@ +import tempfile +import os +from pathlib import Path +from codemap.parsers import PythonParser + + +def test_parse_simple_python_file(): + parser = PythonParser() + code = ''' +import os +import sys +from pathlib import Path + +def hello(): + pass +''' + with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: + f.write(code) + temp_path = f.name + + try: + result = parser.parse(Path(temp_path)) + assert result.module_name == Path(temp_path).stem + assert result.file_type == "python" + assert len(result.dependencies) >= 2 + dep_names = [d.module_name for d in result.dependencies] + assert "os" in dep_names + assert "sys" in dep_names + assert "pathlib" in dep_names or "Path" in dep_names + finally: + os.unlink(temp_path) + + +def test_parse_python_with_from_import(): + parser = PythonParser() + code = ''' +from typing import List, Dict +from collections import Counter +''' + with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: + f.write(code) + temp_path = f.name + + try: + result = parser.parse(Path(temp_path)) + assert len(result.dependencies) >= 2 + finally: + os.unlink(temp_path) + + +def test_parse_python_with_syntax_error(): + parser = PythonParser() + code = ''' +def hello(: + pass +''' + with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: + f.write(code) + temp_path = f.name + + try: + result = parser.parse(Path(temp_path)) + assert result.file_type == "python" + finally: + os.unlink(temp_path) + + +def test_can_parse(): + parser = PythonParser() + assert parser.can_parse(Path("test.py")) == True + assert parser.can_parse(Path("test.pyi")) == True + assert parser.can_parse(Path("test.js")) == False + assert parser.can_parse(Path("test.go")) == False