def test_contents_triples(self): res_wanted = [] ident_uri = 'http://example.com/context_1' ctx = Context(ident=ident_uri) for i in range(5): stmt = create_mock_statement(ident_uri, i) ctx.add_statement(stmt) res_wanted.append(stmt.to_triple()) for triples in ctx.contents_triples(): self.assertTrue(triples in res_wanted)
def test_adhoc_datatype_property_in_context(self): class A(DataObject): a = DatatypeProperty() class B(DataObject): pass ctx = Context(ident='http://example.org/geogia') b = ctx(B)(key='b') A.a(b)('square') self.assertIn((R.URIRef('http://data.openworm.org/B#b'), R.URIRef('http://schema.openworm.org/2020/07/A/a'), R.Literal('square')), list(ctx.contents_triples()))
def test_adhoc_union_property_in_context(self): class A(DataObject): a = UnionProperty() class B(DataObject): pass ctx = Context(ident='http://example.org/wisconsin') b = ctx(B)(key='b') A.a(b)(A(key='a')) self.assertIn((R.URIRef('http://data.openworm.org/B#b'), R.URIRef('http://schema.openworm.org/2020/07/A/a'), R.URIRef('http://data.openworm.org/A#a')), list(ctx.contents_triples()))
def test_inverse_property_context(self): class A(DataObject): unmapped = True def __init__(self, **kwargs): super(A, self).__init__(**kwargs) self.a = A.ObjectProperty(value_type=B) class B(DataObject): unmapped = True def __init__(self, **kwargs): super(B, self).__init__(**kwargs) self.b = B.ObjectProperty(value_type=A) InverseProperty(B, 'b', A, 'a') ctx1 = Context(ident='http://example.org/context_1') ctx2 = Context(ident='http://example.org/context_2') a = ctx1(A)(ident='a') b = ctx2(B)(ident='b') a.a(b) expected = (URIRef('b'), B.schema_namespace['b'], URIRef('a')) self.assertIn(expected, list(ctx1.contents_triples()))