Changeset 7fd30c1 in serd


Ignore:
Timestamp:
Sep 24, 2017, 12:45:38 PM (8 weeks ago)
Author:
David Robillard <d@…>
Branches:
master, serd1
Children:
9dd64d0
Parents:
3d05616
Message:

Remove test suite rdflib dependency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wscript

    r3d05616 r7fd30c1  
    302302
    303303def test_suite(ctx, srcdir, base, testdir, report, isyntax, osyntax):
    304     import rdflib
    305304    import itertools
    306305
    307     earl = rdflib.Namespace('http://www.w3.org/ns/earl#')
    308     mf   = rdflib.Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
    309     rdf  = rdflib.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
    310 
     306    def load_rdf(filename):
     307        "Load an RDF file into python dictionaries via serdi.  Only supports URIs."
     308        import subprocess
     309        import re
     310        model = {}
     311        proc  = subprocess.Popen(['./serdi_static', filename], stdout=subprocess.PIPE)
     312        for line in proc.communicate()[0].splitlines():
     313            matches = re.match('<([^ ]*)> <([^ ]*)> <([^ ]*)> \.', line)
     314            if matches:
     315                if matches.group(1) not in model:
     316                    model[matches.group(1)] = {}
     317                if matches.group(2) not in model[matches.group(1)]:
     318                    model[matches.group(1)][matches.group(2)] = []
     319                model[matches.group(1)][matches.group(2)] += [matches.group(3)]
     320        return model
     321
     322    mf = 'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#'
    311323    base_uri = os.path.join(base, testdir, '')
    312     model = rdflib.ConjunctiveGraph()
    313     model.parse(os.path.join(srcdir, 'tests', testdir, 'manifest.ttl'),
    314                 rdflib.URIRef(base_uri + 'manifest.ttl'),
    315                 format='n3')
     324    model = load_rdf(os.path.join(srcdir, 'tests', testdir, 'manifest.ttl'))
    316325
    317326    asserter = ''
     
    328337
    329338    def run_tests(test_class, expected_return):
    330         tests = sorted(model.triples([None, rdf.type, test_class]))
     339        tests = []
     340        for s, desc in model.iteritems():
     341            if str(test_class) in desc['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']:
     342                tests += [s]
    331343        if len(tests) == 0:
    332344            return
    333345
    334346        with autowaf.begin_tests(ctx, APPNAME, str(test_class)):
    335             for (num, i) in enumerate(tests):
    336                 test        = i[0]
    337                 action_node = model.value(test, mf.action, None)
    338                 output_node = model.value(test, mf.result, None)
     347            for (num, test) in enumerate(tests):
     348                action_node = model[test][mf + 'action'][0]
    339349                action      = os.path.join('tests', testdir, os.path.basename(action_node))
    340350                abs_action  = os.path.join(srcdir, action)
     
    345355                # Run strict test
    346356                result = run_test(command, expected_return, action)
    347                 if output_node:
     357                if (mf + 'result') in model[test]:
    348358                    # Check output against test suite
    349                     output_rel = output_node[len(base_uri):]
    350                     check_path = os.path.join(srcdir, 'tests', testdir, output_rel)
     359                    check_path = model[test][mf + 'result'][0][len('file://'):]
    351360                    result     = autowaf.run_test(
    352361                        ctx, APPNAME,
     
    369378
    370379    def test_types():
    371         rdft = rdflib.Namespace('http://www.w3.org/ns/rdftest#')
    372380        types = []
    373381        for lang in ['Turtle', 'NTriples', 'Trig', 'NQuads']:
    374             types += [[rdft['Test%sPositiveSyntax' % lang], 0],
    375                       [rdft['Test%sNegativeSyntax' % lang], 1],
    376                       [rdft['Test%sNegativeEval' % lang], 1],
    377                       [rdft['Test%sEval' % lang], 0]]
     382            types += [['http://www.w3.org/ns/rdftest#Test%sPositiveSyntax' % lang, 0],
     383                      ['http://www.w3.org/ns/rdftest#Test%sNegativeSyntax' % lang, 1],
     384                      ['http://www.w3.org/ns/rdftest#Test%sNegativeEval' % lang, 1],
     385                      ['http://www.w3.org/ns/rdftest#Test%sEval' % lang, 0]]
    378386        return types
    379387
     
    382390
    383391def test(ctx):
    384     try:
    385         import rdflib
    386     except:
    387         Logs.error('error: python rdflib is required to run tests')
    388         return
     392    "runs test suite"
    389393
    390394    # Create test output directories
Note: See TracChangeset for help on using the changeset viewer.