aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-06 20:39:05 +0200
committerDavid Robillard <d@drobilla.net>2018-11-25 22:12:47 +0100
commitf5e1b264ae4098d4edd70604d57adb60abbed224 (patch)
treed51ad0cb65cf95d34c5238ca82e9bbeed581ca6e
parenta160d532d7c7c2e210fe93c956f5b2b8305242e1 (diff)
downloadserd-f5e1b264ae4098d4edd70604d57adb60abbed224.tar.gz
serd-f5e1b264ae4098d4edd70604d57adb60abbed224.tar.bz2
serd-f5e1b264ae4098d4edd70604d57adb60abbed224.zip
Factor out some generic test suite running code
-rw-r--r--wscript95
1 files changed, 52 insertions, 43 deletions
diff --git a/wscript b/wscript
index 1a7fa8d9..cb978265 100644
--- a/wscript
+++ b/wscript
@@ -333,27 +333,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'))
@@ -371,10 +378,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
@@ -431,6 +435,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"
@@ -510,29 +541,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)