#!/usr/bin/env python3 """Test filtering statements exclusively.""" import argparse import sys import shlex import subprocess import tempfile DOCUMENTS = { "ntriples": """ . . """, "nquads": """ . . """, } parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--tool", default="tools/serd-filter", help="executable") parser.add_argument("--wrapper", default="", help="executable wrapper") args = parser.parse_args(sys.argv[1:]) def check_pattern(syntax, pattern, result): command = shlex.split(args.wrapper) + [ args.tool, "-I", syntax, pattern, "-", ] with tempfile.TemporaryFile() as out: proc = subprocess.run( command, capture_output=True, check=False, encoding="utf-8", input=DOCUMENTS[syntax], ) assert proc.returncode == 0 assert args.wrapper or len(proc.stderr) == 0 assert proc.stdout == result check_pattern( "ntriples", "?s .", " .\n", ) check_pattern( "ntriples", " ?p .", " .\n", ) check_pattern( "ntriples", " ?o .", " .\n", ) check_pattern( "nquads", "?s .", " .\n", ) check_pattern( "nquads", " ?p .", " .\n", ) check_pattern( "nquads", " ?o .", " .\n", ) check_pattern( "nquads", " ?g .", " .\n", )