#!/usr/bin/env python3

"""Test filtering statements."""

import argparse
import sys
import shlex
import subprocess
import tempfile

DOCUMENT = """<urn:example:s> <urn:example:p> <urn:example:o> .
<urn:example:s> <urn:example:q> <urn:example:r> .
"""

parser = argparse.ArgumentParser(description=__doc__)

parser.add_argument("--serdi", default="./serdi", help="path to serdi")
parser.add_argument("--wrapper", default="", help="executable wrapper")

args = parser.parse_args(sys.argv[1:])
command = shlex.split(args.wrapper) + [
    args.serdi,
    "-g",
    "?s <urn:example:p> <urn:example:o> .",
    "-s",
    DOCUMENT,
]

with tempfile.TemporaryFile() as out:
    proc = subprocess.run(
        command,
        check=False,
        encoding="utf-8",
        input=DOCUMENT,
        capture_output=True,
    )

    assert proc.returncode == 0
    assert len(proc.stderr) == 0
    assert proc.stdout == "<urn:example:s> <urn:example:p> <urn:example:o> .\n"
