Skip to content

Commit 1aad87e

Browse files
authored
Merge branch 'main' into feature/extend-to-multiple-git-hosts
2 parents 31c695d + 1fd741a commit 1aad87e

File tree

1 file changed

+72
-5
lines changed

1 file changed

+72
-5
lines changed

tests/test_query_ingestion.py

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,81 @@ 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+
Test that when using 'src/*' as include pattern, files under the src directory
102+
are included.
103+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
104+
"""
105+
sample_query["local_path"] = temp_directory
106+
sample_query["include_patterns"] = ["src/*"]
107+
108+
result = _scan_directory(temp_directory, query=sample_query)
109+
assert result is not None, "Result should not be None"
110+
111+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
112+
# Convert Windows paths to Unix-style for test validation
113+
file_paths = {f["path"].replace("\\", "/") for f in files}
114+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
115+
assert file_paths == expected_paths, "Missing or unexpected files in result"
116+
117+
118+
def test_include_src_recursive(temp_directory: Path, sample_query: dict[str, Any]) -> None:
119+
"""
120+
Test that when using 'src/**' as include pattern, all files under src
121+
directory are included recursively.
122+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
123+
"""
124+
sample_query["local_path"] = temp_directory
125+
sample_query["include_patterns"] = ["src/**"]
126+
127+
result = _scan_directory(temp_directory, query=sample_query)
128+
assert result is not None, "Result should not be None"
129+
130+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
131+
# Convert Windows paths to Unix-style for test validation
132+
file_paths = {f["path"].replace("\\", "/") for f in files}
133+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
134+
assert file_paths == expected_paths, "Missing or unexpected files in result"
135+
136+
137+
def test_include_src_wildcard_prefix(temp_directory: Path, sample_query: dict[str, Any]) -> None:
138+
"""
139+
Test that when using 'src*' as include pattern, it matches the src directory
140+
and any paths that start with 'src'.
141+
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
142+
"""
143+
sample_query["local_path"] = temp_directory
144+
sample_query["include_patterns"] = ["src*"]
145+
146+
result = _scan_directory(temp_directory, query=sample_query)
147+
assert result is not None, "Result should not be None"
148+
149+
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
150+
# Convert Windows paths to Unix-style for test validation
151+
file_paths = {f["path"].replace("\\", "/") for f in files}
152+
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
153+
assert file_paths == expected_paths, "Missing or unexpected files in result"
154+
88155

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

0 commit comments

Comments
 (0)