Unify string formatting

Use one way of string formatting: replace old `%` style with new `str.format`.

Resolve #855.
This commit is contained in:
Darko Poljak 2021-03-30 07:56:38 +02:00
commit 4c2d273f07
17 changed files with 67 additions and 65 deletions

View file

@ -86,8 +86,7 @@ class ObjectClassTestCase(test.CdistTestCase):
def test_create_singleton(self):
"""Check whether creating an object without id (singleton) works"""
singleton = self.expected_objects[0].object_from_name(
"__test_singleton")
self.expected_objects[0].object_from_name("__test_singleton")
# came here - everything fine
def test_create_singleton_not_singleton_type(self):
@ -126,16 +125,16 @@ class ObjectIdTestCase(test.CdistTestCase):
def test_object_id_contains_object_marker(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = (
'object_id/may/not/contain/%s/anywhere' % OBJECT_MARKER_NAME)
illegal_object_id = 'object_id/may/not/contain/{}/anywhere'.format(
OBJECT_MARKER_NAME)
with self.assertRaises(core.IllegalObjectIdError):
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
def test_object_id_contains_object_marker_string(self):
cdist_type = core.CdistType(type_base_path, '__third')
illegal_object_id = (
'object_id/may/contain_%s_in_filename' % OBJECT_MARKER_NAME)
illegal_object_id = 'object_id/may/contain_{}_in_filename'.format(
OBJECT_MARKER_NAME)
core.CdistObject(cdist_type, self.object_base_path,
OBJECT_MARKER_NAME, illegal_object_id)
# if we get here, the test passed
@ -195,28 +194,32 @@ class ObjectTestCase(test.CdistTestCase):
def test_path(self):
self.assertEqual(self.cdist_object.path,
"__third/moon/%s" % OBJECT_MARKER_NAME)
"__third/moon/{}".format(OBJECT_MARKER_NAME))
def test_absolute_path(self):
self.assertEqual(self.cdist_object.absolute_path,
os.path.join(self.object_base_path,
"__third/moon/%s" % OBJECT_MARKER_NAME))
"__third/moon/{}".format(
OBJECT_MARKER_NAME)))
def test_code_local_path(self):
self.assertEqual(self.cdist_object.code_local_path,
"__third/moon/%s/code-local" % OBJECT_MARKER_NAME)
"__third/moon/{}/code-local".format(
OBJECT_MARKER_NAME))
def test_code_remote_path(self):
self.assertEqual(self.cdist_object.code_remote_path,
"__third/moon/%s/code-remote" % OBJECT_MARKER_NAME)
"__third/moon/{}/code-remote".format(
OBJECT_MARKER_NAME))
def test_parameter_path(self):
self.assertEqual(self.cdist_object.parameter_path,
"__third/moon/%s/parameter" % OBJECT_MARKER_NAME)
"__third/moon/{}/parameter".format(
OBJECT_MARKER_NAME))
def test_explorer_path(self):
self.assertEqual(self.cdist_object.explorer_path,
"__third/moon/%s/explorer" % OBJECT_MARKER_NAME)
"__third/moon/{}/explorer".format(OBJECT_MARKER_NAME))
def test_parameters(self):
expected_parameters = {'planet': 'Saturn', 'name': 'Prometheus'}

View file

@ -84,8 +84,8 @@ class EmulatorTestCase(test.CdistTestCase):
def test_illegal_object_id_requirement(self):
argv = ['__file', '/tmp/foobar']
self.env['require'] = (
"__file/bad/id/with/%s/inside") % self.local.object_marker_name
self.env['require'] = "__file/bad/id/with/{}/inside".format(
self.local.object_marker_name)
emu = emulator.Emulator(argv, env=self.env)
self.assertRaises(core.IllegalObjectIdError, emu.run)

View file

@ -47,8 +47,8 @@ class RemoteTestCase(test.CdistTestCase):
args = (self.target_host,)
kwargs.setdefault('base_path', self.base_path)
user = getpass.getuser()
kwargs.setdefault('remote_exec', 'ssh -o User=%s -q' % user)
kwargs.setdefault('remote_copy', 'scp -o User=%s -q' % user)
kwargs.setdefault('remote_exec', 'ssh -o User={} -q'.format(user))
kwargs.setdefault('remote_copy', 'scp -o User={} -q'.format(user))
if 'stdout_base_path' not in kwargs:
stdout_path = os.path.join(self.temp_dir, 'stdout')
os.makedirs(stdout_path, exist_ok=True)
@ -170,7 +170,7 @@ class RemoteTestCase(test.CdistTestCase):
r = self.create_remote(remote_exec=remote_exec,
remote_copy=remote_copy)
self.assertEqual(r.run('true', return_output=True),
"%s\n" % self.target_host[0])
"{}\n".format(self.target_host[0]))
def test_run_script_target_host_in_env(self):
handle, remote_exec_path = self.mkstemp(dir=self.temp_dir)
@ -185,7 +185,7 @@ class RemoteTestCase(test.CdistTestCase):
with os.fdopen(handle, "w") as fd:
fd.writelines(["#!/bin/sh\n", "true"])
self.assertEqual(r.run_script(script, return_output=True),
"%s\n" % self.target_host[0])
"{}\n".format(self.target_host[0]))
def test_run_script_with_env_target_host_in_env(self):
handle, script = self.mkstemp(dir=self.temp_dir)

View file

@ -67,7 +67,7 @@ class MessageTestCase(test.CdistTestCase):
def test_message_merge_prefix(self):
"""Ensure messages are merged and are prefixed"""
expectedcontent = "%s:%s" % (self.prefix, self.content)
expectedcontent = "{}:{}".format(self.prefix, self.content)
out = self.message.env['__messages_out']