aboutsummaryrefslogtreecommitdiffstats
path: root/wscript
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-06 20:39:05 +0200
committerDavid Robillard <d@drobilla.net>2018-12-31 11:37:48 -0500
commit08bf8fdb616ed4a753cc6f0092f3dea9e520a96f (patch)
treed950df9a6767c45f6de4042da1cb60c396a21ac2 /wscript
parent03cc8153e49fcf3d075849d358e37bcd4d07446d (diff)
downloadserd-08bf8fdb616ed4a753cc6f0092f3dea9e520a96f.tar.gz
serd-08bf8fdb616ed4a753cc6f0092f3dea9e520a96f.tar.bz2
serd-08bf8fdb616ed4a753cc6f0092f3dea9e520a96f.zip
Factor out some generic test suite running code
Diffstat (limited to 'wscript')
-rw-r--r--wscript95
1 files changed, 52 insertions, 43 deletions
diff --git a/wscript b/wscript
index 86029d16..5b06b2f3 100644
--- a/wscript
+++ b/wscript
@@ -335,27 +335,34 @@ def file_uri_to_path(uri):
drive = os.path.splitdrive(path[1:])[0]
return path if not drive else path[1:]
+def load_rdf(filename):
+ "Load an RDF file into python dictionaries via serdi. Only supports URIs."
+ import subprocess
+ import re
+ model = {}
+ proc = subprocess.Popen(['./serdi_static', filename], stdout=subprocess.PIPE)
+ for line in proc.communicate()[0].splitlines():
+ matches = re.match('<([^ ]*)> <([^ ]*)> <([^ ]*)> \.', line.decode('utf-8'))
+ if matches:
+ if matches.group(1) not in model:
+ model[matches.group(1)] = {}
+ if matches.group(2) not in model[matches.group(1)]:
+ model[matches.group(1)][matches.group(2)] = []
+ model[matches.group(1)][matches.group(2)] += [matches.group(3)]
+ return model
+
+def get_resources_with_type(model, rdf_class):
+ tests = []
+ for s, desc in model.items():
+ if rdf_class in desc['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']:
+ tests += [s]
+ return tests
+
def test_suite(ctx, base_uri, testdir, report, isyntax, osyntax, options=''):
import itertools
srcdir = ctx.path.abspath()
- def load_rdf(filename):
- "Load an RDF file into python dictionaries via serdi. Only supports URIs."
- import subprocess
- import re
- model = {}
- proc = subprocess.Popen(['./serdi_static', filename], stdout=subprocess.PIPE)
- for line in proc.communicate()[0].splitlines():
- matches = re.match('<([^ ]*)> <([^ ]*)> <([^ ]*)> \.', line.decode('utf-8'))
- if matches:
- if matches.group(1) not in model:
- model[matches.group(1)] = {}
- if matches.group(2) not in model[matches.group(1)]:
- model[matches.group(1)][matches.group(2)] = []
- model[matches.group(1)][matches.group(2)] += [matches.group(3)]
- return model
-
mf = 'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#'
model = load_rdf(os.path.join(srcdir, 'tests', testdir, 'manifest.ttl'))
@@ -373,10 +380,7 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, osyntax, options=''):
return result
def run_tests(test_class, expected_return):
- tests = []
- for s, desc in model.items():
- if test_class in desc['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']:
- tests += [s]
+ tests = get_resources_with_type(model, test_class)
if len(tests) == 0:
return
@@ -433,6 +437,33 @@ def test_suite(ctx, base_uri, testdir, report, isyntax, osyntax, options=''):
for i in test_types():
run_tests(i[0], i[1])
+def run_test_suites(ctx, opts):
+ "runs all manifest-driven test suites with the given serdi options"
+
+ # Serd-specific test cases
+ serd_base = 'http://drobilla.net/sw/serd/tests/'
+ test_suite(ctx, serd_base + 'good/', 'good', None, 'Turtle', 'NTriples', opts)
+ test_suite(ctx, serd_base + 'bad/', 'bad', None, 'Turtle', 'NTriples', opts)
+
+ # Standard test suites
+ with open('earl.ttl', 'w') as report:
+ report.write('@prefix earl: <http://www.w3.org/ns/earl#> .\n'
+ '@prefix dc: <http://purl.org/dc/elements/1.1/> .\n')
+
+ with open(os.path.join(ctx.path.abspath(), 'serd.ttl')) as serd_ttl:
+ for line in serd_ttl:
+ report.write(line)
+
+ w3c_base = 'http://www.w3.org/2013/'
+ test_suite(ctx, w3c_base + 'NTriplesTests/',
+ 'NTriplesTests', report, 'NTriples', 'NTriples', opts)
+ test_suite(ctx, w3c_base + 'TurtleTests/',
+ 'TurtleTests', report, 'Turtle', 'NTriples', opts)
+ test_suite(ctx, w3c_base + 'NQuadsTests/',
+ 'NQuadsTests', report, 'NQuads', 'NQuads', opts)
+ test_suite(ctx, w3c_base + 'TriGTests/',
+ 'TriGTests', report, 'TriG', 'NQuads', opts)
+
def test(ctx):
"runs test suite"
@@ -512,29 +543,7 @@ def test(ctx):
'serdi_static "file://%s/tests/good/manifest.ttl" > /dev/full' % srcdir,
1, name='write_error')
- # Serd-specific test cases
- serd_base = 'http://drobilla.net/sw/serd/tests/'
- test_suite(ctx, serd_base + 'good/', 'good', None, 'Turtle', 'NTriples')
- test_suite(ctx, serd_base + 'bad/', 'bad', None, 'Turtle', 'NTriples')
-
- # Standard test suites
- with open('earl.ttl', 'w') as report:
- report.write('@prefix earl: <http://www.w3.org/ns/earl#> .\n'
- '@prefix dc: <http://purl.org/dc/elements/1.1/> .\n')
-
- with open(os.path.join(srcdir, 'serd.ttl')) as serd_ttl:
- for line in serd_ttl:
- report.write(line)
-
- w3c_base = 'http://www.w3.org/2013/'
- test_suite(ctx, w3c_base + 'TurtleTests/',
- 'TurtleTests', report, 'Turtle', 'NTriples')
- test_suite(ctx, w3c_base + 'NTriplesTests/',
- 'NTriplesTests', report, 'NTriples', 'NTriples')
- test_suite(ctx, w3c_base + 'NQuadsTests/',
- 'NQuadsTests', report, 'NQuads', 'NQuads')
- test_suite(ctx, w3c_base + 'TriGTests/',
- 'TriGTests', report, 'TriG', 'NQuads')
+ run_test_suites(ctx, '')
autowaf.post_test(ctx, APPNAME)