diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/meson.build | 4 | ||||
-rw-r--r-- | test/test_grep.py | 40 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build index d364b4f2..501f8b13 100644 --- a/test/meson.build +++ b/test/meson.build @@ -88,6 +88,10 @@ if get_option('utils') args: script_args + files('bad/bad-base.ttl'), suite: ['serdi', 'options']) + test('grep', files('test_grep.py'), + args: script_args, + suite: ['serdi', 'options']) + # Inputs test('stdin', files('test_stdin.py'), diff --git a/test/test_grep.py b/test/test_grep.py new file mode 100644 index 00000000..a4c8d91c --- /dev/null +++ b/test/test_grep.py @@ -0,0 +1,40 @@ +#!/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" |