summaryrefslogtreecommitdiffstats
path: root/xlate-test.py
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2022-10-28 19:07:14 +0200
committerPhil Sutter <phil@nwl.cc>2022-11-11 19:14:28 +0100
commit595cad95fd2f61c6bc71e521ab58556f13648c30 (patch)
tree3e8c4092b50b193d1926684baf825c8ff426aaf5 /xlate-test.py
parent0d652b8b9ed45d2cfb2e246033cc074faf8aad16 (diff)
tests: xlate-test.py: Introduce run_proc()
It's just a convenience wrapper around Popen(), simplifying the call. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'xlate-test.py')
-rwxr-xr-xxlate-test.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/xlate-test.py b/xlate-test.py
index ee393349..bfcddde0 100755
--- a/xlate-test.py
+++ b/xlate-test.py
@@ -7,6 +7,13 @@ import shlex
import argparse
from subprocess import Popen, PIPE
+def run_proc(args, shell = False):
+ """A simple wrapper around Popen, returning (rc, stdout, stderr)"""
+ process = Popen(args, text = True, shell = shell,
+ stdout = PIPE, stderr = PIPE)
+ output, error = process.communicate()
+ return (process.returncode, output, error)
+
keywords = ("iptables-translate", "ip6tables-translate", "ebtables-translate")
xtables_nft_multi = 'xtables-nft-multi'
@@ -34,14 +41,13 @@ def green(string):
def test_one_xlate(name, sourceline, expected, result):
- process = Popen([ xtables_nft_multi ] + shlex.split(sourceline), stdout=PIPE, stderr=PIPE)
- (output, error) = process.communicate()
- if process.returncode != 0:
+ rc, output, error = run_proc([xtables_nft_multi] + shlex.split(sourceline))
+ if rc != 0:
result.append(name + ": " + red("Error: ") + "iptables-translate failure")
- result.append(error.decode("utf-8"))
+ result.append(error)
return False
- translation = output.decode("utf-8").rstrip(" \n")
+ translation = output.rstrip(" \n")
if translation != expected:
result.append(name + ": " + red("Fail"))
result.append(magenta("src: ") + sourceline.rstrip(" \n"))