Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Directory Pattern Matching Test Coverage #123

Merged
merged 6 commits into from
Jan 13, 2025
Merged
60 changes: 56 additions & 4 deletions tests/test_query_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,62 @@ def test_include_nonexistent_extension(temp_directory: Path, sample_query: dict[


# single folder patterns
# TODO: test with include patterns: ['src/*']
# TODO: test with include patterns: ['/src/*']
# TODO: test with include patterns: ['/src/']
# TODO: test with include patterns: ['/src*']
def test_include_src_star_pattern(temp_directory: Path, sample_query: dict[str, Any]) -> None:
"""
Test that when using 'src/*' as include pattern, files under the src directory
are included.
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
"""
sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src/*"]

result = _scan_directory(temp_directory, query=sample_query)
assert result is not None, "Result should not be None"

files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
# Convert Windows paths to Unix-style for test validation
file_paths = {f["path"].replace("\\", "/") for f in files}
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
assert file_paths == expected_paths, "Missing or unexpected files in result"


def test_include_src_recursive(temp_directory: Path, sample_query: dict[str, Any]) -> None:
"""
Test that when using 'src/**' as include pattern, all files under src
directory are included recursively.
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
"""
sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src/**"]

result = _scan_directory(temp_directory, query=sample_query)
assert result is not None, "Result should not be None"

files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
# Convert Windows paths to Unix-style for test validation
file_paths = {f["path"].replace("\\", "/") for f in files}
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
assert file_paths == expected_paths, "Missing or unexpected files in result"


def test_include_src_wildcard_prefix(temp_directory: Path, sample_query: dict[str, Any]) -> None:
"""
Test that when using 'src*' as include pattern, it matches the src directory
and any paths that start with 'src'.
Note: Windows is not supported - test converts Windows paths to Unix-style for validation.
"""
sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src*"]

result = _scan_directory(temp_directory, query=sample_query)
assert result is not None, "Result should not be None"

files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
# Convert Windows paths to Unix-style for test validation
file_paths = {f["path"].replace("\\", "/") for f in files}
expected_paths = {"src/subfile1.txt", "src/subfile2.py", "src/subdir/file_subdir.txt", "src/subdir/file_subdir.py"}
assert file_paths == expected_paths, "Missing or unexpected files in result"


# multiple patterns
# TODO: test with multiple include patterns: ['*.txt', '*.py']
Expand Down
Loading