aboutsummaryrefslogtreecommitdiffstats
path: root/test/serd_test_util/__init__.py
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-03-31 14:17:27 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:07 -0500
commit2f490c80f9623ac2deaeb37a29fc98d01eb20e7e (patch)
treef3dcbbef79d7bf3ae0ff30768bdce69a57cfeee3 /test/serd_test_util/__init__.py
parent55cb2411c1ddfe268c5d48f486f4da02470ab3d1 (diff)
downloadserd-2f490c80f9623ac2deaeb37a29fc98d01eb20e7e.tar.gz
serd-2f490c80f9623ac2deaeb37a29fc98d01eb20e7e.tar.bz2
serd-2f490c80f9623ac2deaeb37a29fc98d01eb20e7e.zip
Factor out test runner script argument parsing
Diffstat (limited to 'test/serd_test_util/__init__.py')
-rw-r--r--test/serd_test_util/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/serd_test_util/__init__.py b/test/serd_test_util/__init__.py
index 04876f98..260dcd9d 100644
--- a/test/serd_test_util/__init__.py
+++ b/test/serd_test_util/__init__.py
@@ -8,10 +8,12 @@
# pylint: disable=consider-using-f-string
# pylint: disable=invalid-name
+import argparse
import datetime
import difflib
import os
import re
+import shlex
import subprocess
import sys
import urllib.parse
@@ -51,6 +53,33 @@ def error(message):
sys.stderr.write("\n")
+def wrapper_args(description, with_input=False):
+ """Return the command line arguments for a wrapped test."""
+
+ parser = argparse.ArgumentParser(description)
+ parser.add_argument("--serdi", default="./serdi", help="serdi executable")
+ parser.add_argument("--wrapper", default="", help="executable wrapper")
+ if with_input:
+ parser.add_argument("input", help="input file")
+
+ return parser.parse_args(sys.argv[1:])
+
+
+def command_output(wrapper, command, stdin=None):
+ """Run a command and check that stdout matches the expected output."""
+
+ proc = subprocess.run(
+ shlex.split(wrapper) + command,
+ capture_output=True,
+ check=True,
+ encoding="utf-8",
+ input=stdin,
+ )
+
+ assert wrapper or not proc.stderr
+ return proc.stdout
+
+
def print_result_summary(results):
"""Print test result summary to stdout or stderr as appropriate."""