summaryrefslogtreecommitdiff
path: root/test/earl.py
blob: 9e4d041337990cdef758a79d5020f4caddcd7202 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from datetime import datetime

from rdflib import Graph, URIRef, Literal, BNode, RDF, Namespace
from rdflib.namespace import FOAF, DOAP, DC

from nose.tools import nottest

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)

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")))

rdflib = URIRef('https://github.com/RDFLib/rdflib')

report.add((rdflib, DOAP.homepage, rdflib))
report.add((rdflib, DOAP.name, Literal("rdflib")))
report.add((rdflib, DOAP.developer, me))
report.add((rdflib, RDF.type, DOAP.Project))

now = Literal(datetime.now())


@nottest
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)))