Skip to content

Commit 83ae767

Browse files
committed
Re-enable doctests, adjust docstrings for use with py3compat.
1 parent 79723c7 commit 83ae767

File tree

10 files changed

+57
-79
lines changed

10 files changed

+57
-79
lines changed

rdflib/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Collection(object):
2323
>>> g.add((listItem2,RDF.first,Literal(3)))
2424
>>> c=Collection(g,listName)
2525
>>> print(list(c))
26-
[rdflib.term.Literal(%(u)s'1', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(%(u)s'2', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(%(u)s'3', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))]
26+
[rdflib.term.Literal(%(u)s'1', datatype=rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(%(u)s'2', datatype=rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(%(u)s'3', datatype=rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#integer'))]
2727
>>> 1 in c
2828
True
2929
>>> len(c)

rdflib/compare.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
"""
2+
import sys
3+
if sys.version_info[:2] > (2,4): # No doctest.skip in Python 2.4
4+
__doc__ = """
35
A collection of utilities for canonicalizing and inspecting graphs.
46
57
Among other things, they solve of the problem of deterministic bnode
@@ -64,6 +66,8 @@
6466
<http://example.org> <http://example.org/ns#rel> _:cb558f30e21ddfc05ca53108348338ade8 .
6567
_:cb558f30e21ddfc05ca53108348338ade8 <http://example.org/ns#label> "B" .
6668
"""
69+
else:
70+
__doc__ = """"""
6771

6872
# ======================================================================
6973
# FAIL: Doctest: rdflib.compare

rdflib/graph.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Instantiating Graphs with default store (IOMemory) and default identifier
1+
from __future__ import generators
2+
from rdflib.py3compat import format_doctest_out
3+
__doc__ = format_doctest_out("""\
4+
Instantiating Graphs with default store (IOMemory) and default identifier
25
(a BNode):
36
47
>>> g = Graph()
@@ -24,7 +27,7 @@
2427
2528
>>> g = Graph('IOMemory', URIRef("http://rdflib.net"))
2629
>>> g.identifier
27-
rdflib.term.URIRef(u'http://rdflib.net')
30+
rdflib.term.URIRef(%(u)s'http://rdflib.net')
2831
>>> str(g)
2932
"<http://rdflib.net> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']."
3033
@@ -43,7 +46,7 @@
4346
>>> print(len(g))
4447
0
4548
>>> g.add((statementId, RDF.type, RDF.Statement))
46-
>>> g.add((statementId, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
49+
>>> g.add((statementId, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
4750
>>> g.add((statementId, RDF.predicate, RDFS.label))
4851
>>> g.add((statementId, RDF.object, Literal("Conjunctive Graph")))
4952
>>> print(len(g))
@@ -77,15 +80,15 @@
7780
>>> stmt2 = BNode()
7881
>>> stmt3 = BNode()
7982
>>> g1.add((stmt1, RDF.type, RDF.Statement))
80-
>>> g1.add((stmt1, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
83+
>>> g1.add((stmt1, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
8184
>>> g1.add((stmt1, RDF.predicate, RDFS.label))
8285
>>> g1.add((stmt1, RDF.object, Literal("Conjunctive Graph")))
8386
>>> g2.add((stmt2, RDF.type, RDF.Statement))
84-
>>> g2.add((stmt2, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
87+
>>> g2.add((stmt2, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
8588
>>> g2.add((stmt2, RDF.predicate, RDF.type))
8689
>>> g2.add((stmt2, RDF.object, RDFS.Class))
8790
>>> g3.add((stmt3, RDF.type, RDF.Statement))
88-
>>> g3.add((stmt3, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
91+
>>> g3.add((stmt3, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
8992
>>> g3.add((stmt3, RDF.predicate, RDFS.comment))
9093
>>> g3.add((stmt3, RDF.object, Literal("The top-level aggregate graph - The sum of all named graphs within a Store")))
9194
>>> len(list(ConjunctiveGraph(store).subjects(RDF.type, RDF.Statement)))
@@ -105,9 +108,8 @@
105108
>>> len(uniqueGraphNames)
106109
2
107110
108-
Parsing N3 from StringIO
111+
Parsing N3 from a string
109112
110-
>>> from StringIO import StringIO
111113
>>> g2 = Graph()
112114
>>> src = '''
113115
... @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@@ -117,21 +119,19 @@
117119
... rdf:predicate rdfs:label;
118120
... rdf:object "Conjunctive Graph" ] .
119121
... '''
120-
>>> g2 = g2.parse(StringIO(src), format='n3')
122+
>>> g2 = g2.parse(data=src, format='n3')
121123
>>> print(len(g2))
122124
4
123125
124126
Using Namespace class:
125127
126128
>>> RDFLib = Namespace('http://rdflib.net')
127129
>>> RDFLib.ConjunctiveGraph
128-
rdflib.term.URIRef(u'http://rdflib.netConjunctiveGraph')
130+
rdflib.term.URIRef(%(u)s'http://rdflib.netConjunctiveGraph')
129131
>>> RDFLib['Graph']
130-
rdflib.term.URIRef(u'http://rdflib.netGraph')
131-
132-
"""
132+
rdflib.term.URIRef(%(u)s'http://rdflib.netGraph')
133133
134-
from __future__ import generators
134+
""")
135135

136136
import logging
137137
_logger = logging.getLogger(__name__)
@@ -588,29 +588,29 @@ def preferredLabel(self, subject, lang=None, default=[],
588588
skos:prefLabel or rdfs:label.
589589
590590
>>> g = ConjunctiveGraph()
591-
>>> u = URIRef(u'http://example.com/foo')
591+
>>> u = URIRef(%(u)s'http://example.com/foo')
592592
>>> g.add([u, RDFS.label, Literal('foo')])
593593
>>> g.add([u, RDFS.label, Literal('bar')])
594594
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
595-
[(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
595+
[(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
596596
rdflib.term.Literal(%(u)s'bar')),
597-
(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
597+
(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
598598
rdflib.term.Literal(%(u)s'foo'))]
599599
>>> g.add([u, SKOS.prefLabel, Literal('bla')])
600600
>>> g.preferredLabel(u) #doctest: +NORMALIZE_WHITESPACE
601-
[(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
601+
[(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
602602
rdflib.term.Literal(%(u)s'bla'))]
603603
>>> g.add([u, SKOS.prefLabel, Literal('blubb', lang='en')])
604604
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
605-
[(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
605+
[(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
606606
rdflib.term.Literal(%(u)s'blubb', lang='en')),
607-
(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
607+
(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
608608
rdflib.term.Literal(%(u)s'bla'))]
609609
>>> g.preferredLabel(u, lang='') #doctest: +NORMALIZE_WHITESPACE
610-
[(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
610+
[(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
611611
rdflib.term.Literal(%(u)s'bla'))]
612612
>>> g.preferredLabel(u, lang='en') #doctest: +NORMALIZE_WHITESPACE
613-
[(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
613+
[(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
614614
rdflib.term.Literal(%(u)s'blubb', lang='en'))]
615615
"""
616616

rdflib/namespace.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,15 @@
2020
.. code-block:: pycon
2121
2222
>>> fuxi.ruleBase
23-
rdflib.term.URIRef(u'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
23+
rdflib.term.URIRef(%(u)s'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
2424
>>> fuxi['ruleBase']
25-
rdflib.term.URIRef(u'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
25+
rdflib.term.URIRef(%(u)s'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
2626
2727
Automatic handling of unknown predicates
2828
-----------------------------------------
2929
30-
As a programming convenience, a namespace binding is automatically created when :class:`rdflib.term.URIRef` predicates are added to the graph:
31-
32-
.. code-block:: pycon
33-
34-
>>> from rdflib import Graph, URIRef
35-
>>> g = Graph()
36-
>>> g.add((URIRef("http://example0.com/foo"),
37-
... URIRef("http://example1.com/bar"),
38-
... URIRef("http://example2.com/baz")))
39-
>>> print(g.serialize(format="n3"))
40-
@prefix ns1: <http://example1.com/> .
41-
<BLANKLINE>
42-
<http://example0.com/foo> ns1:bar <http://example2.com/baz> .
43-
<BLANKLINE>
44-
<BLANKLINE>
45-
>>>
30+
As a programming convenience, a namespace binding is automatically
31+
created when :class:`rdflib.term.URIRef` predicates are added to the graph.
4632
4733
Importable namespaces
4834
-----------------------
@@ -58,7 +44,7 @@
5844
5945
>>> from rdflib import OWL
6046
>>> OWL.seeAlso
61-
rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#seeAlso')
47+
rdflib.term.URIRef(%(u)s'http://www.w3.org/2002/07/owl#seeAlso')
6248
6349
""")
6450

rdflib/plugins/parsers/notation3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def join(here, there):
138138
139139
We grok IRIs
140140
141-
>>> len(u'Andr\\xe9')
141+
>>> len(%(u)s'Andr\\xe9')
142142
5
143143
144-
>>> join('http://example.org/', u'#Andr\\xe9')
144+
>>> join('http://example.org/', %(u)s'#Andr\\xe9')
145145
%(u)s'http://example.org/#Andr\\xe9'
146146
"""
147147

@@ -336,7 +336,7 @@ def canonical(str_in):
336336
>>> canonical("foo bar")
337337
%(b)s'foo%%20bar'
338338
339-
>>> canonical(u'http:')
339+
>>> canonical(%(u)s'http:')
340340
%(b)s'http:'
341341
342342
>>> canonical('fran%%c3%%83%%c2%%a7ois')

rdflib/py3compat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ def format_doctest_out(s):
5151
"%(u)s'abc'" --> "'abc'"
5252
"%(b)s'abc'" --> "b'abc'"
5353
"55%(L)s" --> "55"
54+
"unicode(x)" --> "str(x)"
5455
5556
Accepts a string or a function, so it can be used as a decorator."""
56-
return s % {'u':'', 'b':'b', 'L':''}
57+
return s % {'u':'', 'b':'b', 'L':'', 'unicode': 'str'}
5758

5859
def type_cmp(a, b):
5960
"""Python 2 style comparison based on type"""
@@ -89,7 +90,7 @@ def format_doctest_out(s):
8990
"55%(L)s" --> "55L"
9091
9192
Accepts a string or a function, so it can be used as a decorator."""
92-
return s % {'u':'u', 'b':'', 'L':'L'}
93+
return s % {'u':'u', 'b':'', 'L':'L', 'unicode':'unicode'}
9394

9495
def type_cmp(a, b):
9596
# return 1 if a > b else -1 if a < b else 0

rdflib/resource.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from rdflib import py3compat
3+
34
__doc__ = py3compat.format_doctest_out("""
45
The :class:`~rdflib.resource.Resource` class wraps a :class:`~rdflib.graph.Graph`
56
and a resource reference (i.e. a :class:`rdflib.term.URIRef` or
@@ -63,7 +64,7 @@
6364
Retrieve some basic facts::
6465
6566
>>> person.identifier
66-
rdflib.term.URIRef(u'http://example.org/person/some1#self')
67+
rdflib.term.URIRef(%(u)s'http://example.org/person/some1#self')
6768
6869
>>> person.value(FOAF.name)
6970
rdflib.term.Literal(%(u)s'Some Body')
@@ -73,7 +74,7 @@
7374
7475
Resources as unicode are represented by their identifiers as unicode::
7576
76-
>>> unicode(person)
77+
>>> %(unicode)s(person)
7778
%(u)s'http://example.org/person/some1#self'
7879
7980
Resource references are also Resources, so you can easily get e.g. a qname

rdflib/term.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Literal(Identifier):
294294
>>> lit2006 < Literal('2007-01-01',datatype=XSD.date)
295295
True
296296
>>> Literal(datetime.utcnow()).datatype
297-
rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#dateTime')
297+
rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#dateTime')
298298
>>> oneInt = Literal(1)
299299
>>> twoInt = Literal(2)
300300
>>> twoInt < oneInt
@@ -319,12 +319,12 @@ class Literal(Identifier):
319319
True
320320
>>> x = Literal("2", datatype=XSD.integer)
321321
>>> x
322-
rdflib.term.Literal(u'2', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#integer'))
322+
rdflib.term.Literal(%(u)s'2', datatype=rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#integer'))
323323
>>> Literal(x) == x
324324
True
325325
>>> x = Literal("cake", lang="en")
326326
>>> x
327-
rdflib.term.Literal(u'cake', lang='en')
327+
rdflib.term.Literal(%(u)s'cake', lang='en')
328328
>>> Literal(x) == x
329329
True
330330
"""
@@ -484,9 +484,9 @@ def __lt__(self, other):
484484
>>> from rdflib.namespace import XSD
485485
>>> Literal("YXNkZg==", datatype=XSD['base64Binary']) < "foo"
486486
True
487-
>>> u"\xfe" < Literal(u"foo")
487+
>>> %(u)s"\xfe" < Literal(%(u)s"foo")
488488
False
489-
>>> Literal(base64.encodestring(u"\xfe".encode("utf-8")), datatype=URIRef("http://www.w3.org/2001/XMLSchema#base64Binary")) < u"foo"
489+
>>> Literal(base64.encodestring(%(u)s"\xfe".encode("utf-8")), datatype=URIRef("http://www.w3.org/2001/XMLSchema#base64Binary")) < %(u)s"foo"
490490
False
491491
"""
492492

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[nosetests]
22

3-
attr = !known_issue,!slow,!non_core,!sparql,!manual
4-
verbosity = 2
5-
#with-doctest = 1
3+
attr = !known_issue,!non_core,
4+
verbosity = 1
5+
with-doctest = 1
66

77

88

tox.ini

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ envlist =
66
commands =
77
python setup.py clean --all
88
python setup.py build
9-
nosetests -q --with-xunit
9+
python run_tests.py --with-xunit
1010
deps =
1111
nose
1212
isodate
@@ -15,10 +15,6 @@ deps =
1515
[testenv:py24]
1616
basepython =
1717
python2.4
18-
commands =
19-
python setup.py clean --all
20-
python setup.py build
21-
python setup.py nosetests -q
2218
deps =
2319
nose
2420
isodate
@@ -30,30 +26,20 @@ basepython =
3026
commands =
3127
python setup.py clean --all
3228
python setup.py build
33-
python setup.py nosetests -q --where=./build/src
29+
nosetests -q --where=./build/src \
30+
--with-doctest \
31+
--doctest-extension=.doctest \
32+
--doctest-tests
33+
3434
deps =
3535
nose
3636
isodate
3737

38-
[testenv:jython]
39-
commands =
40-
jython setup.py clean --all
41-
jython setup.py build
42-
nosetests -q --with-xunit
43-
44-
[testenv:pypy]
45-
basepython =
46-
pypy
47-
commands =
48-
pypy setup.py clean --all
49-
pypy setup.py build
50-
pypy setup.py nosetests -q --where=./ --with-xunit
51-
5238
[testenv:cover]
5339
basepython =
5440
python2.7
5541
commands =
56-
nosetests -q --where=./ \
42+
python run_tests.py -q --where=./ \
5743
--with-coverage --cover-html --cover-html-dir=./coverage \
5844
--cover-package=rdflib --cover-inclusive
5945
deps =

0 commit comments

Comments
 (0)