diff options
author | Thomas Haller <thaller@redhat.com> | 2023-02-03 13:26:32 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-02-08 09:51:26 +0100 |
commit | 5da7301ec981f8887ddb1dd2a7447d5a566263d9 (patch) | |
tree | 0589401ecdfc4ca61d29a8083fbe33368df09066 | |
parent | b76bb7333e11448b4692bf57c123d564eaf0864e (diff) | |
download | NetworkManager-5da7301ec981f8887ddb1dd2a7447d5a566263d9.tar.gz |
test-client: add Util.shlex_join() helper
-rwxr-xr-x | src/tests/client/test-client.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index e936c4c452..66212501eb 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -251,7 +251,8 @@ class Util: ).search @staticmethod - def quote(s): + def shlex_quote(s): + # Reimplement shlex.quote(). if Util.python_has_version(3, 3): return shlex.quote(s) if not s: @@ -261,6 +262,11 @@ class Util: return "'" + s.replace("'", "'\"'\"'") + "'" @staticmethod + def shlex_join(args): + # Reimplement shlex.join() + return " ".join(Util.shlex_quote(s) for s in args) + + @staticmethod def popen_wait(p, timeout=0): (res, b_stdout, b_stderr) = Util.popen_wait_read( p, timeout=timeout, read_std_pipes=False @@ -1024,7 +1030,7 @@ class TestNmcli(NmTestBase): self.assertEqual(returncode, -5) if check_on_disk: - cmd = "$NMCLI %s" % (" ".join([Util.quote(a) for a in args[1:]])) + cmd = "$NMCLI %s" % (Util.shlex_join(args[1:]),) cmd = Util.replace_text(cmd, replace_cmd) if returncode < 0: @@ -1971,16 +1977,13 @@ def main(): "eval `dbus-launch --sh-syntax`;\n" + 'trap "kill $DBUS_SESSION_BUS_PID" EXIT;\n' + "\n" - + " ".join( + + Util.shlex_join( [ - Util.quote(a) - for a in [ - sys.executable, - __file__, - "--started-with-dbus-session", - ] - + sys.argv[1:] + sys.executable, + __file__, + "--started-with-dbus-session", ] + + sys.argv[1:] ) + " \n" + "", |