Skip to content

Commit f600c85

Browse files
committed
Add flake8-pep3101
Replace modulo formatting by str.format()
1 parent 39d77f2 commit f600c85

25 files changed

+68
-60
lines changed

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
# General information about the project.
6464
project = u'testinfra'
65-
copyright = u'%s, Philippe Pepiot' % datetime.date.today().year
65+
copyright = u'{}, Philippe Pepiot'.format(datetime.date.today().year)
6666

6767
# The version info for the project you're documenting, acts as replacement for
6868
# |version| and |release|, also used in various other places throughout the

test/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def teardown():
118118
port = check_output("docker port %s 22", docker_id)
119119
port = int(port.rsplit(":", 1)[-1])
120120
return docker_id, docker_host, port
121-
fname = "_docker_container_%s_%s" % (image, scope)
121+
fname = "_docker_container_{}_{}".format(image, scope)
122122
mod = sys.modules[__name__]
123123
setattr(mod, fname, func)
124124

@@ -147,7 +147,7 @@ def host(request, tmpdir_factory):
147147
else:
148148
scope = "session"
149149

150-
fname = "_docker_container_%s_%s" % (spec.name, scope)
150+
fname = "_docker_container_{}_{}".format(spec.name, scope)
151151
docker_id, docker_host, port = request.getfixturevalue(fname)
152152

153153
if kw["connection"] == "docker":

testinfra/backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_backend_class(connection):
3535
try:
3636
classpath = BACKENDS[connection]
3737
except KeyError:
38-
raise RuntimeError("Unknown connection type '%s'" % (connection,))
38+
raise RuntimeError("Unknown connection type '{}'".format(connection))
3939
module, name = classpath.rsplit('.', 1)
4040
return getattr(importlib.import_module(module), name)
4141

testinfra/backend/base.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def stderr_bytes(self):
9191

9292
def __repr__(self):
9393
return (
94-
"CommandResult(command=%s, exit_status=%s, stdout=%s, "
95-
"stderr=%s)"
96-
) % (
97-
repr(self.command),
94+
"CommandResult(command={!r}, exit_status={}, stdout={!r}, "
95+
"stderr={!r})"
96+
).format(
97+
self.command,
9898
self.exit_status,
99-
repr(self._stdout_bytes or self._stdout),
100-
repr(self._stderr_bytes or self._stderr),
99+
self._stdout_bytes or self._stdout,
100+
self._stderr_bytes or self._stderr,
101101
)
102102

103103

@@ -160,15 +160,14 @@ def get_pytest_id(self):
160160
def get_hosts(cls, host, **kwargs):
161161
if host is None:
162162
raise RuntimeError(
163-
"One or more hosts is required with the %s backend" % (
164-
cls.get_connection_type(),),
165-
)
163+
"One or more hosts is required with the {} backend".format(
164+
cls.get_connection_type()))
166165
return [host]
167166

168167
@staticmethod
169168
def quote(command, *args):
170169
if args:
171-
return command % tuple(shlex.quote(a) for a in args)
170+
return command % tuple(shlex.quote(a) for a in args) # noqa: S001
172171
return command
173172

174173
def get_sudo_command(self, command, sudo_user):

testinfra/backend/salt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def run_salt(self, func, args=None):
4444
out = self.client.cmd(self.host, func, args or [])
4545
if self.host not in out:
4646
raise RuntimeError(
47-
"Error while running %s(%s): %s. Minion not connected ?" % (
47+
"Error while running {}({}): {}. "
48+
"Minion not connected ?".format(
4849
func, args, out))
4950
return out[self.host]
5051

@@ -60,6 +61,6 @@ def get_hosts(cls, host, **kwargs):
6061
else:
6162
hosts = client.cmd(host, "test.true").keys()
6263
if not hosts:
63-
raise RuntimeError("No host matching '%s'" % (host,))
64+
raise RuntimeError("No host matching '{}'".format(host))
6465
return sorted(hosts)
6566
return super().get_hosts(host, **kwargs)

testinfra/backend/ssh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _build_ssh_command(self, command):
6060
if self.controlpersist and (
6161
'controlmaster' not in (self.ssh_extra_args or '').lower()
6262
):
63-
cmd.append("-o ControlMaster=auto -o ControlPersist=%ds" % (
63+
cmd.append("-o ControlMaster=auto -o ControlPersist={}s".format(
6464
self.controlpersist))
6565
cmd.append("%s %s")
6666
cmd_args.extend([self.host.name, command])
@@ -99,9 +99,9 @@ def run(self, command, *args, **kwargs):
9999
orig_command = self.get_command('sh -c %s', orig_command)
100100

101101
out = self.run_ssh((
102-
'''of=$(mktemp)&&ef=$(mktemp)&&%s >$of 2>$ef; r=$?;'''
102+
'''of=$(mktemp)&&ef=$(mktemp)&&{} >$of 2>$ef; r=$?;'''
103103
'''echo "TESTINFRA_START;$r;$(base64 < $of);$(base64 < $ef);'''
104-
'''TESTINFRA_END";rm -f $of $ef''') % (orig_command,))
104+
'''TESTINFRA_END";rm -f $of $ef''').format(orig_command))
105105

106106
start = out.stdout.find("TESTINFRA_START;") + len("TESTINFRA_START;")
107107
end = out.stdout.find("TESTINFRA_END") - 1

testinfra/backend/winrm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ def run_winrm(self, command, *args):
7979
@staticmethod
8080
def quote(command, *args):
8181
if args:
82-
return command % tuple(_quote(a) for a in args)
82+
return command % tuple(_quote(a) for a in args) # noqa: S001
8383
return command

testinfra/host.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def find_command(self, command, extrapaths=('/sbin', '/usr/sbin')):
4343
path = os.path.join(basedir, command)
4444
if self.exists(path):
4545
return path
46-
raise ValueError('cannot find "%s" command' % (command,))
46+
raise ValueError('cannot find "{}" command'.format(command))
4747

4848
def run(self, command, *args, **kwargs):
4949
"""Run given command and return rc (exit status), stdout and stderr
@@ -83,7 +83,7 @@ def run_expect(self, expected, command, *args, **kwargs):
8383
__tracebackhide__ = True
8484
out = self.run(command, *args, **kwargs)
8585
assert out.rc in expected, (
86-
'Unexpected exit code %s for %s' % (out.rc, out))
86+
'Unexpected exit code {} for {}'.format(out.rc, out))
8787
return out
8888

8989
def run_test(self, command, *args, **kwargs):
@@ -102,7 +102,7 @@ def check_output(self, command, *args, **kwargs):
102102
__tracebackhide__ = True
103103
out = self.run(command, *args, **kwargs)
104104
assert out.rc == 0, (
105-
'Unexpected exit code %s for %s' % (out.rc, out))
105+
'Unexpected exit code {} for {}'.format(out.rc, out))
106106
return out.stdout.rstrip("\r\n")
107107

108108
def __getattr__(self, name):

testinfra/modules/addr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _prefix(self):
9090
"""Return the prefix to use for commands"""
9191
prefix = ""
9292
if self.namespace:
93-
prefix = "ip netns exec %s " % self.namespace
93+
prefix = "ip netns exec {} ".format(self.namespace)
9494
return prefix
9595

9696
@property
@@ -131,7 +131,7 @@ def port(self, port):
131131
return _AddrPort(self, port)
132132

133133
def __repr__(self):
134-
return "<addr %s>" % (self.name,)
134+
return "<addr {}>".format(self.name)
135135

136136
def _resolve(self, method):
137137
result = self.run_expect([0, 1, 2], "{}getent {} {}".format(

testinfra/modules/blockdevice.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def is_writable(self):
101101
return True
102102
if mode == 'ro':
103103
return False
104-
raise ValueError('Unexpected value for rw: %s' % mode)
104+
raise ValueError('Unexpected value for rw: {}'.format(mode))
105105

106106
@property
107107
def ra(self):
@@ -119,7 +119,7 @@ def get_module_class(cls, host):
119119
raise NotImplementedError
120120

121121
def __repr__(self):
122-
return '<BlockDevice(path=%s)>' % self.device
122+
return '<BlockDevice(path={})>'.format(self.device)
123123

124124

125125
class LinuxBlockDevice(BlockDevice):
@@ -128,14 +128,16 @@ class LinuxBlockDevice(BlockDevice):
128128
def _data(self):
129129
header = ['RO', 'RA', 'SSZ', 'BSZ', 'StartSec', 'Size', 'Device']
130130
command = 'blockdev --report %s'
131-
blockdev = self.run(command % self.device)
131+
blockdev = self.run(command, self.device)
132132
if blockdev.rc != 0 or blockdev.stderr:
133-
raise RuntimeError("Failed to gather data: %s" % blockdev.stderr)
133+
raise RuntimeError("Failed to gather data: {}".format(
134+
blockdev.stderr))
134135
output = blockdev.stdout.splitlines()
135136
if len(output) < 2:
136-
raise RuntimeError("No data from %s" % self.device)
137+
raise RuntimeError("No data from {}".format(self.device))
137138
if output[0].split() != header:
138-
raise RuntimeError('Unknown output of blockdev: %s' % output[0])
139+
raise RuntimeError('Unknown output of blockdev: {}'.format(
140+
output[0]))
139141
fields = output[1].split()
140142
return {
141143
'rw_mode': str(fields[0]),

0 commit comments

Comments
 (0)