def test_diff_prop_same_name_same_object_diff_value_same_id(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) c = DataObject.DatatypeProperty("boots", do) c1 = DataObject.DatatypeProperty("boots", do) c('partition') c1('join') self.assertEqual(c.identifier, c1.identifier)
def test_asserts_query_multiple(self): """ Show that setting the evidence with distinct objects yields distinct results """ r = DataObject(key='relationship') ar = DataObject(key='aref') br = DataObject(key='bref') e = self.ctx.Evidence(key="a", reference=ar) e.supports(r) self.save() e1 = self.ctx.Evidence(key="b", reference=br) e1.supports(r) self.save() e0 = self.ctx.Evidence() e0.supports(r) for x in e0.load(): lar = x.reference.one() lbr = x.reference.one() # Testing that either a has a result [email protected] and y has nothing or # y has a result 1999 and a has nothing if x.idl == e1.idl: self.assertEqual(lbr.identifier, br.identifier) elif x.idl == e.idl: self.assertEqual(lar.identifier, ar.identifier) else: self.fail("Unknown object returned from load")
def test_diff_value_diff_id_equal(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do1 = self.ctx.DataObject(ident=R.URIRef("http://example.org")) c = DataObject.DatatypeProperty("boots", do) c1 = DataObject.DatatypeProperty("boots", do1) do.boots('join') do1.boots('partition') self.assertEqual(c.identifier, c1.identifier)
def test_cls_object_from_id_type(self): ''' Calling object_from_id on the class should search for the rdf_type ''' ctx = Mock() DataObject.contextualize(ctx).object_from_id( 'http://openworm.org/some_rdf_type') ctx.resolve_class.assert_called()
def test_same_value_same_id_not_empty_object_property(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do1 = self.ctx.DataObject(ident=R.URIRef("http://example.org")) dz = self.ctx.DataObject(ident=R.URIRef("http://example.org/vip")) dz1 = self.ctx.DataObject(ident=R.URIRef("http://example.org/vip")) c = DataObject.ObjectProperty("boots", do) c1 = DataObject.ObjectProperty("boots", do1) do.boots(dz) do1.boots(dz1) self.assertEqual(c.identifier, c1.identifier)
def test_diff_value_insert_order_same_id(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do1 = self.ctx.DataObject(ident=R.URIRef("http://example.org")) print(list(self.context.contents_triples())) c = DataObject.DatatypeProperty("boots", do, multiple=True) c1 = DataObject.DatatypeProperty("boots", do1, multiple=True) do.boots('join') do.boots('simile') do.boots('partition') do1.boots('partition') do1.boots('join') do1.boots('simile') self.assertEqual(c.identifier, c1.identifier)
def test_statements_staged(self): ''' Statements have the Context included as a regular attribute, so we don't filter by the property's current context. The property's `rdf` attribute evals to the context's staged graph, so we get an "extra" entry from the context ''' do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) ctx = Context('http://example.org/ctx/') do.birds = DataObject.DatatypeProperty(multiple=True) ctx(do).birds(4) do.birds(5) stmts = list(do.birds.statements) for s in stmts: print(s.to_quad()) # Split up into 3 asserts so you can actually read pytest' error print-out... assert stmts[0] == Statement(do, do.birds, PropertyValue(R.Literal(4)), ctx) assert stmts[1] == Statement(do, do.birds, PropertyValue(R.Literal(5)), self.context) # These statements are not actually equal because statements mints a new Context # for what it retrieves from the RDF graph (it has to) assert stmts[2].to_quad() == Statement(do, do.birds, PropertyValue(R.Literal(5)), self.context).to_quad()
def test_asserts(self): """ Asserting something should allow us to get it back. """ e = self.ctx.Evidence(key='WBPaper00044600') r = DataObject(key="context_data_object") e.supports(r) s = list(e.supports.get()) self.assertIn(r, s)
def test_property_get_returns_collection(self): """ This is for issue #175. """ do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do.boots = DataObject.DatatypeProperty(multiple=True) do.boots(4) # self.save() do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do.boots = DataObject.DatatypeProperty(multiple=True) x = do.boots() l1 = list(x) print(l1) b = list(x) self.assertEqual([4], b)
def test_asserts_query(self): """ Show that we can store the evidence on an object and later retrieve it """ e = self.ctx.Evidence(key="a") r = DataObject(key="relationship") e.supports(r) self.save() e0 = self.ctx.Evidence() e0.supports(r) s = list(e0.load_terms()) self.assertIn(e.identifier, s)
def test_object_property_diff_value_insert_order_same_id(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do1 = self.ctx.DataObject(ident=R.URIRef("http://example.org")) oa = self.ctx.DataObject(ident=R.URIRef("http://example.org/a")) ob = self.ctx.DataObject(ident=R.URIRef("http://example.org/b")) oc = self.ctx.DataObject(ident=R.URIRef("http://example.org/c")) c = DataObject.ObjectProperty("boots", do, multiple=True) c1 = DataObject.ObjectProperty("boots", do1, multiple=True) do.boots(oa) do.boots(ob) do.boots(oc) do1.boots(oc) do1.boots(oa) do1.boots(ob) self.assertEqual(c.identifier, c1.identifier)
def setUp(self): super(Issue211EvidenceTest, self).setUp() self.e1 = self.ctx.Evidence() self.e2 = self.ctx.Evidence() c = DataObject(key='23') self.e1.supports(c) self.e2.supports(c) self.evs = self.context.stored(Evidence)() self.evs.supports(c) self.expected_ids = set(['777', '888'])
def test_defined_statements_across_contexts_datatype_property(self): ''' Statements have the Context included as a regular attribute, so we don't filter by the property's current context ''' do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) ctx = Context('http://example.org/ctx/') do.birds = DataObject.DatatypeProperty(multiple=True) ctx(do).birds(4) do.birds(5) stmts = list(ctx(do).birds.defined_statements) assert stmts == [ Statement(do, do.birds, PropertyValue(R.Literal(4)), ctx), Statement(do, do.birds, PropertyValue(R.Literal(5)), self.context) ]
def test_defined_statements_across_contexts_object_property(self): ''' Statements have the Context included as a regular attribute, so we don't filter by the property's current context ''' do = self.ctx.DataObject(ident=R.URIRef("http://example.org/1")) ctx = Context('http://example.org/ctx/') do.bugs = DataObject.ObjectProperty(multiple=True) dp = self.ctx.DataObject(ident=R.URIRef("http://example.org/2")) ctx(do).bugs(do) do.bugs(dp) stmts = list(ctx(do).bugs.defined_statements) assert stmts == [ Statement(do, do.bugs, do, ctx), Statement(do, do.bugs, dp, self.context) ]
def test_statements_query_empty(self): ''' Statements have the Context included as a regular attribute, so we don't filter by the property's current context. The property's `rdf` attribute evals to the context's staged graph, so we get an "extra" entry from the context ''' do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) ctx = Context('http://example.org/ctx/') do.birds = DataObject.DatatypeProperty(multiple=True) ctx(do).birds(4) do.birds(5) stmts = list(Context('http://example.org/ctx/')(do).birds.statements) assert stmts == [ Statement(do, do.birds, PropertyValue(R.Literal(4)), ctx), Statement(do, do.birds, PropertyValue(R.Literal(5)), self.context) ]
def test_context_setter(self): a = DataObject() a.context = 42 self.assertEquals(a.context, 42)
def test_rdfs_comment_property(self): a = DataObject(rdfs_comment='Hello') self.assertIn('Hello', a.rdfs_comment())
def test_context_getter(self): a = DataObject() self.assertIsNone(a.context)
def test_DataUser(self): do = DataObject() self.assertTrue(isinstance(do, DataUser))
def test_identifier(self): """ Test that we can set and return an identifier """ do = DataObject(ident="http://example.org") self.assertEqual(do.identifier, R.URIRef("http://example.org"))
def test_same_value_same_id_empty(self): do = self.ctx.DataObject(ident=R.URIRef("http://example.org")) do1 = self.ctx.DataObject(ident=R.URIRef("http://example.org")) c = DataObject.DatatypeProperty("boots", do) c1 = DataObject.DatatypeProperty("boots", do1) self.assertEqual(c.identifier, c1.identifier)
def test_repr(self): self.assertRegexpMatches( repr(DataObject(ident="http://example.com")), r"DataObject\(ident=rdflib\.term\.URIRef\(" r"u?[\"']http://example.com[\"']\)\)")
def test_references(self): self.e1.reference(DataObject(ident='777')) self.e2.reference(DataObject(ident='888')) self.save() loaded_ids = set(str(x.identifier) for x in self.evs.reference.get()) self.assertTrue(self.expected_ids.issubset(loaded_ids))