Skip to content

Commit

Permalink
chore: address linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry committed Nov 25, 2024
1 parent b652389 commit 5c7a891
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 65 deletions.
8 changes: 4 additions & 4 deletions codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ def _dry_run_list_output(
logger.warning(f"label-analysis didn't run correctly. Error: {fallback_reason}")

to_run_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_run))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_run))
)
to_skip_line = " ".join(
sorted(map(lambda l: f"'{l}'", runner_options))
+ sorted(map(lambda l: f"'{l}'", labels_to_skip))
sorted(map(lambda option: f"'{option}'", runner_options))
+ sorted(map(lambda label: f"'{label}'", labels_to_skip))
)
# ⚠️ DON'T use logger
# logger goes to stderr, we want it in stdout
Expand Down
4 changes: 2 additions & 2 deletions codecov_cli/helpers/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def get_cli_args(ctx: click.Context):
filtered_args = {}
for k in args.keys():
try:
if type(args[k]) == PosixPath:
if isinstance(args[k], PosixPath):
filtered_args[k] = str(args[k])
else:
json.dumps(args[k])
filtered_args[k] = args[k]
except Exception as e:
except Exception:
continue

return filtered_args
2 changes: 1 addition & 1 deletion codecov_cli/helpers/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def wrapper(*args, **kwargs):
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
RetryException,
) as exp:
):
logger.warning(
"Request failed. Retrying",
extra=dict(extra_log_attributes=dict(retry=retry)),
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/runners/dan_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def process_labelanalysis_result(self, result: LabelAnalysisRequestResult):
"DAN runner missing 'process_labelanalysis_result_command' configuration value"
)
command_list = []
if type(command) == list:
if isinstance(command, list):
command_list.extend(command)
else:
command_list.append(command)
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/services/staticanalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def run_analysis_entrypoint(
failed_uploads = []
with click.progressbar(
length=len(files_that_need_upload),
label=f"Upload info to storage",
label="Upload info to storage",
) as bar:
# It's better to have less files competing over CPU time when uploading
# Especially if we might have large files
Expand Down
2 changes: 1 addition & 1 deletion codecov_cli/services/upload/upload_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _get_file_fixes(
reason=err.reason,
),
)
except IsADirectoryError as err:
except IsADirectoryError as _:
logger.info(f"Skipping {filename}, found a directory not a file")

return UploadCollectionResultFileFixer(
Expand Down
2 changes: 1 addition & 1 deletion tests/ci_adapters/test_circleci.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_branch(self, env_dict, expected, mocker):
assert actual == expected

def test_raises_value_error_if_invalid_field(self):
with pytest.raises(ValueError) as ex:
with pytest.raises(ValueError) as _:
CircleCICIAdapter().get_fallback_value("some random key x 123")

def test_service(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/ci_adapters/test_herokuci.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_branch(self, env_dict, expected, mocker):
assert actual == expected

def test_raises_value_error_if_invalid_field(self):
with pytest.raises(ValueError) as ex:
with pytest.raises(ValueError) as _:
HerokuCIAdapter().get_fallback_value("some_random_key")

def test_service(self):
Expand All @@ -82,7 +82,7 @@ def test_service(self):
)

def test_other_values_fallback_to_none(self):
assert HerokuCIAdapter()._get_slug() == None
assert HerokuCIAdapter()._get_build_url() == None
assert HerokuCIAdapter()._get_job_code() == None
assert HerokuCIAdapter()._get_pull_request_number() == None
assert HerokuCIAdapter()._get_slug() is None
assert HerokuCIAdapter()._get_build_url() is None
assert HerokuCIAdapter()._get_job_code() is None
assert HerokuCIAdapter()._get_pull_request_number() is None
17 changes: 3 additions & 14 deletions tests/ci_adapters/test_jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ def test_detect(self, env_dict, expected, mocker):
actual = JenkinsAdapter().detect()
assert actual == expected

@pytest.mark.parametrize(
"env_dict,expected",
[
({}, None),
({JenkinsCIEnvEnum.BUILD_URL: "url"}, "url"),
],
)
def test_build_url(self, env_dict, expected, mocker):
mocker.patch.dict(os.environ, env_dict)
actual = JenkinsAdapter().get_fallback_value(FallbackFieldEnum.build_url)
assert actual == expected

@pytest.mark.parametrize(
"env_dict,expected",
Expand Down Expand Up @@ -99,6 +88,6 @@ def test_service(self):
)

def test_none_values(self):
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.slug) == None
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.commit_sha) == None
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.job_code) == None
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.slug) is None
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.commit_sha) is None
JenkinsAdapter().get_fallback_value(FallbackFieldEnum.job_code) is None
2 changes: 1 addition & 1 deletion tests/ci_adapters/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_detect_git_not_installed(self, mocker):
"codecov_cli.helpers.ci_adapters.local.subprocess.run",
return_value=mocker.MagicMock(returncode=1),
)
assert LocalAdapter().detect() == False
assert not LocalAdapter().detect()
mocked_subprocess.assert_called_once()

@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/commands/test_invoke_labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_invoke_label_analysis(
):
mock_get_runner = get_labelanalysis_deps["mock_get_runner"]
fake_runner = get_labelanalysis_deps["fake_runner"]
collected_labels = get_labelanalysis_deps["collected_labels"]
_ = get_labelanalysis_deps["collected_labels"]

label_analysis_result = {
"present_report_labels": ["test_present"],
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_invoke_label_analysis_dry_run(
def test_invoke_label_analysis_dry_run_pytest_format(
self, get_labelanalysis_deps, mocker
):
mock_get_runner = get_labelanalysis_deps["mock_get_runner"]
_ = get_labelanalysis_deps["mock_get_runner"]
fake_runner = get_labelanalysis_deps["fake_runner"]

label_analysis_result = {
Expand Down Expand Up @@ -733,7 +733,7 @@ def test_first_labelanalysis_request_fails_but_second_works(
):
mock_get_runner = get_labelanalysis_deps["mock_get_runner"]
fake_runner = get_labelanalysis_deps["fake_runner"]
collected_labels = get_labelanalysis_deps["collected_labels"]
_ = get_labelanalysis_deps["collected_labels"]

label_analysis_result = {
"present_report_labels": ["test_present"],
Expand Down
24 changes: 12 additions & 12 deletions tests/commands/test_process_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_process_test_results(
tmpdir,
):

tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand All @@ -21,7 +21,7 @@ def test_process_test_results(
"GITHUB_REF": "pull/fake/pull",
},
)
mocked_post = mocker.patch(
_ = mocker.patch(
"codecov_cli.commands.process_test_results.send_post_request",
return_value=RequestResult(
status_code=200, error=None, warnings=[], text="yay it worked"
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_process_test_results_create_github_message(
tmpdir,
):

tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_process_test_results_update_github_message(
tmpdir,
):

tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_process_test_results_errors_getting_comments(
tmpdir,
):

tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand All @@ -187,7 +187,7 @@ def test_process_test_results_errors_getting_comments(
),
)

mocked_post = mocker.patch(
_ = mocker.patch(
"codecov_cli.commands.process_test_results.send_post_request",
return_value=RequestResult(
status_code=200, error=None, warnings=[], text="yay it worked"
Expand All @@ -211,7 +211,7 @@ def test_process_test_results_errors_getting_comments(


def test_process_test_results_non_existent_file(mocker, tmpdir):
tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand All @@ -220,7 +220,7 @@ def test_process_test_results_non_existent_file(mocker, tmpdir):
"GITHUB_REF": "pull/fake/pull",
},
)
mocked_post = mocker.patch(
_ = mocker.patch(
"codecov_cli.commands.process_test_results.send_post_request",
return_value=RequestResult(
status_code=200, error=None, warnings=[], text="yay it worked"
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_process_test_results_non_existent_file(mocker, tmpdir):


def test_process_test_results_missing_repo(mocker, tmpdir):
tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand All @@ -258,7 +258,7 @@ def test_process_test_results_missing_repo(mocker, tmpdir):
)
if "GITHUB_REPOSITORY" in os.environ:
del os.environ["GITHUB_REPOSITORY"]
mocked_post = mocker.patch(
_ = mocker.patch(
"codecov_cli.commands.process_test_results.send_post_request",
return_value=RequestResult(
status_code=200, error=None, warnings=[], text="yay it worked"
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_process_test_results_missing_repo(mocker, tmpdir):


def test_process_test_results_missing_ref(mocker, tmpdir):
tmp_file = tmpdir.mkdir("folder").join("summary.txt")
_ = tmpdir.mkdir("folder").join("summary.txt")

mocker.patch.dict(
os.environ,
Expand All @@ -299,7 +299,7 @@ def test_process_test_results_missing_ref(mocker, tmpdir):

if "GITHUB_REF" in os.environ:
del os.environ["GITHUB_REF"]
mocked_post = mocker.patch(
_ = mocker.patch(
"codecov_cli.commands.process_test_results.send_post_request",
return_value=RequestResult(
status_code=200, error=None, warnings=[], text="yay it worked"
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/git_services/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def mock_request(*args, headers={}, **kwargs):
)
slug = "codecov/codecov-cli"
response = Github().get_pull_request(slug, 1)
assert response == None
assert response is None
4 changes: 2 additions & 2 deletions tests/helpers/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def test_load_config(mocker):
def test_load_config_doesnt_exist(mocker):
path = pathlib.Path("doesnt/exist")
result = load_cli_config(path)
assert result == None
assert result is None


def test_load_config_not_file(mocker):
path = pathlib.Path("samples/")
result = load_cli_config(path)
assert result == None
assert result is None


def test_find_codecov_yaml(mocker):
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
)
def test_encode_invalid_slug(slug):
with pytest.raises(ValueError) as ex:
with pytest.raises(ValueError) as _:
encode_slug(slug)


Expand Down Expand Up @@ -77,7 +77,7 @@ def test_valid_slug():
)
def test_invalid_encoded_slug(slug):
assert slug_encoded_incorrectly(slug)
with pytest.raises(ValueError) as ex:
with pytest.raises(ValueError) as _:
decode_slug(slug)


Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ def test_parse_git_service_invalid_service(url):

def test_get_git_service_class():
assert isinstance(git.get_git_service("github"), Github)
assert git.get_git_service("gitlab") == None
assert git.get_git_service("bitbucket") == None
assert git.get_git_service("gitlab") is None
assert git.get_git_service("bitbucket") is None
8 changes: 4 additions & 4 deletions tests/helpers/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_log_error_no_raise(mocker):
error=error, warnings=[], status_code=401, text="Unauthorized"
)
log_warnings_and_errors_if_any(result, "Process", fail_on_error=False)
mock_log_error.assert_called_with(f"Process failed: Unauthorized")
mock_log_error.assert_called_with("Process failed: Unauthorized")


def test_log_error_raise(mocker):
Expand All @@ -51,7 +51,7 @@ def test_log_error_raise(mocker):
)
with pytest.raises(SystemExit):
log_warnings_and_errors_if_any(result, "Process", fail_on_error=True)
mock_log_error.assert_called_with(f"Process failed: Unauthorized")
mock_log_error.assert_called_with("Process failed: Unauthorized")


def test_log_result_without_token(mocker):
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_request_retry(mocker, valid_response):


def test_request_retry_too_many_errors(mocker):
mock_sleep = mocker.patch("codecov_cli.helpers.request.sleep")
_ = mocker.patch("codecov_cli.helpers.request.sleep")
mocker.patch.object(
requests,
"post",
Expand All @@ -150,7 +150,7 @@ def test_request_retry_too_many_errors(mocker):
],
)
with pytest.raises(Exception) as exp:
resp = send_post_request("my_url")
_ = send_post_request("my_url")
assert str(exp.value) == "Request failed after too many retries"


Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def mocked_legacy_upload_endpoint(mocked_responses):
def mocked_test_results_endpoint(mocked_responses):
resp = responses.Response(
responses.POST,
f"https://ingest.codecov.io/upload/test_results/v1",
"https://ingest.codecov.io/upload/test_results/v1",
status=200,
json={
"raw_upload_location": "https://puturl.com",
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/test_versioning_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ def test_list_relevant_files_fails_if_no_root_is_found(self, mocker):
)

vs = GitVersioningSystem()
with pytest.raises(ValueError) as ex:
with pytest.raises(ValueError) as _:
vs.list_relevant_files()
6 changes: 3 additions & 3 deletions tests/plugins/test_compress_pycoverage_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class TestCompressPycoverageContexts(object):
def test_default_options(self):
plugin = CompressPycoverageContexts()
assert plugin.config.file_to_compress == pathlib.Path("coverage.json")
assert plugin.config.delete_uncompressed == True
assert plugin.config.delete_uncompressed
assert plugin.file_to_compress == pathlib.Path("coverage.json")
assert plugin.file_to_write == pathlib.Path("coverage.codecov.json")

Expand All @@ -183,7 +183,7 @@ def test_change_options(self):
}
plugin = CompressPycoverageContexts(config)
assert plugin.config.file_to_compress == pathlib.Path("label.coverage.json")
assert plugin.config.delete_uncompressed == False
assert not plugin.config.delete_uncompressed
assert plugin.file_to_compress == pathlib.Path("label.coverage.json")
assert plugin.file_to_write == pathlib.Path("label.coverage.codecov.json")

Expand All @@ -192,7 +192,7 @@ def test_run_preparation_fail_fast_no_file(self):
res = plugin.run_preparation(None)
assert res == PreparationPluginReturn(
success=False,
messages=[f"File to compress coverage.json not found."],
messages=["File to compress coverage.json not found."],
)

def test_run_preparation_fail_fast_path_not_file(self, tmp_path):
Expand Down
Loading

0 comments on commit 5c7a891

Please sign in to comment.