X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Fintegration%2Ftestlib%2Futil.py;h=fdba760eb985350cde31e3af6423f1aa44a084cd;hb=c8402791b82947c49ba1d04f855dab04191607ca;hp=f0849b954a5c02173caefc9be566b8a631ab57df;hpb=3d787920d51a35e74e442c7265be3b13b69ad8e4;p=tinc diff --git a/test/integration/testlib/util.py b/test/integration/testlib/util.py index f0849b95..fdba760e 100755 --- a/test/integration/testlib/util.py +++ b/test/integration/testlib/util.py @@ -7,6 +7,7 @@ import random import string import socket import typing as T +import tempfile from pathlib import Path from . import check @@ -32,6 +33,14 @@ def random_port() -> int: log.debug("could not bind to random port %d", port, exc_info=ex) +def temp_file(content: str) -> str: + """Create a temporary file and write text content into it.""" + file = tempfile.mktemp() + with open(file, "w", encoding="utf-8") as f: + f.write(content) + return file + + def remove_file(path: T.Union[str, Path]) -> bool: """Try to remove file without failing if it does not exist.""" try: @@ -70,9 +79,13 @@ def require_command(*args: str) -> None: """Check that command args runs with exit code 0. Exit with code 77 otherwise. """ - if subp.run(args, check=False).returncode: - log.info('this test requires command "%s" to work', " ".join(args)) - sys.exit(EXIT_SKIP) + try: + if subp.run(args, check=False).returncode == 0: + return + except FileNotFoundError: + pass + log.info('this test requires command "%s" to work', " ".join(args)) + sys.exit(EXIT_SKIP) def require_path(path: str) -> None: