def test21_serialize(self): """Test serialize method.""" uri = URIRef('http://ex.org/ldprs') g = Graph() g.add((uri, RDF.type, URIRef('http://ex.org/some_type'))) g.add((URIRef('http://ex.org/a'), URIRef('http://ex.org/b'), Literal('LITERAL'))) r = LDPRS(uri=uri, content=g) s = r.serialize() self.assertIn('@prefix ldp: <http://www.w3.org/ns/ldp#> .', s) self.assertIn('ldprs', s) # might prefix or not self.assertIn('some_type', s) # might prefix or not self.assertIn('ldp:RDFSource', s) self.assertIn('ldp:Resource', s) self.assertIn('"LITERAL"', s) # Test omits (nothing to come out) s = r.serialize(omits=['minimal']) self.assertNotIn('ldprs', s) # might prefix or not self.assertNotIn('some_type', s) # might prefix or not self.assertNotIn('ldp:RDFSource', s) self.assertNotIn('ldp:Resource', s) self.assertNotIn('"LITERAL"', s) self.assertNotIn('"Wombat"', s) # Test extra eg = Graph() eg.add((EX.Happy, EX.Lazy, EX.Wombat)) s = r.serialize(extra=eg) self.assertIn('Wombat', s)
def test06_serialize(self): """Test some simple serialization cases.""" uri = URIRef('http://ex.org/ldprs') g = Graph() g.add((uri, RDF.type, URIRef('http://ex.org/some_type'))) g.add((URIRef('http://ex.org/a'), URIRef('http://ex.org/b'), Literal('LITERAL'))) r = LDPRS(uri=uri, content=g) s = r.serialize() self.assertIn('@prefix ldp: <http://www.w3.org/ns/ldp#> .', s) self.assertIn('ldprs', s) # might prefix or not self.assertIn('some_type', s) # might prefix or not self.assertIn('ldp:RDFSource', s) self.assertIn('ldp:Resource', s) self.assertIn('"LITERAL"', s) # s = r.serialize(omits=['content']) self.assertIn('ldprs', s) # might prefix or not self.assertNotIn('some_type', s) # might prefix or not self.assertIn('ldp:RDFSource', s) self.assertIn('ldp:Resource', s) self.assertNotIn('"LITERAL"', s)