From: Nicki Křížek Date: Thu, 23 Oct 2025 10:36:56 +0000 (+0200) Subject: Add generic isctest.run.EnvCmd helper to pytest X-Git-Tag: v9.21.17~53^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff613a72d73ba6b778d24c4e0bd3190d6c8930c7;p=thirdparty%2Fbind9.git Add generic isctest.run.EnvCmd helper to pytest A generic helper that calls the environment-specified binaries in a developer-friendly manner, i.e. passing arguments as strings rather than having to split them first. The isctest.run.cmd() remains as the basis which provides a clean and robust interface, while the isctest.run.EnvCmd() can be used as a convenient wrapper for tests, or when there are some shared default parameters. The isctest.run.Dig() is superseded with the isctest.run.EnvCmd(). In the future, we might revisit adding Dig() or command-specific helpers again, but it probably only makes sense if they offer command-aware attributes / methods, rather than just being shortcuts to isctest.run.EnvCmd(). --- diff --git a/bin/tests/system/isctest/run.py b/bin/tests/system/isctest/run.py index 530d413751f..9b6ef31236b 100644 --- a/bin/tests/system/isctest/run.py +++ b/bin/tests/system/isctest/run.py @@ -81,6 +81,19 @@ def cmd( return CmdResult(exc) +class EnvCmd: + """Helper for executing binaries from env with optional base parameters.""" + + def __init__(self, name: str, base_params: str = ""): + self.bin_path = os.environ[name] + self.base_params = base_params.split() + + def __call__(self, params: str, **kwargs) -> CmdResult: + """Call the command. Keyword arguments from isctest.run.cmd() are supported.""" + args = self.base_params + params.split() + return cmd([self.bin_path] + args, **kwargs) + + def _run_script( interpreter: str, script: str, @@ -116,17 +129,6 @@ def _run_script( isctest.log.debug(" exited with %d", returncode) -class Dig: - def __init__(self, base_params: str = ""): - self.base_params = base_params - - def __call__(self, params: str) -> CmdResult: - """Run the dig command with the given parameters.""" - return cmd( - [os.environ.get("DIG")] + f"{self.base_params} {params}".split(), - ) - - def shell(script: str, args: Optional[List[str]] = None) -> None: """Run a given script with system's shell interpreter.""" _run_script(os.environ["SHELL"], script, args) diff --git a/bin/tests/system/keepalive/tests_keepalive.py b/bin/tests/system/keepalive/tests_keepalive.py index 5314d7ee57b..1025ac53840 100644 --- a/bin/tests/system/keepalive/tests_keepalive.py +++ b/bin/tests/system/keepalive/tests_keepalive.py @@ -28,7 +28,7 @@ def test_dig_tcp_keepalive_handling(named_port, ns2): options_received = line.split()[0] return int(options_received) - dig = isctest.run.Dig(f"-p {str(named_port)}") + dig = isctest.run.EnvCmd("DIG", f"-p {str(named_port)}") isctest.log.info("check that dig handles TCP keepalive in query") assert "; TCP-KEEPALIVE" in dig("+qr +keepalive foo.example. @10.53.0.2").out