def test_save_context(self): graph = set() ident_uri = 'http://example.com/context_1' ctx = Context(ident=ident_uri) for i in range(5): ctx.add_statement(create_mock_statement(ident_uri, i)) ctx.save_context(graph) self.assertEqual(len(graph), 5)
def test_triples_saved_noundef_triples_counted(self): graph = set() ident_uri = 'http://example.com/context_1' ctx = Context(ident=ident_uri) statement = MagicMock() statement.context.identifier = rdflib.term.URIRef(ident_uri) statement.to_triple.return_value = (Variable('var'), 1, 2) ctx.add_statement(statement) ctx.save_context(graph) self.assertEqual(ctx.triples_saved, 0)
def setUp(self): # Make the statements and evidence we will query for in the test super(EvidenceForTest, self).setUp() self.process_class(Evidence) c1 = Context(ident='http://example.org/statements', conf=self.conf) c1(Neuron)('AVAL').innexin('UNC-7') evc = Context(ident='http://example.org/metadata', conf=self.conf) ev1 = evc(Evidence)(key='js2019') ev1.supports(c1.rdf_object) # Save them c1.save_context() evc.save_context()
def test_triples_saved_multi(self): graph = set() ident_uri = 'http://example.com/context_1' ident_uri1 = 'http://example.com/context_11' ident_uri2 = 'http://example.com/context_12' ctx = Context(ident=ident_uri) ctx1 = Context(ident=ident_uri1) ctx2 = Context(ident=ident_uri2) ctx2.add_import(ctx) ctx1.add_import(ctx2) ctx1.add_import(ctx) ctx.add_statement(create_mock_statement(ident_uri, 1)) ctx1.add_statement(create_mock_statement(ident_uri1, 3)) ctx2.add_statement(create_mock_statement(ident_uri2, 2)) ctx1.save_context(graph, inline_imports=True) self.assertEqual(ctx1.triples_saved, 3)
def test_triples_saved(self): graph = set() ident_uri = 'http://example.com/context_1' ident_uri2 = 'http://example.com/context_2' ident_uri2_1 = 'http://example.com/context_2_1' ident_uri3 = 'http://example.com/context_3' ident_uri4 = 'http://example.com/context_4' ctx = Context(ident=ident_uri) ctx2 = Context(ident=ident_uri2) ctx2_1 = Context(ident=ident_uri2_1) ctx.add_import(ctx2) ctx.add_import(ctx2_1) ctx3 = Context(ident=ident_uri3) ctx3.add_import(ctx) last_ctx = Context(ident=ident_uri4) last_ctx.add_import(ctx3) ctx.add_statement(create_mock_statement(ident_uri, 1)) ctx2.add_statement(create_mock_statement(ident_uri2, 2)) ctx2_1.add_statement(create_mock_statement(ident_uri2_1, 2.1)) ctx3.add_statement(create_mock_statement(ident_uri3, 3)) last_ctx.add_statement(create_mock_statement(ident_uri4, 4)) last_ctx.save_context(graph, True) self.assertEqual(last_ctx.triples_saved, 5)
def test_save_context_no_graph(self): ctx = Context() with patch('owmeta_core.data.ALLOW_UNCONNECTED_DATA_USERS', False): with self.assertRaisesRegexp(Exception, r'graph'): ctx.save_context()