def test_set_was_generated_by(self): entity = prov.Entity("test:entity") entity.set_label("example entity") activity = prov.Activity("test:activity") activity.set_label("example activity") entity.set_was_generated_by(activity) ttl = prov.serialize(format="turtle") self.assertIsNotNone(ttl)
def test_many_get_used(self): e1 = prov.Entity("test:e1") e2 = prov.Entity("test:e2") activity = prov.Activity("test:activity") activity.set_used(e1) activity.set_used(e2) used_entities = activity.get_used() used_entities = sorted(used_entities, key=lambda entity: entity.identifier) self.assertEqual(len(used_entities), 2) self.assertEqual(used_entities[0].identifier, e1.identifier) self.assertEqual(used_entities[1].identifier, e2.identifier)
def test_fully_qualified_derivation(self): e1 = prov.Entity("test:e1") e2 = prov.Entity("test:e2") activity = prov.Activity("test:activity") derivation = e2.derivation(e1, id="test:derivation") generation = e2.generation(activity, id="test:generation") usage = activity.usage(e1, id="test:usage") derivation.set_had_generation(generation) derivation.set_had_activity(activity) derivation.set_had_usage(usage) self.assertTrue(isinstance(derivation, prov.Derivation)) self.assertTrue(isinstance(generation, prov.Generation)) self.assertTrue(isinstance(usage, prov.Usage))
def test_generation(self): entity = prov.Entity("test:entity") activity = prov.Activity("test:activity") generation = entity.generation(activity) self.assertTrue(isinstance(generation, prov.Generation))
def test_usage(self): activity = prov.Activity("test:activity") role = prov.Role("test:role") entity = prov.Entity("test:entity") usage = activity.usage(entity, role=role) self.assertTrue(isinstance(usage, prov.Usage))
def test_activity_constructor(self): activity = prov.Activity("test:activity") self.assertEqual(activity.identifier, activity.identifier)
def test_get_ended_at_time(self): activity = prov.Activity("test:activity") dt_str = "2014-05-01T00:00:00" activity.set_ended_at_time(self.get_datetime(dt_str)) dt = activity.get_ended_at_time() self.assertEqual(dt.isoformat(), dt_str)
def test_get_was_generated_by(self): entity = prov.Entity("test:e1") activity = prov.Activity("test:activity") entity.set_was_generated_by(activity) generated_by = entity.get_was_generated_by() self.assertEqual(generated_by[0].identifier, activity.identifier)
def test_get_used(self): entity = prov.Entity("test:e1") activity = prov.Activity("test:activity") activity.set_used(entity) used_entity = activity.get_used() self.assertEqual(used_entity[0].identifier, entity.identifier)
# Entities article = prov.Entity("ex:article") article.add(DCT.title, rdflib.Literal("Crime rises in cities")) dataset1 = prov.Entity("ex:dataset1") regionList = prov.Entity("ex:regionList") composition1 = prov.Entity("ex:composition1") chart1 = prov.Entity("ex:chart1") # Activities compile1 = prov.Activity("ex:compile1") compose1 = prov.Activity("ex:compose1") illustrate1 = prov.Activity("ex:illustrate1") # Usage and Generation compose1.set_used(dataset1) compose1.set_used(regionList) composition1.set_was_generated_by(compose1) illustrate1.set_used(composition1) chart1.set_was_generated_by(illustrate1)