From 08bf8fdb616ed4a753cc6f0092f3dea9e520a96f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 6 Jun 2018 20:39:05 +0200 Subject: Factor out some generic test suite running code --- wscript | 95 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 43 deletions(-) (limited to 'wscript') 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: .\n' + '@prefix dc: .\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: .\n' - '@prefix dc: .\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) -- cgit v1.2.1