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

Add test for non-existent file extension pattern (*.qwerty) #120

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 81 additions & 5 deletions tests/test_query_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,90 @@ def test_include_txt_pattern(temp_directory: Path, sample_query: dict[str, Any])
assert not any(path.endswith(".py") for path in file_paths), "Should not include .py files"


# TODO: test with wrong include patterns: ['*.qwerty']
def test_include_nonexistent_extension(temp_directory: Path, sample_query: dict[str, Any]) -> None:
sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["*.query"] # Is a Non existant extension ?

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

# Extract the files content & set file limit cap
files = _extract_files_content(query=sample_query, node=result, max_file_size=1_000_000)
# Verify no file processed with wrong extension
assert len(files) == 0, "Should not find any files with .qwerty extension"

assert result["type"] == "directory"
assert result["file_count"] == 0
assert result["dir_count"] == 0
assert len(result["children"]) == 0


# 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:

sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src/*"] # Without leading slash

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)
assert len(files) == 4, "Should find all files under src directory"

# Normalize paths to use platform-specific separator
file_paths = {str(Path(f["path"])) for f in files} # Using set and Path for normalization
expected_paths = {
str(Path("src/subfile1.txt")),
str(Path("src/subfile2.py")),
str(Path("src/subdir/file_subdir.txt")),
str(Path("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:

sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src/**"] # Use ** for recursive matching

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)
assert len(files) == 4, "Should find all files under src/"

# Normalize paths to use platform-specific separator
file_paths = {str(Path(f["path"])) for f in files}
expected_paths = {
str(Path("src/subfile1.txt")),
str(Path("src/subfile2.py")),
str(Path("src/subdir/file_subdir.txt")),
str(Path("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:

sample_query["local_path"] = temp_directory
sample_query["include_patterns"] = ["src*"] # Without leading slash

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)
assert len(files) == 4, "Should find all files under paths starting with src"

# Normalize paths to use platform-specific separator
file_paths = {str(Path(f["path"])) for f in files}
expected_paths = {
str(Path("src/subfile1.txt")),
str(Path("src/subfile2.py")),
str(Path("src/subdir/file_subdir.txt")),
str(Path("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