From 374cbaca611cc397022a29a6d98c53a1e3c66679 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 25 Mar 2025 12:06:49 +0100 Subject: [PATCH 1/3] Test on all OSs This adds Windows and MacOS to our CI test matrix. --- .github/workflows/ci.yml | 16 ++-- codecov_cli/helpers/folder_searcher.py | 9 +- codecov_cli/helpers/versioning_systems.py | 74 +++++++++------- codecov_cli/plugins/xcode.py | 44 +++++----- codecov_cli/services/upload/upload_sender.py | 2 +- tests/helpers/test_args.py | 6 +- tests/helpers/test_folder_searcher.py | 86 +++++++++---------- tests/plugins/test_xcode.py | 2 +- .../static_analysis/test_analyse_file.py | 2 +- 9 files changed, 126 insertions(+), 115 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 672b2a2ba..92e341022 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,16 +70,12 @@ jobs: codecovcli create-report -t ${{ secrets.CODECOV_TOKEN }} --git-service github build-test-upload: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - include: - - python-version: "3.13" - - python-version: "3.12" - - python-version: "3.11" - - python-version: "3.10" - - python-version: "3.9" + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: ["3.13", "3.12", "3.11", "3.10", "3.9"] + runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v4 with: @@ -97,7 +93,7 @@ jobs: pip install -r tests/requirements.txt - name: Test with pytest run: | - pytest --cov --junitxml=${{matrix.python-version}}junit.xml + pytest --cov --junitxml=${{matrix.os}}-${{matrix.python-version}}junit.xml env: CODECOV_ENV: test - name: Dogfooding codecov-cli @@ -109,8 +105,8 @@ jobs: if: ${{ !cancelled() }} uses: actions/upload-artifact@v4 with: - name: ${{matrix.python-version}}junit.xml - path: ${{matrix.python-version}}junit.xml + name: ${{matrix.os}}-${{matrix.python-version}}junit.xml + path: ${{matrix.os}}-${{matrix.python-version}}junit.xml process-test-results: if: ${{ always() }} diff --git a/codecov_cli/helpers/folder_searcher.py b/codecov_cli/helpers/folder_searcher.py index 31f0af800..8b7f35dfa 100644 --- a/codecov_cli/helpers/folder_searcher.py +++ b/codecov_cli/helpers/folder_searcher.py @@ -17,7 +17,7 @@ def _is_included( ): return filename_include_regex.match(path.name) and ( multipart_include_regex is None - or multipart_include_regex.match(str(path.resolve())) + or multipart_include_regex.match(path.resolve().as_posix()) ) @@ -29,7 +29,8 @@ def _is_excluded( return ( filename_exclude_regex is not None and filename_exclude_regex.match(path.name) ) or ( - multipart_exclude_regex is not None and multipart_exclude_regex.match(str(path)) + multipart_exclude_regex is not None + and multipart_exclude_regex.match(path.as_posix()) ) @@ -69,7 +70,9 @@ def search_files( dirs_to_remove.union( directory for directory in dirnames - if multipart_exclude_regex.match(str(pathlib.Path(dirpath) / directory)) + if multipart_exclude_regex.match( + (pathlib.Path(dirpath) / directory).as_posix() + ) ) for directory in dirs_to_remove: diff --git a/codecov_cli/helpers/versioning_systems.py b/codecov_cli/helpers/versioning_systems.py index c4e44cc80..ff31c0506 100644 --- a/codecov_cli/helpers/versioning_systems.py +++ b/codecov_cli/helpers/versioning_systems.py @@ -12,38 +12,38 @@ logger = logging.getLogger("codecovcli") IGNORE_DIRS = [ - '*.egg-info', - '.DS_Store', - '.circleci', - '.env', - '.envs', - '.git', - '.gitignore', - '.mypy_cache', - '.nvmrc', - '.nyc_output', - '.ruff_cache', - '.venv', - '.venvns', - '.virtualenv', - '.virtualenvs', - '__pycache__', - 'bower_components', - 'build/lib/', - 'jspm_packages', - 'node_modules', - 'vendor', - 'virtualenv', - 'virtualenvs', + "*.egg-info", + ".DS_Store", + ".circleci", + ".env", + ".envs", + ".git", + ".gitignore", + ".mypy_cache", + ".nvmrc", + ".nyc_output", + ".ruff_cache", + ".venv", + ".venvns", + ".virtualenv", + ".virtualenvs", + "__pycache__", + "bower_components", + "build/lib/", + "jspm_packages", + "node_modules", + "vendor", + "virtualenv", + "virtualenvs", ] IGNORE_PATHS = [ - '*.gif', - '*.jpeg', - '*.jpg', - '*.md', - '*.png', - 'shunit2*', + "*.gif", + "*.jpeg", + "*.jpg", + "*.md", + "*.png", + "shunit2*", ] @@ -203,12 +203,20 @@ def list_relevant_files( cmd = [ "find", - dir_to_use, - *chain.from_iterable(["-name", block, "-prune", "-o"] for block in IGNORE_DIRS), - *chain.from_iterable(["-path", block, "-prune", "-o"] for block in IGNORE_PATHS), + str(dir_to_use), + *chain.from_iterable( + ["-name", block, "-prune", "-o"] for block in IGNORE_DIRS + ), + *chain.from_iterable( + ["-path", block, "-prune", "-o"] for block in IGNORE_PATHS + ), "-type", "f", "-print", ] res = subprocess.run(cmd, capture_output=True) - return [filename for filename in res.stdout.decode("unicode_escape").strip().split("\n") if filename] + return [ + filename + for filename in res.stdout.decode("unicode_escape").strip().split("\n") + if filename + ] diff --git a/codecov_cli/plugins/xcode.py b/codecov_cli/plugins/xcode.py index 417511a6e..6bf60e980 100644 --- a/codecov_cli/plugins/xcode.py +++ b/codecov_cli/plugins/xcode.py @@ -42,21 +42,25 @@ def run_preparation(self, collector) -> PreparationPluginReturn: filename_include_regex = globs_to_regex(["*.profdata"]) - matched_paths = [ - str(path) - for path in search_files( + matched_paths = list( + search_files( folder_to_search=self.derived_data_folder, folders_to_ignore=[], filename_include_regex=filename_include_regex, ) - ] + ) + if not matched_paths: logger.warning("No swift data found.") return logger.info( "Running swift coverage on the following list of files:", - extra=dict(extra_log_attributes=dict(matched_paths=matched_paths)), + extra=dict( + extra_log_attributes=dict( + matched_paths=[p.as_posix() for p in matched_paths] + ) + ), ) for path in matched_paths: @@ -64,36 +68,36 @@ def run_preparation(self, collector) -> PreparationPluginReturn: return PreparationPluginReturn(success=True, messages="") - def swiftcov(self, path, app_name: str): + def swiftcov(self, path: pathlib.Path, app_name: str) -> None: directory = os.path.dirname(path) build_dir = pathlib.Path(re.sub("(Build).*", "Build", directory)) for type in ["app", "framework", "xctest"]: filename_include_regex = re.compile(translate(f"*.{type}")) - matched_dir_paths = [ - str(path) - for path in search_files( - folder_to_search=pathlib.Path(build_dir), - folders_to_ignore=[], - filename_include_regex=filename_include_regex, - search_for_directories=True, - ) - ] + matched_dir_paths = search_files( + folder_to_search=build_dir, + folders_to_ignore=[], + filename_include_regex=filename_include_regex, + search_for_directories=True, + ) + for dir_path in matched_dir_paths: # proj name without extension - proj = pathlib.Path(dir_path).stem + proj = dir_path.stem if app_name == "" or (app_name.lower() in proj.lower()): logger.info(f"+ Building reports for {proj} {type}") - proj_path = pathlib.Path(pathlib.Path(dir_path) / proj) + proj_path = dir_path / proj dest = ( proj_path if proj_path.is_file() - else pathlib.Path(f"{dir_path}/Contents/MacOS/{proj}") + else dir_path / "Contents/MacOS/{proj}" ) output_file_name = f"{proj}.{type}.coverage.txt".replace(" ", "") self.run_llvm_cov(output_file_name, path, dest) - def run_llvm_cov(self, output_file_name, path, dest): + def run_llvm_cov( + self, output_file_name: str, path: pathlib.Path, dest: pathlib.Path + ) -> None: with open(output_file_name, "w") as output_file: s = subprocess.run( [ @@ -101,7 +105,7 @@ def run_llvm_cov(self, output_file_name, path, dest): "llvm-cov", "show", "-instr-profile", - path, + str(path), str(dest), ], stdout=output_file, diff --git a/codecov_cli/services/upload/upload_sender.py b/codecov_cli/services/upload/upload_sender.py index 450f68385..a02ee2091 100644 --- a/codecov_cli/services/upload/upload_sender.py +++ b/codecov_cli/services/upload/upload_sender.py @@ -176,7 +176,7 @@ def _get_file_fixers( total_fixed_lines = list( file_fixer.fixed_lines_without_reason.union(fixed_lines_with_reason) ) - file_fixers[str(file_fixer.path)] = { + file_fixers[file_fixer.path.as_posix()] = { "eof": file_fixer.eof, "lines": total_fixed_lines, } diff --git a/tests/helpers/test_args.py b/tests/helpers/test_args.py index 503b877ef..08cceb735 100644 --- a/tests/helpers/test_args.py +++ b/tests/helpers/test_args.py @@ -1,7 +1,8 @@ import os -from pathlib import PosixPath +import sys import click +import pytest from codecov_cli import __version__ from codecov_cli.helpers.args import get_cli_args @@ -28,7 +29,10 @@ def test_get_cli_args(): assert get_cli_args(ctx) == expected +@pytest.mark.skipif(sys.platform == "win32", reason="requires posix platform") def test_get_cli_args_with_posix(): + from pathlib import PosixPath + ctx = click.Context(click.Command("do-upload")) ctx.obj = {} ctx.obj["cli_args"] = { diff --git a/tests/helpers/test_folder_searcher.py b/tests/helpers/test_folder_searcher.py index a6ab98951..59eeef9dc 100644 --- a/tests/helpers/test_folder_searcher.py +++ b/tests/helpers/test_folder_searcher.py @@ -18,7 +18,12 @@ def test_search_files(tmp_path): relevant_filepath = tmp_path / f relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( + + assert sorted( + search_files( + tmp_path, [], filename_include_regex=search_for, filename_exclude_regex=None + ) + ) == sorted( [ tmp_path / "banana.txt", tmp_path / "banana.py", @@ -26,11 +31,6 @@ def test_search_files(tmp_path): tmp_path / "path/to/banana.c", ] ) - assert expected_results == sorted( - search_files( - tmp_path, [], filename_include_regex=search_for, filename_exclude_regex=None - ) - ) def test_search_files_with_folder_exclusion(tmp_path): @@ -51,7 +51,15 @@ def test_search_files_with_folder_exclusion(tmp_path): relevant_filepath = tmp_path / f relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( + + assert sorted( + search_files( + tmp_path, + ["to"], + filename_include_regex=search_for, + filename_exclude_regex=None, + ) + ) == sorted( [ tmp_path / "banana.txt", tmp_path / "banana.py", @@ -60,14 +68,6 @@ def test_search_files_with_folder_exclusion(tmp_path): tmp_path / "path/folder with space/banana.py", ] ) - assert expected_results == sorted( - search_files( - tmp_path, - ["to"], - filename_include_regex=search_for, - filename_exclude_regex=None, - ) - ) def test_search_files_combined_regex(tmp_path): @@ -83,7 +83,12 @@ def test_search_files_combined_regex(tmp_path): relevant_filepath = tmp_path / f relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( + + assert sorted( + search_files( + tmp_path, [], filename_include_regex=search_for, filename_exclude_regex=None + ) + ) == sorted( [ tmp_path / "banana.txt", tmp_path / "banana.py", @@ -92,11 +97,6 @@ def test_search_files_combined_regex(tmp_path): tmp_path / "path/to/banana.c", ] ) - assert expected_results == sorted( - search_files( - tmp_path, [], filename_include_regex=search_for, filename_exclude_regex=None - ) - ) def test_search_files_with_exclude_regex(tmp_path): @@ -112,15 +112,15 @@ def test_search_files_with_exclude_regex(tmp_path): relevant_filepath = tmp_path / f relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted([tmp_path / "banana.txt", tmp_path / "path/to/banana.c"]) - assert expected_results == sorted( + + assert sorted( search_files( tmp_path, [], filename_include_regex=search_for, filename_exclude_regex=re.compile(r".*\.py"), ) - ) + ) == sorted([tmp_path / "banana.txt", tmp_path / "path/to/banana.c"]) def test_search_files_with_multipart_excluded_regex_with_filename(tmp_path): @@ -137,10 +137,7 @@ def test_search_files_with_multipart_excluded_regex_with_filename(tmp_path): relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( - [tmp_path / "report.xml", tmp_path / "path/to/report.xml"] - ) - assert expected_results == sorted( + assert sorted( search_files( tmp_path, [], @@ -148,7 +145,7 @@ def test_search_files_with_multipart_excluded_regex_with_filename(tmp_path): filename_exclude_regex=None, multipart_exclude_regex=multipart_exclude_regex, ) - ) + ) == sorted([tmp_path / "report.xml", tmp_path / "path/to/report.xml"]) def test_search_files_with_multipart_excluded_regex_with_foldername(tmp_path): @@ -167,14 +164,7 @@ def test_search_files_with_multipart_excluded_regex_with_foldername(tmp_path): relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( - [ - tmp_path / "report.xml", - tmp_path / "path/to/report.xml", - tmp_path / "js/generated/report.xml", - ] - ) - assert expected_results == sorted( + assert sorted( search_files( tmp_path, [], @@ -182,6 +172,12 @@ def test_search_files_with_multipart_excluded_regex_with_foldername(tmp_path): filename_exclude_regex=None, multipart_exclude_regex=multipart_exclude_regex, ) + ) == sorted( + [ + tmp_path / "report.xml", + tmp_path / "path/to/report.xml", + tmp_path / "js/generated/report.xml", + ] ) @@ -269,14 +265,8 @@ def test_search_directories(tmp_path): relevant_filepath = tmp_path / f relevant_filepath.parent.mkdir(parents=True, exist_ok=True) relevant_filepath.touch() - expected_results = sorted( - [ - tmp_path / "banana.app", - tmp_path / "path/to/banana.app", - tmp_path / "path/to/apple.app", - ] - ) - assert expected_results == sorted( + + assert sorted( search_files( tmp_path, [], @@ -284,4 +274,10 @@ def test_search_directories(tmp_path): filename_exclude_regex=None, search_for_directories=True, ) + ) == sorted( + [ + tmp_path / "banana.app", + tmp_path / "path/to/banana.app", + tmp_path / "path/to/apple.app", + ] ) diff --git a/tests/plugins/test_xcode.py b/tests/plugins/test_xcode.py index 89cbde779..ec5ebb0ee 100644 --- a/tests/plugins/test_xcode.py +++ b/tests/plugins/test_xcode.py @@ -48,7 +48,7 @@ def test_swift_data_found(self, mocker, tmp_path, capsys): expected = ( "info", 'Running swift coverage on the following list of files: --- {"matched_paths": ["' - + f"{dir}/cov_data.profdata" + + f"{dir.as_posix()}/cov_data.profdata" + '"]}', ) assert expected in output diff --git a/tests/services/static_analysis/test_analyse_file.py b/tests/services/static_analysis/test_analyse_file.py index 43269b16c..8f509c1bc 100644 --- a/tests/services/static_analysis/test_analyse_file.py +++ b/tests/services/static_analysis/test_analyse_file.py @@ -24,7 +24,7 @@ def test_sample_analysis(input_filename, output_filename): config = {} res = analyze_file( - config, FileAnalysisRequest(Path(input_filename), Path(input_filename)) + config, FileAnalysisRequest(input_filename, Path(input_filename)) ) with open(output_filename, "r") as file: expected_result = json.load(file) From d71097796e8da3cd6cefda96ec3c1bf8aba68ce6 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 25 Mar 2025 13:43:45 +0100 Subject: [PATCH 2/3] skip more tests and use `as_posix` in more places --- codecov_cli/commands/process_test_results.py | 2 +- .../services/upload/legacy_upload_sender.py | 2 +- codecov_cli/services/upload/upload_sender.py | 2 +- codecov_cli/types.py | 4 ++-- tests/helpers/test_legacy_upload_sender.py | 6 ++--- tests/helpers/test_upload_sender.py | 8 +++---- .../static_analysis/test_analyse_file.py | 4 ++++ .../services/upload/test_upload_collector.py | 22 +++++++++++-------- tests/test_types.py | 4 ++-- 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/codecov_cli/commands/process_test_results.py b/codecov_cli/commands/process_test_results.py index 0c903ea37..c0b52bb4d 100644 --- a/codecov_cli/commands/process_test_results.py +++ b/codecov_cli/commands/process_test_results.py @@ -268,6 +268,6 @@ def generate_message_payload( payload.passed += 1 except ParserError as err: raise click.ClickException( - f"Error parsing {str(result.get_filename(), 'utf8')} with error: {err}" + f"Error parsing {result.get_filename()} with error: {err}" ) return payload diff --git a/codecov_cli/services/upload/legacy_upload_sender.py b/codecov_cli/services/upload/legacy_upload_sender.py index a1d65c6b1..9f311e636 100644 --- a/codecov_cli/services/upload/legacy_upload_sender.py +++ b/codecov_cli/services/upload/legacy_upload_sender.py @@ -125,7 +125,7 @@ def _generate_coverage_files_section(self, upload_data: UploadCollectionResult): return b"".join(self._format_coverage_file(file) for file in upload_data.files) def _format_coverage_file(self, file: UploadCollectionResultFile) -> bytes: - header = b"# path=" + file.get_filename() + b"\n" + header = b"# path=" + file.get_filename().encode() + b"\n" file_content = file.get_content() + b"\n" file_end = b"<<<<<< EOF\n" diff --git a/codecov_cli/services/upload/upload_sender.py b/codecov_cli/services/upload/upload_sender.py index a02ee2091..8454fed11 100644 --- a/codecov_cli/services/upload/upload_sender.py +++ b/codecov_cli/services/upload/upload_sender.py @@ -189,7 +189,7 @@ def _get_files(self, upload_data: UploadCollectionResult): def _format_file(self, file: UploadCollectionResultFile): format, formatted_content = self._get_format_info(file) return { - "filename": file.get_filename().decode(), + "filename": file.get_filename(), "format": format, "data": formatted_content, "labels": "", diff --git a/codecov_cli/types.py b/codecov_cli/types.py index 4050c47e7..2ca6f391b 100644 --- a/codecov_cli/types.py +++ b/codecov_cli/types.py @@ -23,8 +23,8 @@ class UploadCollectionResultFile(object): def __init__(self, path: pathlib.Path): self.path = path - def get_filename(self) -> bytes: - return bytes(self.path) + def get_filename(self) -> str: + return self.path.as_posix() def get_content(self) -> bytes: with open(self.path, "rb") as f: diff --git a/tests/helpers/test_legacy_upload_sender.py b/tests/helpers/test_legacy_upload_sender.py index beb4c79ce..f218199a4 100644 --- a/tests/helpers/test_legacy_upload_sender.py +++ b/tests/helpers/test_legacy_upload_sender.py @@ -267,9 +267,9 @@ def test_format_coverage_file(self, mocker): b"\n", 1 ) - fake_result_file.get_filename.return_value = coverage_file_seperated[0][ - len(b"# path=") : - ].strip() + fake_result_file.get_filename.return_value = ( + coverage_file_seperated[0][len(b"# path=") :].strip().decode() + ) fake_result_file.get_content.return_value = coverage_file_seperated[1][ : -len(b"\n<<<<<< EOF\n") ] diff --git a/tests/helpers/test_upload_sender.py b/tests/helpers/test_upload_sender.py index 0d7863223..f04eb77a6 100644 --- a/tests/helpers/test_upload_sender.py +++ b/tests/helpers/test_upload_sender.py @@ -142,9 +142,9 @@ def mocked_coverage_file(mocker): coverage_file_seperated = reports_examples.coverage_file_section_simple.split( b"\n", 1 ) - fake_result_file.get_filename.return_value = coverage_file_seperated[0][ - len(b"# path=") : - ].strip() + fake_result_file.get_filename.return_value = ( + coverage_file_seperated[0][len(b"# path=") :].strip().decode() + ) fake_result_file.get_content.return_value = coverage_file_seperated[1][ : -len(b"\n<<<<<< EOF\n") ] @@ -564,7 +564,7 @@ def test_coverage_file_format(self, mocker, mocked_coverage_file): json_formatted_coverage_file = UploadSender()._format_file(mocked_coverage_file) print(json_formatted_coverage_file["data"]) assert json_formatted_coverage_file == { - "filename": mocked_coverage_file.get_filename().decode(), + "filename": mocked_coverage_file.get_filename(), "format": "base64+compressed", "data": "encoded_file_data", "labels": "", diff --git a/tests/services/static_analysis/test_analyse_file.py b/tests/services/static_analysis/test_analyse_file.py index 8f509c1bc..9d4ad7494 100644 --- a/tests/services/static_analysis/test_analyse_file.py +++ b/tests/services/static_analysis/test_analyse_file.py @@ -1,4 +1,5 @@ import json +import sys from pathlib import Path from unittest.mock import MagicMock, patch @@ -21,6 +22,9 @@ ("samples/inputs/sample_005.py", "samples/outputs/sample_005.json"), ], ) +@pytest.mark.skipif( + sys.platform == "win32", reason="windows is producing different `code_hash` values" +) def test_sample_analysis(input_filename, output_filename): config = {} res = analyze_file( diff --git a/tests/services/upload/test_upload_collector.py b/tests/services/upload/test_upload_collector.py index 5e383e9f8..1d57b3972 100644 --- a/tests/services/upload/test_upload_collector.py +++ b/tests/services/upload/test_upload_collector.py @@ -1,5 +1,7 @@ from pathlib import Path from unittest.mock import patch +import pytest +import sys from codecov_cli.helpers.versioning_systems import ( GitVersioningSystem, @@ -180,10 +182,11 @@ def test_generate_upload_data(tmp_path): @patch("codecov_cli.services.upload.upload_collector.logger") -@patch.object(GitVersioningSystem, "get_network_root", return_value=None) -def test_generate_upload_data_with_none_network( - mock_get_network_root, mock_logger, tmp_path -): +@pytest.mark.skipif( + sys.platform == "win32", + reason="the fallback `list_relevant_files` is currently broken on windows", +) +def test_generate_upload_data_with_none_network(mock_logger, tmp_path): (tmp_path / "coverage.xml").touch() file_finder = FileFinder(tmp_path) @@ -202,11 +205,12 @@ def test_generate_upload_data_with_none_network( assert len(res.files) == 1 assert len(res.file_fixes) > 1 -@patch("codecov_cli.services.upload.upload_collector.logger") -@patch.object(GitVersioningSystem, "get_network_root", return_value=None) -def test_generate_network_with_no_versioning_system( - mock_get_network_root, mock_logger, tmp_path -): + +@pytest.mark.skipif( + sys.platform == "win32", + reason="the fallback `list_relevant_files` is currently broken on windows", +) +def test_generate_network_with_no_versioning_system(tmp_path): versioning_system = NoVersioningSystem() found_files = versioning_system.list_relevant_files() assert len(found_files) > 1 diff --git a/tests/test_types.py b/tests/test_types.py index d6000b154..9b1eda485 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -5,11 +5,11 @@ class TestUploadCollectionResultFile(object): def test_get_file_name(self, tmp_path): filename = "a.txt" path = tmp_path / filename - assert UploadCollectionResultFile(path).get_filename() == bytes(path) + assert UploadCollectionResultFile(path).get_filename() == path.as_posix() filename = "sub/a.txt" path = tmp_path / filename - assert UploadCollectionResultFile(path).get_filename() == bytes(path) + assert UploadCollectionResultFile(path).get_filename() == path.as_posix() def test_get_content(self, tmp_path): content = b"first line\nsecondline\nlastline\n" From 7b6ad1a6f04f1225034a955c63ec02b6c01d452f Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 26 Mar 2025 17:38:24 +0100 Subject: [PATCH 3/3] use as_posix in more places --- codecov_cli/services/upload/file_finder.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/codecov_cli/services/upload/file_finder.py b/codecov_cli/services/upload/file_finder.py index 156f36599..54386e89e 100644 --- a/codecov_cli/services/upload/file_finder.py +++ b/codecov_cli/services/upload/file_finder.py @@ -197,8 +197,10 @@ def __init__( report_type: ReportType = ReportType.COVERAGE, ): self.search_root = search_root or Path(os.getcwd()) - self.folders_to_ignore = list(folders_to_ignore) if folders_to_ignore else [] - self.explicitly_listed_files = explicitly_listed_files or None + self.folders_to_ignore = ( + [f.as_posix() for f in folders_to_ignore] if folders_to_ignore else [] + ) + self.explicitly_listed_files = explicitly_listed_files or [] self.disable_search = disable_search self.report_type: ReportType = report_type @@ -223,8 +225,7 @@ def find_files(self) -> List[UploadCollectionResultFile]: assert regex_patterns_to_include # this is never `None` files_paths = search_files( self.search_root, - default_folders_to_ignore - + [str(folder) for folder in self.folders_to_ignore], + default_folders_to_ignore + self.folders_to_ignore, filename_include_regex=regex_patterns_to_include, filename_exclude_regex=regex_patterns_to_exclude, ) @@ -252,7 +253,7 @@ def get_user_specified_files(self, regex_patterns_to_exclude: Pattern): for file in self.explicitly_listed_files: user_filenames_to_include.append(file.name) if regex_patterns_to_exclude.match(file.name): - files_excluded_but_user_includes.append(str(file)) + files_excluded_but_user_includes.append(file.as_posix()) if files_excluded_but_user_includes: logger.warning( "Some files being explicitly added are found in the list of excluded files for upload. We are still going to search for the explicitly added files.", @@ -262,7 +263,7 @@ def get_user_specified_files(self, regex_patterns_to_exclude: Pattern): ) regex_patterns_to_include = globs_to_regex(user_filenames_to_include) multipart_include_regex = globs_to_regex( - [str(path.resolve()) for path in self.explicitly_listed_files] + [path.resolve().as_posix() for path in self.explicitly_listed_files] ) user_files_paths = list( search_files(