1
2 from rdflib import ConjunctiveGraph, Namespace, URIRef, RDF, RDFS
3 from oort.display import AspectBase, TemplateAspectBase
4 from oort.display import SubTypeAwareDisplay
5
6
7
9 dummyType = object()
10 queries = {'a': 0}
11 if maker:
12 aspect = maker(dummyType, queries)
13 else:
14 class TestAspect(AspectBase):
15 def post_init_configure(self, cfg):
16 self.cfg = cfg
17 aspect = TestAspect(dummyType, queries)
18 globalQueries = {'a': 1, 'b': 2}
19 assert aspect.forType == dummyType
20 assert aspect.queries == queries
21
22 aspect.post_init_setup(globalQueries, cfg)
23 if not maker:
24 assert aspect.cfg == cfg
25
26 assert aspect.queries == {'a': 0, 'b': 2}
27 return aspect
28
30 tbase = "TEMPLATE_BASE"
31 tname = "TEMPLATE"
32 cfg = {'templateBase': tbase}
33 def maker(forType, queries):
34 return TemplateAspectBase(forType, tname, queries)
35 aspect = test_AspectBase(cfg, maker)
36 assert aspect.templateBase == tbase
37 assert aspect.templateName == tname
38
39
40 ont = Namespace("urn:ont#")
41
43
49
51
52
53 graph = ConjunctiveGraph()
54
55 def classAndSubClass(C1, C2):
56 graph.add( (C1, RDF.type, RDFS.Class) )
57 graph.add( (C2, RDF.type, RDFS.Class) )
58 graph.add( (C2, RDFS.subClassOf, C1) )
59
60 classAndSubClass(ont.T1, ont.T2)
61 classAndSubClass(ont.T2, ont.T3)
62 classAndSubClass(ont.T3, ont.T4)
63 classAndSubClass(ont.T4, ont.T5)
64
65 item1 = URIRef("urn:item1")
66 item2 = URIRef("urn:item2")
67 item3 = URIRef("urn:item3")
68 item4 = URIRef("urn:item4")
69 item5 = URIRef("urn:item5")
70
71 graph.add( (item1, RDF.type, ont.T1) )
72 graph.add( (item2, RDF.type, ont.T2) )
73 graph.add( (item3, RDF.type, ont.T3) )
74 graph.add( (item4, RDF.type, ont.T4) )
75 graph.add( (item5, RDF.type, ont.T5) )
76
77 matchGraph = self.display.create_match_graph(graph)
78
79 def get_aspect(resource):
80 for rdfType in matchGraph.objects(resource, RDF.type):
81 return self.display.typeAspects.get(rdfType)
82
83 assert get_aspect(item1) == "T1 handler"
84 assert get_aspect(item2) == "T1 handler"
85 assert get_aspect(item3) == "T1 handler"
86 assert get_aspect(item4) == "T1 handler"
87 assert get_aspect(item5) == "T5 handler"
88