From 838b202122c4d75ade9f9a201db8a002c7bb4f05 Mon Sep 17 00:00:00 2001 From: Dana Date: Thu, 5 Oct 2023 17:35:19 +0300 Subject: [PATCH] disable file fixes --- codecov_cli/commands/upload.py | 9 +++++++++ codecov_cli/commands/upload_process.py | 3 +++ codecov_cli/services/upload/__init__.py | 3 ++- codecov_cli/services/upload/upload_collector.py | 4 +++- tests/commands/test_invoke_upload_process.py | 2 ++ tests/services/upload/test_upload_collector.py | 11 +++++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/codecov_cli/commands/upload.py b/codecov_cli/commands/upload.py index 28bc0fa3..cf6a4b1b 100644 --- a/codecov_cli/commands/upload.py +++ b/codecov_cli/commands/upload.py @@ -65,6 +65,12 @@ def _turn_env_vars_into_dict(ctx, params, value): is_flag=True, default=False, ), + click.option( + "--disable-file-fixes", + help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)", + is_flag=True, + default=False, + ), click.option( "-b", "--build", @@ -178,6 +184,7 @@ def do_upload( coverage_files_search_exclude_folders: typing.List[pathlib.Path], coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path], disable_search: bool, + disable_file_fixes: bool, token: typing.Optional[uuid.UUID], plugin_names: typing.List[str], branch: typing.Optional[str], @@ -218,6 +225,7 @@ def do_upload( git_service=git_service, enterprise_url=enterprise_url, disable_search=disable_search, + disable_file_fixes=disable_file_fixes, handle_no_reports_found=handle_no_reports_found, ) ), @@ -254,4 +262,5 @@ def do_upload( enterprise_url=enterprise_url, disable_search=disable_search, handle_no_reports_found=handle_no_reports_found, + disable_file_fixes=disable_file_fixes, ) diff --git a/codecov_cli/commands/upload_process.py b/codecov_cli/commands/upload_process.py index df355ae9..67fd14da 100644 --- a/codecov_cli/commands/upload_process.py +++ b/codecov_cli/commands/upload_process.py @@ -37,6 +37,7 @@ def upload_process( coverage_files_search_exclude_folders: typing.List[pathlib.Path], coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path], disable_search: bool, + disable_file_fixes: bool, token: typing.Optional[uuid.UUID], plugin_names: typing.List[str], branch: typing.Optional[str], @@ -72,6 +73,7 @@ def upload_process( pull_request_number=pull_request_number, git_service=git_service, disable_search=disable_search, + disable_file_fixes=disable_file_fixes, fail_on_error=fail_on_error, handle_no_reports_found=handle_no_reports_found, ) @@ -123,4 +125,5 @@ def upload_process( dry_run=dry_run, git_service=git_service, handle_no_reports_found=handle_no_reports_found, + disable_file_fixes=disable_file_fixes, ) diff --git a/codecov_cli/services/upload/__init__.py b/codecov_cli/services/upload/__init__.py index 52cfdca6..959d6ed9 100644 --- a/codecov_cli/services/upload/__init__.py +++ b/codecov_cli/services/upload/__init__.py @@ -50,6 +50,7 @@ def do_upload_logic( enterprise_url: typing.Optional[str], disable_search: bool = False, handle_no_reports_found: bool = False, + disable_file_fixes: bool = False, ): preparation_plugins = select_preparation_plugins(cli_config, plugin_names) coverage_file_selector = select_coverage_file_finder( @@ -60,7 +61,7 @@ def do_upload_logic( ) network_finder = select_network_finder(versioning_system) collector = UploadCollector( - preparation_plugins, network_finder, coverage_file_selector + preparation_plugins, network_finder, coverage_file_selector, disable_file_fixes ) try: upload_data = collector.generate_upload_data() diff --git a/codecov_cli/services/upload/upload_collector.py b/codecov_cli/services/upload/upload_collector.py index 61c24e25..d30e036e 100644 --- a/codecov_cli/services/upload/upload_collector.py +++ b/codecov_cli/services/upload/upload_collector.py @@ -29,15 +29,17 @@ def __init__( preparation_plugins: typing.List[PreparationPluginInterface], network_finder: NetworkFinder, coverage_file_finder: CoverageFileFinder, + disable_file_fixes: bool = False, ): self.preparation_plugins = preparation_plugins self.network_finder = network_finder self.coverage_file_finder = coverage_file_finder + self.disable_file_fixes = disable_file_fixes def _produce_file_fixes_for_network( self, network: typing.List[str] ) -> typing.List[UploadCollectionResultFileFixer]: - if not network: + if not network or self.disable_file_fixes: return [] # patterns that we don't need to specify a reason for empty_line_regex = re.compile(r"^\s*$") diff --git a/tests/commands/test_invoke_upload_process.py b/tests/commands/test_invoke_upload_process.py index 37cfc795..026c128d 100644 --- a/tests/commands/test_invoke_upload_process.py +++ b/tests/commands/test_invoke_upload_process.py @@ -92,6 +92,8 @@ def test_upload_process_options(mocker): " --disable-search Disable search for coverage files. This is", " helpful when specifying what files you want to", " uload with the --file option.", + " --disable-file-fixes Disable file fixes to ignore common lines from", + " coverage (e.g. blank lines or empty brackets)", " -b, --build, --build-code TEXT Specify the build number manually", " --build-url TEXT The URL of the build where this is running", " --job-code TEXT", diff --git a/tests/services/upload/test_upload_collector.py b/tests/services/upload/test_upload_collector.py index 4e08a9eb..15279275 100644 --- a/tests/services/upload/test_upload_collector.py +++ b/tests/services/upload/test_upload_collector.py @@ -98,3 +98,14 @@ def test_fix_for_cpp_swift_vala(tmp_path): (7, "// LCOV_EXCL_START\n"), ] ) + + +def test_fix_when_disabled_fixes(tmp_path): + cpp_file = Path("tests/data/files_to_fix_examples/sample.cpp") + + col = UploadCollector(None, None, None, True) + + fixes = col._produce_file_fixes_for_network([str(cpp_file)]) + + assert len(fixes) == 0 + assert fixes == []