Skip to content

Commit 85be231

Browse files
committed
Add test cases for directory pattern matching
1 parent 6d37e15 commit 85be231

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

tests/test_query_ingestion.py

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,90 @@ def test_include_txt_pattern(temp_directory: Path, sample_query: dict[str, Any])
7777
assert not any(path.endswith(".py") for path in file_paths), "Should not include .py files"
7878

7979

80-
# TODO: test with wrong include patterns: ['*.qwerty']
80+
def test_include_nonexistent_extension(temp_directory: Path, sample_query: dict[str, Any]) -> None:
81+
sample_query["local_path"] = temp_directory
82+
sample_query["include_patterns"] = ["*.query"] # Is a Non existant extension ?
83+
84+
result = _scan_directory(temp_directory, query=sample_query)
85+
assert result is not None, "Result should not be None"
86+
87+
# Extract the files content & set file limit cap
88+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
89+
# Verify no file processed with wrong extension
90+
assert len(files) == 0, "Should not find any files with .qwerty extension"
91+
92+
assert result["type"] == "directory"
93+
assert result["file_count"] == 0
94+
assert result["dir_count"] == 0
95+
assert len(result["children"]) == 0
8196

8297

8398
# single folder patterns
84-
# TODO: test with include patterns: ['src/*']
85-
# TODO: test with include patterns: ['/src/*']
86-
# TODO: test with include patterns: ['/src/']
87-
# TODO: test with include patterns: ['/src*']
99+
def test_include_src_star_pattern(temp_directory: Path, sample_query: dict[str, Any]) -> None:
100+
101+
sample_query["local_path"] = temp_directory
102+
sample_query["include_patterns"] = ["src/*"] # Without leading slash
103+
104+
result = _scan_directory(temp_directory, query=sample_query)
105+
assert result is not None, "Result should not be None"
106+
107+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
108+
assert len(files) == 4, "Should find all files under src directory"
109+
110+
# Normalize paths to use platform-specific separator
111+
file_paths = {str(Path(f["path"])) for f in files} # Using set and Path for normalization
112+
expected_paths = {
113+
str(Path("src/subfile1.txt")),
114+
str(Path("src/subfile2.py")),
115+
str(Path("src/subdir/file_subdir.txt")),
116+
str(Path("src/subdir/file_subdir.py")),
117+
}
118+
assert file_paths == expected_paths, "Missing or unexpected files in result"
119+
120+
121+
def test_include_src_recursive(temp_directory: Path, sample_query: dict[str, Any]) -> None:
122+
123+
sample_query["local_path"] = temp_directory
124+
sample_query["include_patterns"] = ["src/**"] # Use ** for recursive matching
125+
126+
result = _scan_directory(temp_directory, query=sample_query)
127+
assert result is not None, "Result should not be None"
128+
129+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
130+
assert len(files) == 4, "Should find all files under src/"
131+
132+
# Normalize paths to use platform-specific separator
133+
file_paths = {str(Path(f["path"])) for f in files}
134+
expected_paths = {
135+
str(Path("src/subfile1.txt")),
136+
str(Path("src/subfile2.py")),
137+
str(Path("src/subdir/file_subdir.txt")),
138+
str(Path("src/subdir/file_subdir.py")),
139+
}
140+
assert file_paths == expected_paths, "Missing or unexpected files in result"
141+
142+
143+
def test_include_src_wildcard_prefix(temp_directory: Path, sample_query: dict[str, Any]) -> None:
144+
145+
sample_query["local_path"] = temp_directory
146+
sample_query["include_patterns"] = ["src*"] # Without leading slash
147+
148+
result = _scan_directory(temp_directory, query=sample_query)
149+
assert result is not None, "Result should not be None"
150+
151+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
152+
assert len(files) == 4, "Should find all files under paths starting with src"
153+
154+
# Normalize paths to use platform-specific separator
155+
file_paths = {str(Path(f["path"])) for f in files}
156+
expected_paths = {
157+
str(Path("src/subfile1.txt")),
158+
str(Path("src/subfile2.py")),
159+
str(Path("src/subdir/file_subdir.txt")),
160+
str(Path("src/subdir/file_subdir.py")),
161+
}
162+
assert file_paths == expected_paths, "Missing or unexpected files in result"
163+
88164

89165
# multiple patterns
90166
# TODO: test with multiple include patterns: ['*.txt', '*.py']

0 commit comments

Comments
 (0)