Skip to content

Commit

Permalink
[6.15.z] Preparations for ruff 0.4.1 (#14885) (#14900)
Browse files Browse the repository at this point in the history
Preparations for ruff 0.4.1 (#14885)

(cherry picked from commit db9b858)
  • Loading branch information
ogajduse authored Apr 26, 2024
1 parent dc848da commit b0afc25
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 50 deletions.
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ exclude = '''

[tool.ruff]
target-version = "py311"

[tool.ruff.lint]
fixable = ["ALL"]

select = [
Expand All @@ -40,21 +42,21 @@ ignore = [
"PT005", # pytest no underscrore prefix for return fixtures
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = [
"robottelo",
]
combine-as-imports = true

[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.pytest.ini_options]
Expand Down
4 changes: 1 addition & 3 deletions robottelo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def __str__(self):

def __repr__(self):
"""Include class name status, stderr and msg to improve logging"""
return '{}(status={!r}, stderr={!r}, msg={!r}'.format(
type(self).__name__, self.status, self.stderr, self.msg
)
return f'{type(self).__name__}(status={self.status!r}, stderr={self.stderr!r}, msg={self.msg!r}'


class CLIReturnCodeError(CLIBaseError):
Expand Down
8 changes: 2 additions & 6 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def create_object(cli_object, options, values=None, credentials=None, timeout=No
except CLIReturnCodeError as err:
# If the object is not created, raise exception, stop the show.
raise CLIFactoryError(
'Failed to create {} with data:\n{}\n{}'.format(
cli_object.__name__, pprint.pformat(options, indent=2), err.msg
)
f'Failed to create {cli_object.__name__} with data:\n{pprint.pformat(options, indent=2)}\n{err.msg}'
) from err
# Sometimes we get a list with a dictionary and not a dictionary.
if isinstance(result, list) and len(result) > 0:
Expand Down Expand Up @@ -999,9 +997,7 @@ def add_role_permissions(self, role_id, resource_permissions):
missing_permissions = set(permission_names).difference(set(available_permission_names))
if missing_permissions:
raise CLIFactoryError(
'Permissions "{}" are not available in Resource "{}"'.format(
list(missing_permissions), resource_type
)
f'Permissions "{list(missing_permissions)}" are not available in Resource "{resource_type}"'
)
# Create the current resource type role permissions
options = {'role-id': role_id}
Expand Down
6 changes: 1 addition & 5 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,7 @@ def add_authorized_key(self, pub_key):
# ensure ssh directory exists
self.execute(f'mkdir -p {ssh_path}')
# append the key if doesn't exists
self.execute(
"grep -q '{key}' {dest} || echo '{key}' >> {dest}".format(
key=key_content, dest=auth_file
)
)
self.execute(f"grep -q '{key_content}' {auth_file} || echo '{key_content}' >> {auth_file}")
# set proper permissions
self.execute(f'chmod 700 {ssh_path}')
self.execute(f'chmod 600 {auth_file}')
Expand Down
8 changes: 2 additions & 6 deletions robottelo/utils/decorators/func_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ def function_wrapper(*args, **kwargs):

with file_lock(lock_file_path, remove=False, timeout=timeout) as handler:
logger.info(
'process id: {} lock function using file path: {}'.format(
process_id, lock_file_path
)
f'process id: {process_id} lock function using file path: {lock_file_path}'
)
# write the process id that locked this function
_write_content(handler, process_id)
Expand Down Expand Up @@ -303,9 +301,7 @@ def locking_function(

with file_lock(lock_file_path, remove=False, timeout=timeout) as handler:
logger.info(
'process id: {} - lock function name:{} - using file path: {}'.format(
process_id, function_name, lock_file_path
)
f'process id: {process_id} - lock function name:{function_name} - using file path: {lock_file_path}'
)
# write the process id that locked this function
_write_content(handler, process_id)
Expand Down
8 changes: 2 additions & 6 deletions robottelo/utils/decorators/func_shared/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ def _call_function(self):
traceback_text = None
try:
logger.info(
'calling shared function: {} - retry index: {}'.format(
self._function_key, retry_index
)
f'calling shared function: {self._function_key} - retry index: {retry_index}'
)
result = self._function(*self._function_args, **self._function_kwargs)
break
Expand Down Expand Up @@ -334,9 +332,7 @@ def __call__(self):
creation_datetime = datetime.datetime.utcnow().strftime(_DATETIME_FORMAT)
if exp:
error = str(exp) or 'error occurred'
error_class_name = '{}.{}'.format(
exp.__class__.__module__, exp.__class__.__name__
)
error_class_name = f'{exp.__class__.__module__}.{exp.__class__.__name__}'
value = dict(
state=_STATE_FAILED,
id=self.transaction,
Expand Down
12 changes: 3 additions & 9 deletions robottelo/utils/virtwho.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,14 @@ def register_system(system, activation_key=None, org='Default_Organization', env
runcmd('subscription-manager clean', system)
runcmd('rpm -qa | grep katello-ca-consumer | xargs rpm -e |sort', system)
runcmd(
'rpm -ihv http://{}/pub/katello-ca-consumer-latest.noarch.rpm'.format(
settings.server.hostname
),
f'rpm -ihv http://{settings.server.hostname}/pub/katello-ca-consumer-latest.noarch.rpm',
system,
)
cmd = f'subscription-manager register --org={org} --environment={env} '
if activation_key is not None:
cmd += f'--activationkey={activation_key}'
else:
cmd += '--username={} --password={}'.format(
settings.server.admin_username, settings.server.admin_password
)
cmd += f'--username={settings.server.admin_username} --password={settings.server.admin_password}'
ret, stdout = runcmd(cmd, system)
if ret == 0 or "system has been registered" in stdout:
return True
Expand Down Expand Up @@ -170,9 +166,7 @@ def get_configure_command(config_id, org=DEFAULT_ORG):
:param str org: the satellite organization name.
"""
username, password = Base._get_username_password()
return "hammer -u {} -p {} virt-who-config deploy --id {} --organization '{}' ".format(
username, password, config_id, org
)
return f"hammer -u {username} -p {password} virt-who-config deploy --id {config_id} --organization '{org}' "


def get_configure_file(config_id):
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/ui/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,6 @@ def test_positive_add_event(session, module_org):
assert values['resource_type'] == 'KATELLO/CONTENT VIEW ENVIRONMENT'
assert values['resource_name'] == f'{ENVIRONMENT}/{cv.name} / {cv.name}'
assert len(values['action_summary']) == 1
assert values['action_summary'][0]['column0'] == 'Added {}/{} to {}'.format(
ENVIRONMENT, cv.name, cv.name
assert (
values['action_summary'][0]['column0'] == f'Added {ENVIRONMENT}/{cv.name} to {cv.name}'
)
4 changes: 1 addition & 3 deletions tests/foreman/ui/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def test_positive_task_status(session, target_sat):
tasks = session.task.read_all()
total_items = session.task.total_items()
assert total_items == int(tasks['StoppedChart']['table'][1]['Total'])
task_name = "Synchronize repository '{}'; product '{}'; organization '{}'".format(
repo.name, product.name, org.name
)
task_name = f"Synchronize repository '{repo.name}'; product '{product.name}'; organization '{org.name}'"
assert tasks['table'][0]['Action'] == task_name
assert tasks['table'][0]['State'] == 'stopped'
assert tasks['table'][0]['Result'] == 'warning'
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/ui/test_hostcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ def test_positive_install_modular_errata(
"""
stream = "0"
version = "20180704111719"
_module_install_command = 'dnf -y module install {}:{}:{}'.format(
constants.FAKE_4_CUSTOM_PACKAGE_NAME, stream, version
_module_install_command = (
f'dnf -y module install {constants.FAKE_4_CUSTOM_PACKAGE_NAME}:{stream}:{version}'
)
_run_remote_command_on_content_hosts(_module_install_command, vm_content_hosts_module_stream)
_run_remote_command_on_content_hosts('dnf -y upload-profile', vm_content_hosts_module_stream)
Expand Down
10 changes: 6 additions & 4 deletions tests/foreman/ui/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,9 @@ def test_positive_upstream_with_credentials(session, module_prod):
)
assert session.repository.search(module_prod.name, repo_name)[0]['Name'] == repo_name
repo_values = session.repository.read(module_prod.name, repo_name)
assert repo_values['repo_content']['upstream_authorization'] == '{} / {}'.format(
upstream_username, hidden_password
assert (
repo_values['repo_content']['upstream_authorization']
== f'{upstream_username} / {hidden_password}'
)
session.repository.update(
module_prod.name,
Expand All @@ -596,8 +597,9 @@ def test_positive_upstream_with_credentials(session, module_prod):
},
)
repo_values = session.repository.read(module_prod.name, repo_name)
assert repo_values['repo_content']['upstream_authorization'] == '{} / {}'.format(
new_upstream_username, hidden_password
assert (
repo_values['repo_content']['upstream_authorization']
== f'{new_upstream_username} / {hidden_password}'
)
session.repository.update(
module_prod.name, repo_name, {'repo_content.upstream_authorization': {}}
Expand Down

0 comments on commit b0afc25

Please sign in to comment.