Skip to content

Commit

Permalink
fix: directory as filename (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu-codecov authored Jan 17, 2025
1 parent 602ae3f commit d364161
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
14 changes: 9 additions & 5 deletions codecov_cli/services/upload/file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,15 @@ def find_files(self) -> List[UploadCollectionResultFile]:
filename_exclude_regex=regex_patterns_to_exclude,
)
result_files = [UploadCollectionResultFile(path) for path in files_paths]
user_result_files = [
UploadCollectionResultFile(path)
for path in user_files_paths
if user_files_paths
]

user_result_files = []
for path in user_files_paths:
if os.path.isfile(path):
user_result_files.append(UploadCollectionResultFile(path))
else:
logger.warning(
f"File \"{path}\" could not be found or does not exist. Please enter in the full path or from the search root \"{self.search_root}\"",
)

return list(set(result_files + user_result_files))

Expand Down
44 changes: 44 additions & 0 deletions tests/services/upload/test_coverage_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,50 @@ def test_find_coverage_files_with_existing_files(
expected_paths = sorted([file.get_filename() for file in expected])
assert result == expected_paths

def test_find_coverage_files_with_directory_named_as_file(
self, coverage_file_finder_fixture
):
# Create some sample coverage coverage_file_finder_fixture
(
project_root,
coverage_file_finder,
) = coverage_file_finder_fixture
coverage_files = [
project_root / "coverage.xml" / "coverage.xml",
]
(project_root / "coverage.xml").mkdir()
for file in coverage_files:
file.touch()

coverage_file_finder.explicitly_listed_files = [Path("coverage.xml/coverage.xml")]
result = sorted(
[file.get_filename() for file in coverage_file_finder.find_files()]
)
expected = [
UploadCollectionResultFile(Path(f"{project_root}/coverage.xml/coverage.xml")),
]
expected_paths = sorted([file.get_filename() for file in expected])
assert result == expected_paths

coverage_file_finder.explicitly_listed_files = [Path("coverage.xml")]
result = sorted(
[file.get_filename() for file in coverage_file_finder.find_files()]
)
expected = [
UploadCollectionResultFile(Path(f"{project_root}/coverage.xml/coverage.xml")),
]
expected_paths = sorted([file.get_filename() for file in expected])
assert result == expected_paths

coverage_file_finder.explicitly_listed_files = [Path("coverage.xml")]
coverage_file_finder.disable_search = True
result = sorted(
[file.get_filename() for file in coverage_file_finder.find_files()]
)
expected = []
expected_paths = sorted([file.get_filename() for file in expected])
assert result == expected_paths

def test_find_coverage_files_with_file_in_parent(
self, coverage_file_finder_fixture
):
Expand Down

0 comments on commit d364161

Please sign in to comment.