Skip to content

Commit

Permalink
Comply to newer versions of pylint [RHELDST-26606] (#215)
Browse files Browse the repository at this point in the history
+ Change .pylintrc to ignore `too-many-positional-arguments`
+ Assign variables by default when they are possibly unbound
  • Loading branch information
Gdetrane authored Oct 9, 2024
1 parent 675561d commit 267bec6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ disable=fixme,
too-many-instance-attributes,
too-many-statements,
too-many-arguments,
too-many-positional-arguments,

18 changes: 9 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion tests/test_depsolve_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
from unittest import mock

import pytest
from pubtools.pulplib import Distributor, ModulemdDefaultsUnit, ModulemdUnit, RpmUnit
from pubtools.pulplib import (
Distributor,
ModulemdDefaultsUnit,
ModulemdUnit,
RpmUnit,
Unit,
)

from ubi_manifest.worker.models import UbiUnit
from ubi_manifest.worker.tasks import depsolve
from ubi_manifest.worker.ubi_config import ContentConfigMissing

Expand Down Expand Up @@ -871,6 +878,30 @@ def test_multiple_population_sources(pulp):
assert unit["value"] == "gcc_src_debug-1-0.src.rpm"


@mock.patch("ubi_manifest.worker.tasks.depsolve.redis.from_url")
def test_save_with_invalid_inner_unit(mock_redis_from_url):
"""Test scenario to reach the else continue statement in the _save() function
of depsolve_task."""

class InvalidInnerUnit(Unit):
def __init__(self):
super().__init__(content_type_id="mock_content")

redis = MockedRedis(data={})
mock_redis_from_url.return_value = redis

invalid_unit = UbiUnit(
unit=InvalidInnerUnit(),
src_repo_id="mock_repo_id",
)

data = {"mock_repo_id": [invalid_unit]}

depsolve._save(data)

mock_redis_from_url.set.assert_not_called()


def test_missing_content_config(pulp):
"""Exception is raised where there is no matching ubi content config"""
_setup_repos_missing_config(pulp)
Expand Down
8 changes: 6 additions & 2 deletions ubi_manifest/worker/tasks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def validate_content_config(_: AttrsInstance, attr: Any, value: dict[str, str])
for repo_class, url_or_dir in value.items():
if not re.match(REPO_CLASS_REGEX, repo_class):
raise ValueError(
f"Repo classes in '{attr.name}' must match regex '{REPO_CLASS_REGEX}'. '{repo_class}' doesn't."
(
f"Repo classes in '{attr.name}' must match regex '{REPO_CLASS_REGEX}'."
f"'{repo_class}' doesn't."
)
)
url_or_dir = str(url_or_dir)
if url_or_dir.lower().startswith(("http://", "https://")):
Expand All @@ -33,7 +36,8 @@ def validate_content_config(_: AttrsInstance, attr: Any, value: dict[str, str])
value_type = "Path"
if not re.match(regex, url_or_dir, re.VERBOSE):
raise ValueError(
f"{value_type} to config in '{attr.name}' must match regex '{regex}'. '{url_or_dir}' doesn't."
f"{value_type} to config in '{attr.name}' must match regex '{regex}'."
f"'{url_or_dir}' doesn't."
)


Expand Down
1 change: 1 addition & 0 deletions ubi_manifest/worker/tasks/content_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def content_audit_task() -> None:
in_repos = client.search_repository(
Criteria.with_id(out_repo.population_sources)
)
modular_rpm_filenames = set()
if has_modules:
modular_rpm_filenames = get_pkgs_from_all_modules(
list(in_repos) + [out_repo]
Expand Down
3 changes: 3 additions & 0 deletions ubi_manifest/worker/tasks/depsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def _save(data: dict[str, list[UbiUnit]]) -> None:
for repo_id, units in data.items():
items = []
for unit in units:
item = {}
if unit.isinstance_inner_unit(RpmUnit):
item = {
"src_repo_id": unit.associate_source_repo_id,
Expand All @@ -229,6 +230,8 @@ def _save(data: dict[str, list[UbiUnit]]) -> None:
"unit_attr": "name:stream",
"value": f"{unit.name}:{unit.stream}",
}
else:
continue
items.append(item)

data_for_redis[repo_id] = items
Expand Down

0 comments on commit 267bec6

Please sign in to comment.