Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions codecov_cli/services/upload/file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@
class FileFinder(object):
def __init__(
self,
project_root: Path = None,
search_root: Path = None,
folders_to_ignore: typing.List[str] = None,
explicitly_listed_files: typing.List[Path] = None,
disable_search: bool = False,
report_type: str = "coverage",
):
self.project_root = project_root or Path(os.getcwd())
self.search_root = search_root or Path(os.getcwd())
self.folders_to_ignore = folders_to_ignore or []
self.explicitly_listed_files = explicitly_listed_files or None
self.disable_search = disable_search
Expand All @@ -207,7 +207,7 @@ def find_files(self) -> typing.List[UploadCollectionResultFile]:
if not self.disable_search:
regex_patterns_to_include = globs_to_regex(files_patterns)
files_paths = search_files(
self.project_root,
self.search_root,
default_folders_to_ignore + self.folders_to_ignore,
filename_include_regex=regex_patterns_to_include,
filename_exclude_regex=regex_patterns_to_exclude,
Expand Down Expand Up @@ -243,16 +243,17 @@ def get_user_specified_files(self, regex_patterns_to_exclude):
)
user_files_paths = list(
search_files(
self.project_root,
default_folders_to_ignore + self.folders_to_ignore,
self.search_root,
self.folders_to_ignore,
filename_include_regex=regex_patterns_to_include,
filename_exclude_regex=regex_patterns_to_exclude,
multipart_include_regex=multipart_include_regex,
)
)
not_found_files = []
user_files_paths_resolved = [path.resolve() for path in user_files_paths]
for filepath in self.explicitly_listed_files:
if filepath.resolve() not in user_files_paths:
if filepath.resolve() not in user_files_paths_resolved:
not_found_files.append(filepath)

if not_found_files:
Expand Down
41 changes: 41 additions & 0 deletions tests/services/upload/test_coverage_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ def test_find_coverage_files_with_existing_files(self):
self.project_root / "coverage.xml",
self.project_root / "subdirectory" / "test_coverage.xml",
self.project_root / "other_file.txt",
self.project_root / ".tox" / "another_file.abc",
]
(self.project_root / "subdirectory").mkdir()
(self.project_root / ".tox").mkdir()
for file in coverage_files:
file.touch()

Expand Down Expand Up @@ -208,8 +210,10 @@ def test_find_coverage_files_with_disabled_search(self):
self.project_root / "subdirectory" / "another_file.abc",
self.project_root / "subdirectory" / "test_coverage.xml",
self.project_root / "other_file.txt",
self.project_root / ".tox" / "another_file.abc",
]
(self.project_root / "subdirectory").mkdir()
(self.project_root / ".tox").mkdir()
for file in coverage_files:
file.touch()

Expand Down Expand Up @@ -237,8 +241,10 @@ def test_find_coverage_files_with_user_specified_files(self):
self.project_root / "subdirectory" / "test_coverage.xml",
self.project_root / "test_file.abc",
self.project_root / "subdirectory" / "another_file.abc",
self.project_root / ".tox" / "another_file.abc",
]
(self.project_root / "subdirectory").mkdir()
(self.project_root / ".tox").mkdir()
for file in coverage_files:
file.touch()

Expand All @@ -264,8 +270,10 @@ def test_find_coverage_files_with_user_specified_files_not_found(self):
coverage_files = [
self.project_root / "coverage.xml",
self.project_root / "subdirectory" / "test_coverage.xml",
self.project_root / ".tox" / "another_file.abc",
]
(self.project_root / "subdirectory").mkdir()
(self.project_root / ".tox").mkdir()
for file in coverage_files:
file.touch()

Expand All @@ -286,3 +294,36 @@ def test_find_coverage_files_with_user_specified_files_not_found(self):
]
expected_paths = sorted([file.get_filename() for file in expected])
self.assertEqual(result, expected_paths)

def test_find_coverage_files_with_user_specified_files_in_default_ignored_folder(self):
# Create some sample coverage files
coverage_files = [
self.project_root / "coverage.xml",
self.project_root / "subdirectory" / "test_coverage.xml",
self.project_root / "test_file.abc",
self.project_root / "subdirectory" / "another_file.abc",
self.project_root / ".tox" / "another_file.abc",
]
(self.project_root / "subdirectory").mkdir()
(self.project_root / ".tox").mkdir()
for file in coverage_files:
file.touch()

self.coverage_file_finder.explicitly_listed_files = [
self.project_root / ".tox" / "another_file.abc",
]
result = sorted(
[file.get_filename() for file in self.coverage_file_finder.find_files()]
)

expected = [
UploadCollectionResultFile(Path(f"{self.project_root}/coverage.xml")),
UploadCollectionResultFile(
Path(f"{self.project_root}/subdirectory/test_coverage.xml")
),
UploadCollectionResultFile(
Path(f"{self.project_root}/.tox/another_file.abc")
),
]
expected_paths = sorted([file.get_filename() for file in expected])
self.assertEqual(result, expected_paths)