1+ from codetide .parsers .generic_parser import GenericParser
2+ from codetide .core .models import CodeFileModel
3+
4+ import asyncio
5+ import pytest
6+
7+ class TestGenericParser :
8+ @pytest .fixture
9+ def parser (self ):
10+ return GenericParser ()
11+
12+ def test_language_property (self , parser ):
13+ """Test that language property returns 'any'"""
14+ assert parser .language == "any"
15+
16+ def test_extension_property (self , parser ):
17+ """Test that extension property returns empty string"""
18+ assert parser .extension == ""
19+
20+ def test_tree_parser_property (self , parser ):
21+ """Test that tree_parser property returns None"""
22+ assert parser .tree_parser is None
23+
24+ def test_import_statement_template (self , parser ):
25+ """Test that import_statement_template returns None"""
26+ assert parser .import_statement_template (None ) is None
27+
28+ @pytest .mark .asyncio
29+ async def test_parse_file_with_absolute_path (self , parser , tmp_path ):
30+ """Test parsing a file with absolute path"""
31+ test_file = tmp_path / "test.txt"
32+ test_file .write_text ("test content" )
33+
34+ result = await parser .parse_file (test_file )
35+ assert isinstance (result , CodeFileModel )
36+ assert result .file_path == str (test_file )
37+ assert not result .imports
38+ assert not result .variables
39+ assert not result .functions
40+ assert not result .classes
41+
42+ @pytest .mark .asyncio
43+ async def test_parse_file_with_relative_path (self , parser , tmp_path ):
44+ """Test parsing a file with relative path and root_path"""
45+ # Create a test directory structure
46+ root_dir = tmp_path / "project"
47+ root_dir .mkdir ()
48+ test_file = root_dir / "test.txt"
49+ test_file .write_text ("test content" )
50+
51+ # Get relative path from within the project
52+ rel_path = test_file .relative_to (root_dir )
53+
54+ result = await parser .parse_file (test_file , root_path = root_dir )
55+ assert isinstance (result , CodeFileModel )
56+ assert result .file_path == str (rel_path )
57+
58+ @pytest .mark .asyncio
59+ async def test_parse_file_with_string_path (self , parser , tmp_path ):
60+ """Test parsing a file with string path"""
61+ test_file = tmp_path / "test.txt"
62+ test_file .write_text ("test content" )
63+
64+ result = await parser .parse_file (str (test_file ))
65+ assert isinstance (result , CodeFileModel )
66+ assert result .file_path == str (test_file )
67+
68+ def test_parse_code (self , parser , tmp_path ):
69+ """Test the synchronous parse_code method"""
70+ test_file = tmp_path / "test.txt"
71+ result = parser .parse_code (test_file )
72+ assert isinstance (result , CodeFileModel )
73+ assert result .file_path == str (test_file )
74+
75+ def test_resolve_inter_files_dependencies (self , parser ):
76+ """Test that resolve_inter_files_dependencies does nothing"""
77+ # Should not raise any exceptions
78+ parser .resolve_inter_files_dependencies (None )
79+
80+ def test_resolve_intra_file_dependencies (self , parser ):
81+ """Test that resolve_intra_file_dependencies does nothing"""
82+ # Should not raise any exceptions
83+ parser .resolve_intra_file_dependencies ([])
84+
85+ @pytest .mark .asyncio
86+ async def test_concurrent_parsing (self , parser , tmp_path ):
87+ """Test that parser can handle concurrent requests"""
88+ files = [tmp_path / f"test_{ i } .txt" for i in range (5 )]
89+ for file in files :
90+ file .write_text ("content" )
91+
92+ # Parse all files concurrently
93+ tasks = [parser .parse_file (file ) for file in files ]
94+ results = await asyncio .gather (* tasks )
95+
96+ assert len (results ) == 5
97+ for result in results :
98+ assert isinstance (result , CodeFileModel )
99+
100+ def test_filepath_attribute (self , parser ):
101+ """Test that _filepath attribute exists and is None by default"""
102+ assert hasattr (parser , '_filepath' )
103+ assert parser ._filepath is None
0 commit comments