def test_mutate_dataset(self): data = dataset.Dataset() data.triple(self.sub, self.pred, self.obj) data.triple(self.sub, self.pred, rdfuri.Literal("literal data2", "xs:string")) data.triple(self.sub, self.pred, rdfuri.Literal("literal data3", "xs:string")) dgraphapi.mutate_add_dataset(data)
def test_send(self): dgraphapi.drop_all() data = dataset.Dataset() batch_consumer = consumer.BatchConsumer(data) data.triple(self.sub, self.pred, self.obj) data.triple(self.sub, self.pred, rdfuri.Literal("literal data2", "xs:string")) result = batch_consumer.send() self.assertFalse(data)
def test_formatter(self): data = dataset.Dataset() data.triple(self.sub, self.pred, self.obj) data.triple(self.sub, self.pred, rdfuri.Literal("literal data2", "xs:string")) data.triple(self.sub, self.pred, rdfuri.Literal("literal data3", "xs:string")) data.lookup_nodes() print(data.formatter.to_rdf())
def test_lookup_nodes(self): rdfuri.NodeRegistryMeta.clear_registry(rdfuri.NodeType.XID) data = dataset.Dataset() data.triple(self.sub2, self.pred, self.obj) data.triple(self.sub2, self.pred, self.obj) data.triple(self.sub2, self.pred, self.obj) self.assertFalse(data.are_nodes_set()) data.lookup_nodes() self.assertTrue(data.are_nodes_set())
def test_triple(self): data = dataset.Dataset() data.triple(self.sub, self.pred, self.obj) self.assertTrue(self.obj in data[self.sub][self.pred]) self.assertTrue(self.sub in data.keys()) self.assertTrue(self.pred in data[self.sub].keys()) data.triple(self.sub, self.pred, self.obj) self.assertTrue(len(data[self.sub][self.pred]) == 2) pprint.pprint(data.triples())
def test_batch(self): dgraphapi.drop_all() data = dataset.Dataset() processor = batcher.BatchProcessor(data, batch_size=10) batch_count = 0 for i in range(1, 100): data.triple(self.sub, self.pred, rdfuri.Literal("literal data-%s" % i, "xs:string")) processor.increment() if processor.count == 0: batch_count += 1 self.assertTrue(batch_count > 4)
def test_clear(self): data = dataset.Dataset() data.triple(self.sub, self.pred, self.obj) data.triple(self.sub, self.pred, rdfuri.Literal("literal data2", "xs:string")) data.triple(self.sub, self.pred, rdfuri.Literal("literal data3", "xs:string")) data.triple(self.sub, self.pred2, self.obj) data.triple(self.sub2, self.pred, self.obj) data.triple(self.sub2, self.pred, rdfuri.Literal("literal data2", "xs:string")) data.triple(self.sub2, self.pred, rdfuri.Literal("literal data3", "xs:string")) data.triple(self.sub2, self.pred2, self.obj) data.clear()
def __init__(self, sink=None, use_tracker=False, tracker=None, use_batcher=False, batcher=None): if not sink: sink = dataset.Dataset() super().__init__(sink) self.tracker = None if use_tracker or tracker: if tracker: self.tracker = tracker else: self.tracker = Tracker() if use_batcher or batcher: if batcher: self.batcher = batcher else: self.batcher = BatchProcessor(sink)
def test_init(self): data = dataset.Dataset() processor = batcher.BatchProcessor(data) # test default destination function self.assertEqual(processor.batch_consumer.destination, dgraphapi.mutate_add_dataset)
def test_init(self): data = dataset.Dataset() batch_consumer = consumer.BatchConsumer(data) # test default destination function self.assertEqual(batch_consumer.destination, dgraphapi.mutate_add_dataset)
def test_are_nodes_set(self): data = dataset.Dataset() data.triple(self.sub, self.pred, self.obj) self.assertFalse(data.are_nodes_set())
def test_parse_error_normal(self): parser = ntparse.NtParser(dataset.Dataset()) fo = open(self.error_data_file, "rb") data = parser.parse(fo) fo.close() self.assertTrue(data.triples())