aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_multifile.py
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-05-05 16:12:38 +0200
committerDavid Robillard <d@drobilla.net>2022-01-13 23:05:24 -0500
commitb98bd7a32cf4302e0a210dd8558edd3ab2088525 (patch)
tree5f4960229abe31fab1683341609fe37319a49a91 /test/test_multifile.py
parentf7d10ea309fb52d09a58b2832fe4a09a120b16aa (diff)
downloadserd-b98bd7a32cf4302e0a210dd8558edd3ab2088525.tar.gz
serd-b98bd7a32cf4302e0a210dd8558edd3ab2088525.tar.bz2
serd-b98bd7a32cf4302e0a210dd8558edd3ab2088525.zip
Add support for reading multiple files at once
Diffstat (limited to 'test/test_multifile.py')
-rwxr-xr-xtest/test_multifile.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/test_multifile.py b/test/test_multifile.py
new file mode 100755
index 00000000..5fb44bc5
--- /dev/null
+++ b/test/test_multifile.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+"""Test reading from several input files."""
+
+import argparse
+import difflib
+import os
+import shlex
+import subprocess
+import sys
+import tempfile
+
+parser = argparse.ArgumentParser(description=__doc__)
+
+parser.add_argument("--serdi", default="./serdi", help="path to serdi")
+parser.add_argument("--wrapper", default="", help="executable wrapper")
+parser.add_argument("testdir", help="multifile test directory")
+
+args = parser.parse_args(sys.argv[1:])
+in1_path = os.path.join(args.testdir, "input1.ttl")
+in2_path = os.path.join(args.testdir, "input2.trig")
+check_path = os.path.join(args.testdir, "output.nq")
+command = shlex.split(args.wrapper) + [args.serdi, in1_path, in2_path]
+
+
+def _show_diff(from_lines, to_lines, from_filename, to_filename):
+ same = True
+ for line in difflib.unified_diff(
+ from_lines,
+ to_lines,
+ fromfile=os.path.abspath(from_filename),
+ tofile=os.path.abspath(to_filename),
+ ):
+ sys.stderr.write(line)
+ same = False
+
+ return same
+
+
+with tempfile.TemporaryFile(mode="w+", encoding="utf-8") as out:
+ proc = subprocess.run(command, check=False, stdout=out)
+
+ assert proc.returncode == 0
+
+ out.seek(0)
+ with open(check_path, "r", encoding="utf-8") as check:
+
+ output_matches = _show_diff(
+ check.readlines(), out.readlines(), check_path, "output"
+ )
+
+ assert output_matches