diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/earl.py | 42 | ||||
-rw-r--r-- | test/manifest.py | 8 | ||||
-rw-r--r-- | test/test_dawg.py | 52 | ||||
-rw-r--r-- | test/test_nquads_w3c.py | 13 | ||||
-rw-r--r-- | test/test_nt_w3c.py | 13 | ||||
-rw-r--r-- | test/test_trig_w3c.py | 13 | ||||
-rw-r--r-- | test/test_turtle_w3c.py | 13 | ||||
-rw-r--r-- | test/testutils.py | 49 |
8 files changed, 144 insertions, 59 deletions
diff --git a/test/earl.py b/test/earl.py new file mode 100644 index 00000000..ebd0b038 --- /dev/null +++ b/test/earl.py @@ -0,0 +1,42 @@ +from datetime import datetime +from rdflib import Graph, URIRef, Literal, BNode, RDF, Namespace +from rdflib.namespace import FOAF, DOAP, DC + +EARL = Namespace("http://www.w3.org/ns/earl#") + +report = Graph() + +report.bind('foaf', FOAF) +report.bind('earl', EARL) +report.bind('doap', DOAP) +report.bind('dc', DC) + +rdflib = URIRef('https://github.com/RDFLib/rdflib') + +report.add((rdflib, DOAP.homepage, rdflib)) +report.add((rdflib, DOAP.name, Literal("rdflib"))) +report.add((rdflib, RDF.type, DOAP.Project)) + +me = URIRef('http://gromgull.net/me') +report.add((me, RDF.type, FOAF.Person)) +report.add((me, FOAF.homepage, URIRef("http://gromgull.net"))) +report.add((me, FOAF.name, Literal("Gunnar Aastrand Grimnes"))) + +now = Literal(datetime.now()) + +def add_test(test, res, info=None): + a = BNode() + report.add((a, RDF.type, EARL.Assertion)) + report.add((a, EARL.assertedBy, me)) + report.add((a, EARL.test, test)) + report.add((a, EARL.subject, rdflib)) + + report.add((a, DC.date, now)) + + r = BNode() + report.add((a, EARL.result, r)) + report.add((r, RDF.type, EARL.TestResult)) + + report.add((r, EARL.outcome, EARL[res])) + if info: + report.add((r, EARL.info, Literal(info))) diff --git a/test/manifest.py b/test/manifest.py index 730bee09..03ea08f7 100644 --- a/test/manifest.py +++ b/test/manifest.py @@ -13,7 +13,7 @@ DAWG = Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#') RDFTest = namedtuple('RDFTest', ['uri', 'name', 'comment', 'data', 'graphdata', 'action', 'result', 'syntax']) -def read_manifest(f, legacy=False): +def read_manifest(f, base=None, legacy=False): def _str(x): if x is not None: @@ -21,7 +21,7 @@ def read_manifest(f, legacy=False): return None g = Graph() - g.load(f, format='turtle') + g.load(f, publicID=base, format='turtle') for m in g.subjects(RDF.type, MF.Manifest): @@ -123,7 +123,7 @@ def read_manifest(f, legacy=False): res, syntax) @nottest -def nose_tests(testers, manifest, legacy=False): - for _type, test in read_manifest(manifest, legacy): +def nose_tests(testers, manifest, base=None, legacy=False): + for _type, test in read_manifest(manifest, base, legacy): if _type in testers: yield testers[_type], test diff --git a/test/test_dawg.py b/test/test_dawg.py index c88b8af6..7f12ab2c 100644 --- a/test/test_dawg.py +++ b/test/test_dawg.py @@ -30,7 +30,7 @@ import isodate from rdflib import ( - Dataset, Graph, Namespace, RDF, URIRef, BNode, Literal) + Dataset, Graph, URIRef, BNode) from rdflib.query import Result from rdflib.compare import isomorphic @@ -57,6 +57,7 @@ else: from io import BytesIO from manifest import nose_tests, MF, UP +from earl import report, add_test def eq(a,b,msg): return eq_(a,b,msg+': (%r!=%r)'%(a,b)) @@ -102,9 +103,6 @@ DETAILEDASSERT = True # DETAILEDASSERT=False -DOAP = Namespace('http://usefulinc.com/ns/doap#') -FOAF = Namespace('http://xmlns.com/foaf/0.1/') -EARL = Namespace("http://www.w3.org/ns/earl#") NAME = None @@ -114,19 +112,8 @@ errors = Counter() failed_tests = [] error_tests = [] -EARL_REPORT = Graph() -rdflib_sparql = URIRef('https://github.com/RDFLib/rdflib-sparql') - -EARL_REPORT.add((rdflib_sparql, DOAP.homepage, rdflib_sparql)) -EARL_REPORT.add((rdflib_sparql, DOAP.name, Literal("rdflib_sparql"))) -EARL_REPORT.add((rdflib_sparql, RDF.type, DOAP.Project)) - -me = URIRef('http://gromgull.net/me') -EARL_REPORT.add((me, RDF.type, FOAF.Person)) -EARL_REPORT.add((me, FOAF.homepage, URIRef("http://gromgull.net"))) -EARL_REPORT.add((me, FOAF.name, Literal("Gunnar Aastrand Grimnes"))) try: skiptests = dict([(URIRef(x.strip().split( @@ -538,21 +525,6 @@ def test_dawg(): resetFlags() -def earl(test, res, info=None): - a = BNode() - EARL_REPORT.add((a, RDF.type, EARL.Assertion)) - EARL_REPORT.add((a, EARL.assertedBy, me)) - EARL_REPORT.add((a, EARL.test, test)) - EARL_REPORT.add((a, EARL.subject, rdflib_sparql)) - - r = BNode() - EARL_REPORT.add((a, EARL.result, r)) - EARL_REPORT.add((r, RDF.type, EARL.TestResult)) - - EARL_REPORT.add((r, EARL.outcome, EARL[res])) - if info: - EARL_REPORT.add((r, EARL.info, Literal(info))) - if __name__ == '__main__': @@ -574,26 +546,24 @@ if __name__ == '__main__': continue i += 1 try: - if _type not in testers: - raise SkipTest('unknown type: '+_type) # unknown type - f = testers[_type] - f(t) - earl(t[0], "passed") + _type(t) + + add_test(t[0], "passed") success += 1 except SkipTest, e: msg = skiptests.get(t[0], e.message) - earl(t[0], "untested", msg) + add_test(t[0], "untested", msg) print "skipping %s - %s" % (t[0], msg) skip += 1 except KeyboardInterrupt: raise except AssertionError: - earl(t[0], "failed") + add_test(t[0], "failed") except: - earl(t[0], "failed", "error") + add_test(t[0], "failed", "error") import traceback traceback.print_exc() sys.stderr.write("%s\n" % t[0]) @@ -646,8 +616,8 @@ if __name__ == '__main__': now, i, success, f, e, skip, 100. * success / i)) tf.close() - earl_report = 'test_reports/earl_%s.ttl' % now + earl_report = 'test_reports/rdflib_sparql-%s.ttl' % now - EARL_REPORT.serialize(earl_report, format='n3') - EARL_REPORT.serialize('test_reports/earl_latest.ttl', format='n3') + report.serialize(earl_report, format='n3') + report.serialize('test_reports/rdflib_sparql-latest.ttl', format='n3') print "Wrote EARL-report to '%s'" % earl_report diff --git a/test/test_nquads_w3c.py b/test/test_nquads_w3c.py index 9c897cec..7b873519 100644 --- a/test/test_nquads_w3c.py +++ b/test/test_nquads_w3c.py @@ -4,6 +4,7 @@ test suite.""" from rdflib import Graph from manifest import nose_tests, RDFT +from testutils import nose_tst_earl_report def nquads(test): g = Graph() @@ -21,10 +22,18 @@ testers = { RDFT.TestNQuadsNegativeSyntax: nquads } -def test_nquads(): +def test_nquads(tests = None): for t in nose_tests(testers, 'test/w3c/nquads/manifest.ttl'): + if tests: + for test in tests: + if test in t[1].uri: break + else: + continue + yield t if __name__ == '__main__': - pass + verbose = True + + nose_tst_earl_report(test_nquads, 'rdflib_nquads') diff --git a/test/test_nt_w3c.py b/test/test_nt_w3c.py index 5cbbff19..5659d699 100644 --- a/test/test_nt_w3c.py +++ b/test/test_nt_w3c.py @@ -4,6 +4,7 @@ test suite.""" from rdflib import Graph from manifest import nose_tests, RDFT +from testutils import nose_tst_earl_report def nt(test): g = Graph() @@ -21,10 +22,18 @@ testers = { RDFT.TestNTriplesNegativeSyntax: nt } -def test_nt(): +def test_nt(tests=None): for t in nose_tests(testers, 'test/w3c/nt/manifest.ttl', legacy=True): + if tests: + for test in tests: + if test in t[1].uri: break + else: + continue + yield t if __name__ == '__main__': - pass + verbose = True + + nose_tst_earl_report(test_nt, 'rdflib_nt') diff --git a/test/test_trig_w3c.py b/test/test_trig_w3c.py index aed425e0..31049ee2 100644 --- a/test/test_trig_w3c.py +++ b/test/test_trig_w3c.py @@ -4,6 +4,7 @@ from rdflib import Graph from manifest import nose_tests, RDFT +from testutils import nose_tst_earl_report def trig(test): @@ -22,10 +23,18 @@ testers = { RDFT.TestTrigNegativeSyntax: trig } -def test_trig(): +def test_trig(tests): for t in nose_tests(testers, 'test/w3c/trig/manifest.ttl'): + if tests: + for test in tests: + if test in t[1].uri: break + else: + continue + yield t if __name__ == '__main__': - pass + verbose = True + + nose_tst_earl_report(test_trig, 'rdflib_trig') diff --git a/test/test_turtle_w3c.py b/test/test_turtle_w3c.py index c008e55c..52c4d619 100644 --- a/test/test_turtle_w3c.py +++ b/test/test_turtle_w3c.py @@ -4,7 +4,9 @@ test suite.""" from rdflib import Graph from rdflib.namespace import split_uri from rdflib.compare import graph_diff, isomorphic + from manifest import nose_tests, RDFT +from testutils import nose_tst_earl_report verbose = False @@ -51,7 +53,8 @@ testers = { } def test_turtle(tests = None): - for t in nose_tests(testers, 'test/w3c/turtle/manifest.ttl'): + for t in nose_tests(testers, + 'test/w3c/turtle/manifest.ttl'): if tests: for test in tests: if test in t[1].uri: break @@ -65,10 +68,4 @@ if __name__ == '__main__': verbose = True - from optparse import OptionParser - p = OptionParser() - (options, args) = p.parse_args() - - for t in test_turtle(args): - print 'Running ', t[1].uri - t[0](t[1]) + nose_tst_earl_report(test_turtle, 'rdflib_turtle') diff --git a/test/testutils.py b/test/testutils.py index ce130af2..7c3b487f 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -1,6 +1,15 @@ +import sys +import isodate +import datetime + +from traceback import print_exc +from unittest import SkipTest +from earl import add_test, report + from rdflib import BNode, Graph, ConjunctiveGraph + # TODO: make an introspective version (like this one) of # rdflib.graphutils.isomorphic and use instead. def crapCompare(g1, g2): @@ -47,3 +56,43 @@ def _parse_or_report(verbose, graph, *args, **kwargs): print "Error in parsing serialization:" print args, kwargs raise + + +def nose_tst_earl_report(generator, earl_report_name=None): + from optparse import OptionParser + p = OptionParser() + (options, args) = p.parse_args() + + skip = 0 + tests = 0 + success = 0 + + for t in generator(args): + tests += 1 + print 'Running ', t[1].uri + try: + t[0](t[1]) + add_test(t[1].uri, "passed") + success += 1 + except SkipTest, e: + add_test(t[1].uri, "untested", e.message) + print "skipping %s - %s" % (t[1].uri, e.message) + skip += 1 + + except KeyboardInterrupt: + raise + except AssertionError: + add_test(t[1].uri, "failed") + except: + add_test(t[1].uri, "failed", "error") + print_exc() + sys.stderr.write("%s\n" % t[1].uri) + + print "Ran %d tests, %d skipped, %d failed. "%(tests, skip, tests-skip-success) + if earl_report_name: + now = isodate.datetime_isoformat(datetime.datetime.utcnow()) + earl_report = 'test_reports/%s-%s.ttl' % (earl_report_name, now) + + report.serialize(earl_report, format='n3') + report.serialize('test_reports/%s-latest.ttl'%earl_report_name, format='n3') + print "Wrote EARL-report to '%s'" % earl_report |