def test_contexts_combined(self): ctxid0 = URIRef('http://example.com/context_0') ctxid1 = URIRef('http://example.com/context_1') ctx = Mock() graph = Mock() graph.store.triples_choices.side_effect = [[((None, None, ctxid0), ()) ], []] ctx.rdf = graph ctx.contents_triples.return_value = () ctx.identifier = ctxid1 ctx.imports = [] store = ContextStore(ctx, include_stored=True) self.assertEqual(set([ctxid0, ctxid1]), set(store.contexts()))
def test_contexts_staged_ignores_stored(self): ctxid0 = URIRef('http://example.com/context_0') ctxid1 = URIRef('http://example.com/context_1') ctx = Mock() graph = Mock() graph.store.triples_choices.side_effect = [[((None, None, ctxid0), ()) ], []] ctx.conf = {'rdf.graph': graph} ctx.contents_triples.return_value = () ctx.identifier = ctxid1 ctx.imports = [] store = ContextStore(ctx) self.assertNotIn(ctxid0, set(store.contexts()))
def test_no_stored_length(self): ctx = Mock() graph = Mock() ctx.rdf = graph ctx.contents_triples.return_value = () ctx.imports = [] cut = ContextStore(ctx, include_stored=False) self.assertEqual(0, len(cut))
def test_len_fail(self): ctx = Mock() graph = Mock() ctx.rdf = graph ctx.contents_triples.return_value = () ctx.imports = [] store = ContextStore(ctx, include_stored=True) with self.assertRaises(NotImplementedError): len(store)
def test_query(self): rdf_type = 'http://example.org/A' ctxid = URIRef('http://example.com/context_1') ctx = Mock() graph = Mock() graph.store.triples.return_value = [((URIRef('anA0'), rdflib.RDF.type, rdf_type), (ctxid, ))] graph.store.triples_choices.return_value = [] ctx.rdf = graph ctx.contents_triples.return_value = [(URIRef('anA'), rdflib.RDF.type, rdf_type)] ctx.identifier = ctxid ctx.imports = [] store = ContextStore(ctx, include_stored=True) self.assertEqual( set([URIRef('anA'), URIRef('anA0')]), set(x[0][0] for x in store.triples((None, rdflib.RDF.type, rdf_type))))
def test_init_imports(self): ctx = Mock() m = Mock() m.identifier = 'blah' ctx.imports = [m, m] m.imports = [] ctx.contents_triples.return_value = () m.contents_triples.return_value = [('a', 'b', 'c')] with patch('owmeta_core.context_store.RDFContextStore'): ContextStore(ctx, include_stored=True) m.contents_triples.assert_called()
def test_contexts_of_unopened_database(self): cut = ContextStore(None, include_stored=True) with self.assertRaises(ContextStoreException): list(cut.contexts(None))
def test_length_of_unopened_database(self): cut = ContextStore(None, include_stored=True) with self.assertRaises(ContextStoreException): len(cut)