diff options
author | David Robillard <d@drobilla.net> | 2024-09-21 09:53:20 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-09-21 09:53:20 -0400 |
commit | ae803df657df1f9e07a90b71f26736183f98b35d (patch) | |
tree | e8991d3f6907e24748173db1f68b06f58616f315 /test/serd_test_util | |
parent | 762dbf2bd8d22230ac40136d7f1c749a46c60d7b (diff) | |
download | serd-ae803df657df1f9e07a90b71f26736183f98b35d.tar.gz serd-ae803df657df1f9e07a90b71f26736183f98b35d.tar.bz2 serd-ae803df657df1f9e07a90b71f26736183f98b35d.zip |
Factor out test runner script argument and output parsing
Diffstat (limited to 'test/serd_test_util')
-rw-r--r-- | test/serd_test_util/__init__.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/serd_test_util/__init__.py b/test/serd_test_util/__init__.py index 8027462b..ad417762 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.""" |