summaryrefslogtreecommitdiff
path: root/test/test_prettyxml.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_prettyxml.py')
-rw-r--r--test/test_prettyxml.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/test/test_prettyxml.py b/test/test_prettyxml.py
index 08071591..996e6e54 100644
--- a/test/test_prettyxml.py
+++ b/test/test_prettyxml.py
@@ -1,5 +1,5 @@
# -*- coding: UTF-8 -*-
-from rdflib.term import URIRef, BNode, Literal
+from rdflib.term import URIRef, BNode, Literal
from rdflib.namespace import RDF, RDFS
from six import b, BytesIO
@@ -8,7 +8,6 @@ from rdflib.plugins.serializers.rdfxml import PrettyXMLSerializer
from rdflib.graph import ConjunctiveGraph
-
class SerializerTestBase(object):
repeats = 8
@@ -27,7 +26,7 @@ class SerializerTestBase(object):
for i in range(self.repeats):
self.test_serialize_and_reparse()
- #test_multiple.slowtest=True # not really slow?
+ # test_multiple.slowtest=True # not really slow?
def _assert_equal_graphs(g1, g2):
@@ -39,16 +38,22 @@ def _assert_equal_graphs(g1, g2):
assert len(g1copy) == 0, "Source graph larger than serialized graph."
assert len(g2copy) == 0, "Serialized graph larger than source graph."
+
_blank = BNode()
+
def _mangled_copy(g):
"Makes a copy of the graph, replacing all bnodes with the bnode ``_blank``."
gcopy = ConjunctiveGraph()
- isbnode = lambda v: isinstance(v, BNode)
+
+ def isbnode(v): return isinstance(v, BNode)
for s, p, o in g:
- if isbnode(s): s = _blank
- if isbnode(p): p = _blank
- if isbnode(o): o = _blank
+ if isbnode(s):
+ s = _blank
+ if isbnode(p):
+ p = _blank
+ if isbnode(o):
+ o = _blank
gcopy.add((s, p, o))
return gcopy
@@ -59,6 +64,7 @@ def serialize(sourceGraph, makeSerializer, getValue=True, extra_args={}):
serializer.serialize(stream, **extra_args)
return getValue and stream.getvalue() or stream
+
def serialize_and_load(sourceGraph, makeSerializer):
stream = serialize(sourceGraph, makeSerializer, False)
stream.seek(0)
@@ -126,7 +132,7 @@ class TestPrettyXmlSerializer(SerializerTestBase):
def test_result_fragments_with_base(self):
rdfXml = serialize(self.sourceGraph, self.serializer,
- extra_args={'base':"http://example.org/", 'xml_base':"http://example.org/"})
+ extra_args={'base': "http://example.org/", 'xml_base': "http://example.org/"})
assert b('xml:base="http://example.org/"') in rdfXml
assert b('<Test rdf:about="data/a">') in rdfXml
assert b('<rdf:Description rdf:about="data/b">') in rdfXml
@@ -136,8 +142,8 @@ class TestPrettyXmlSerializer(SerializerTestBase):
def test_subClassOf_objects(self):
reparsedGraph = serialize_and_load(self.sourceGraph, self.serializer)
_assert_expected_object_types_for_predicates(reparsedGraph,
- [RDFS.seeAlso, RDFS.subClassOf],
- [URIRef, BNode])
+ [RDFS.seeAlso, RDFS.subClassOf],
+ [URIRef, BNode])
def test_pretty_xmlliteral(self):
# given:
@@ -163,4 +169,4 @@ def _assert_expected_object_types_for_predicates(graph, predicates, types):
if p in predicates:
someTrue = [isinstance(o, t) for t in types]
assert True in someTrue, \
- "Bad type %s for object when predicate is <%s>." % (type(o), p)
+ "Bad type %s for object when predicate is <%s>." % (type(o), p)