From 96f201bad76a4577ad2ca41e7fc393dc2ac7b6cd Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Mon, 4 Nov 2024 21:08:21 +0100 Subject: [PATCH] Concatenate strings that are separated by a single space --- test/conftest.py | 4 ++-- test/test_backends.py | 10 ++++++---- test/test_modules.py | 4 ++-- testinfra/backend/lxc.py | 2 +- testinfra/modules/ansible.py | 2 +- testinfra/modules/mountpoint.py | 4 +--- testinfra/modules/puppet.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 107c0af3..9450619d 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -69,10 +69,10 @@ def setup_ansible_config(tmpdir, name, host, user, port, key): "ansible_user={}".format(user), "ansible_port={}".format(port), ] - tmpdir.join("inventory").write("[testgroup]\n" + " ".join(items) + "\n") + tmpdir.join("inventory").write(f'[testgroup]\n{" ".join(items)}\n') tmpdir.mkdir("host_vars").join(name).write(ANSIBLE_HOSTVARS) tmpdir.mkdir("group_vars").join("testgroup").write( - ("---\n" "myhostvar: should_be_overriden\n" "mygroupvar: qux\n") + "---\nmyhostvar: should_be_overriden\nmygroupvar: qux\n" ) vault_password_file = tmpdir.join("vault-pass.txt") vault_password_file.write("polichinelle\n") diff --git a/test/test_backends.py b/test/test_backends.py index c3b717d5..0d2bc147 100644 --- a/test/test_backends.py +++ b/test/test_backends.py @@ -86,16 +86,18 @@ def test_encoding(host): elif host.backend.get_connection_type() == "ansible" and host.backend.force_ansible: # XXX: this encoding issue comes directly from ansible # not sure how to handle this... - assert cmd.stderr == ( - "ls: impossible d'accéder à '/é': " "Aucun fichier ou dossier de ce type" + assert ( + cmd.stderr + == "ls: impossible d'accéder à '/é': Aucun fichier ou dossier de ce type" ) else: assert cmd.stderr_bytes == ( b"ls: impossible d'acc\xe9der \xe0 '/\xe9': " b"Aucun fichier ou dossier de ce type\n" ) - assert cmd.stderr == ( - "ls: impossible d'accéder à '/é': " "Aucun fichier ou dossier de ce type\n" + assert ( + cmd.stderr + == "ls: impossible d'accéder à '/é': Aucun fichier ou dossier de ce type\n" ) diff --git a/test/test_modules.py b/test/test_modules.py index 15416344..9d5fb447 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -329,7 +329,7 @@ def test_file(host): def test_ansible_unavailable(host): - expected = "Ansible module is only available with " "ansible connection backend" + expected = "Ansible module is only available with ansible connection backend" with pytest.raises(RuntimeError) as excinfo: host.ansible("setup") assert expected in str(excinfo.value) @@ -374,7 +374,7 @@ def test_ansible_module(host): except host.ansible.AnsibleException as exc: assert exc.result["rc"] == 2 # notez que the debian bookworm container is set to LANG=fr_FR - assert exc.result["msg"] == ("[Errno 2] Aucun fichier ou dossier " "de ce type") + assert exc.result["msg"] == "[Errno 2] Aucun fichier ou dossier de ce type" result = host.ansible("command", "echo foo", check=False) assert result["stdout"] == "foo" diff --git a/testinfra/backend/lxc.py b/testinfra/backend/lxc.py index a75e3b62..0db1e290 100644 --- a/testinfra/backend/lxc.py +++ b/testinfra/backend/lxc.py @@ -25,7 +25,7 @@ def __init__(self, name: str, *args: Any, **kwargs: Any): def run(self, command: str, *args: str, **kwargs: Any) -> base.CommandResult: cmd = self.get_command(command, *args) out = self.run_local( - "lxc exec %s --mode=non-interactive -- " "/bin/sh -c %s", self.name, cmd + "lxc exec %s --mode=non-interactive -- /bin/sh -c %s", self.name, cmd ) out.command = self.encode(cmd) return out diff --git a/testinfra/modules/ansible.py b/testinfra/modules/ansible.py index 033992e2..8d997709 100644 --- a/testinfra/modules/ansible.py +++ b/testinfra/modules/ansible.py @@ -38,7 +38,7 @@ def need_ansible(func): def wrapper(self, *args, **kwargs): if not self._host.backend.HAS_RUN_ANSIBLE: raise RuntimeError( - ("Ansible module is only available with ansible " "connection backend") + ("Ansible module is only available with ansible connection backend") ) return func(self, *args, **kwargs) diff --git a/testinfra/modules/mountpoint.py b/testinfra/modules/mountpoint.py index 4fd5369e..45e17580 100644 --- a/testinfra/modules/mountpoint.py +++ b/testinfra/modules/mountpoint.py @@ -101,9 +101,7 @@ def get_module_class(cls, host): raise NotImplementedError def __repr__(self): - return ( - "" - ).format( + return ("").format( self.path, self.device, self.filesystem, diff --git a/testinfra/modules/puppet.py b/testinfra/modules/puppet.py index a5aa414a..b6c8dc87 100644 --- a/testinfra/modules/puppet.py +++ b/testinfra/modules/puppet.py @@ -102,7 +102,7 @@ class Facter(InstanceModule): """ def __call__(self, *facts): - cmd = "facter --json --puppet " + " ".join(facts) + cmd = f'facter --json --puppet {" ".join(facts)}' return json.loads(self.check_output(cmd)) def __repr__(self):