Enable ruff UP031

This is kept separate since it is a little more intricate.

Change-Id: If340ff5c1e44a1b42fb2a34806d7e8a0164432ec
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane
2025-08-01 13:01:32 +01:00
parent 0fe75ebae3
commit c33794470c
7 changed files with 30 additions and 30 deletions

View File

@@ -274,8 +274,8 @@ def forever_retry_uncaught_exceptions(*args, **kwargs):
# The watch has expired or the exception message
# changed, so time to log it again...
logging.exception(
'Unexpected exception occurred %d time(s)... '
'retrying.' % same_failure_count
f'Unexpected exception occurred '
f'{same_failure_count} time(s)... retrying.'
)
if not watch.has_started():
watch.start()

View File

@@ -792,7 +792,7 @@ class VHDXInspector(FileInspector):
)
if count >= 2048:
raise ImageFormatError('Region count is %i (limit 2047)' % count)
raise ImageFormatError('Region count is {int(count)} (limit 2047)')
# Process the regions until we find the metadata one; grab the
# offset and return
@@ -849,7 +849,7 @@ class VHDXInspector(FileInspector):
if count >= 2048:
raise ImageFormatError(
'Metadata item count is %i (limit 2047)' % count
'Metadata item count is {int(count)} (limit 2047)'
)
for i in range(0, count):
@@ -1003,7 +1003,7 @@ class VMDKInspector(FileInspector):
raise ImageFormatError(f'Signature KDMV not found: {sig!r}')
if ver not in (1, 2, 3):
raise ImageFormatError('Unsupported format version %i' % ver)
raise ImageFormatError('Unsupported format version {int(ver)}')
if gdOffset == self.GD_AT_END and not self.has_region('footer'):
# This means we have a footer, which takes precedence over the
@@ -1364,7 +1364,9 @@ class GPTInspector(FileInspector):
sizelba,
) = struct.unpack('<B3BB3BII', pte)
if boot not in (0x00, 0x80):
raise SafetyViolation('MBR PTE %i has invalid boot flag' % i)
raise SafetyViolation(
f'MBR PTE {int(i)} has invalid boot flag'
)
if ostype != 0:
valid_partitions.append(i)
if ostype == 0xEE:
@@ -1415,7 +1417,7 @@ class LUKSInspector(FileInspector):
header = self.header_items
if header['version'] != 1:
raise SafetyViolation(
'LUKS version %i is not supported' % header['version']
f'LUKS version {int(header["version"])} is not supported'
)
@property

View File

@@ -89,7 +89,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
fn = tempfile.mktemp(prefix=prefix, suffix='.iso')
self._created_files.append(fn)
subprocess.check_output(
'dd if=/dev/zero of=%s bs=1M count=%i' % (fn, size), shell=True
f'dd if=/dev/zero of={fn} bs=1M count={int(size)}', shell=True
)
# We need to use different file as input and output as the behavior
# of mkisofs is version dependent if both the input and the output
@@ -140,7 +140,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
'-o',
'key-secret=sec0',
fn,
'%i' % image_size,
f'{int(image_size)}',
]
subprocess.check_output(' '.join(cmd), shell=True)
return fn
@@ -200,7 +200,7 @@ class TestFormatInspectors(test_base.BaseTestCase):
fn = tempfile.mktemp(prefix=prefix, suffix=f'.{fmt}')
self._created_files.append(fn)
subprocess.check_output(
'qemu-img create -f %s %s %s %i' % (fmt, opt, fn, size), shell=True
f'qemu-img create -f {fmt} {opt} {fn} {int(size)}', shell=True
)
return fn
@@ -223,13 +223,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
# Create a file with pseudo-random data, otherwise it will get
# compressed in the streamOptimized format
subprocess.check_output(
'dd if=/dev/urandom of=%s bs=1M count=%i' % (raw, size_mb),
f'dd if=/dev/urandom of={raw} bs=1M count={int(size_mb)}',
shell=True,
)
# Convert it to VMDK
subprocess.check_output(
f'qemu-img convert -f raw -O vmdk -o subformat={subformat} -S 0 {raw} {fn}',
f'qemu-img convert -f raw -O vmdk -o subformat={subformat} '
f'-S 0 {raw} {fn}',
shell=True,
)
return fn
@@ -287,14 +288,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
fmt = self._test_format_at_block_size(format_name, img, block_size)
self.assertTrue(
fmt.format_match,
'Failed to match %s at size %i block %i'
% (format_name, image_size, block_size),
f'Failed to match {format_name} at '
f'size {int(image_size)} block {int(block_size)}',
)
self.assertEqual(
virtual_size,
fmt.virtual_size,
('Failed to calculate size for %s at size %i block %i')
% (format_name, image_size, block_size),
f'Failed to calculate size for {format_name} at '
f'size {int(image_size)} block {int(block_size)}',
)
memory = sum(fmt.context_info.values())
self.assertLess(
@@ -481,14 +482,14 @@ class TestFormatInspectors(test_base.BaseTestCase):
fmt = self._test_format_at_block_size(format_name, img, block_size)
self.assertTrue(
fmt.format_match,
'Failed to match %s at size %i block %i'
% (format_name, image_size, block_size),
f'Failed to match {format_name} at '
f'size {int(image_size)} block {int(block_size)}',
)
self.assertEqual(
virtual_size,
fmt.virtual_size,
('Failed to calculate size for %s at size %i block %i')
% (format_name, image_size, block_size),
f'Failed to calculate size for {format_name} at '
f'size {int(image_size)} block {int(block_size)}',
)
memory = sum(fmt.context_info.values())
self.assertLess(

View File

@@ -132,10 +132,10 @@ class ImageUtilsHumanRawTestCase(test_base.BaseTestCase):
)
for i in range(self.snapshot_count):
img_info = img_info + (
'%d '
'd9a9784a500742a7bb95627bb3aace38 '
'0 2012-08-20 10:52:46 '
'00:00:00.000' % (i + 1),
f'{i + 1} '
f'd9a9784a500742a7bb95627bb3aace38 '
f'0 2012-08-20 10:52:46 '
f'00:00:00.000',
)
return img_info

View File

@@ -175,9 +175,7 @@ class ForeverRetryUncaughtExceptionsTest(test_base.BaseTestCase):
@mock.patch.object(logging, 'exception')
@mock.patch.object(timeutils, 'now')
def test_exc_retrier_1exc_gives_1log(self, mock_now, mock_log):
self._exceptions = [
Exception('unexpected %d' % 1),
]
self._exceptions = [Exception('unexpected 1')]
mock_now.side_effect = [0]
self.exception_generator()
@@ -185,7 +183,7 @@ class ForeverRetryUncaughtExceptionsTest(test_base.BaseTestCase):
self.assertEqual([], self._exceptions)
# log should only be called once
mock_log.assert_called_once_with(
'Unexpected exception occurred %d time(s)... retrying.' % 1
'Unexpected exception occurred 1 time(s)... retrying.'
)
mock_now.assert_has_calls(
[

View File

@@ -44,7 +44,6 @@ docstring-code-format = true
[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "S", "UP"]
ignore = ["UP031"]
[tool.ruff.lint.per-file-ignores]
"oslo_utils/tests/*" = ["S"]

View File

@@ -29,7 +29,7 @@ infile = 'large_json_payload.txt'
with open(infile) as f:
input_str = f.read()
print('payload has %d bytes' % len(input_str))
print(f'payload has {len(input_str)} bytes')
for pattern in strutils._SANITIZE_PATTERNS_2['admin_pass']:
print(f'\ntesting {pattern.pattern}')