Permalink
Browse files

Re-enable doctests, adjust docstrings for use with py3compat.

  • Loading branch information...
gjhiggins committed Feb 18, 2012
1 parent 79723c7 commit 83ae767d949387129baf5a0c6d1b9895be5bfd8a
Showing with 57 additions and 79 deletions.
  1. +1 −1 rdflib/collection.py
  2. +5 −1 rdflib/compare.py
  3. +22 −22 rdflib/graph.py
  4. +5 −19 rdflib/namespace.py
  5. +3 −3 rdflib/plugins/parsers/notation3.py
  6. +3 −2 rdflib/py3compat.py
  7. +3 −2 rdflib/resource.py
  8. +5 −5 rdflib/term.py
  9. +3 −3 setup.cfg
  10. +7 −21 tox.ini
View
@@ -23,7 +23,7 @@ class Collection(object):
>>> g.add((listItem2,RDF.first,Literal(3)))
>>> c=Collection(g,listName)
>>> print(list(c))
- [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'))]
+ [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'))]
>>> 1 in c
True
>>> len(c)
View
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
-"""
+import sys
+if sys.version_info[:2] > (2,4): # No doctest.skip in Python 2.4
+ __doc__ = """
A collection of utilities for canonicalizing and inspecting graphs.
Among other things, they solve of the problem of deterministic bnode
@@ -64,6 +66,8 @@
<http://example.org> <http://example.org/ns#rel> _:cb558f30e21ddfc05ca53108348338ade8 .
_:cb558f30e21ddfc05ca53108348338ade8 <http://example.org/ns#label> "B" .
"""
+else:
+ __doc__ = """"""
# ======================================================================
# FAIL: Doctest: rdflib.compare
View
@@ -1,4 +1,7 @@
-"""Instantiating Graphs with default store (IOMemory) and default identifier
+from __future__ import generators
+from rdflib.py3compat import format_doctest_out
+__doc__ = format_doctest_out("""\
+Instantiating Graphs with default store (IOMemory) and default identifier
(a BNode):
>>> g = Graph()
@@ -24,7 +27,7 @@
>>> g = Graph('IOMemory', URIRef("http://rdflib.net"))
>>> g.identifier
- rdflib.term.URIRef(u'http://rdflib.net')
+ rdflib.term.URIRef(%(u)s'http://rdflib.net')
>>> str(g)
"<http://rdflib.net> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']."
@@ -43,7 +46,7 @@
>>> print(len(g))
0
>>> g.add((statementId, RDF.type, RDF.Statement))
- >>> g.add((statementId, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ >>> g.add((statementId, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
>>> g.add((statementId, RDF.predicate, RDFS.label))
>>> g.add((statementId, RDF.object, Literal("Conjunctive Graph")))
>>> print(len(g))
@@ -77,15 +80,15 @@
>>> stmt2 = BNode()
>>> stmt3 = BNode()
>>> g1.add((stmt1, RDF.type, RDF.Statement))
- >>> g1.add((stmt1, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ >>> g1.add((stmt1, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
>>> g1.add((stmt1, RDF.predicate, RDFS.label))
>>> g1.add((stmt1, RDF.object, Literal("Conjunctive Graph")))
>>> g2.add((stmt2, RDF.type, RDF.Statement))
- >>> g2.add((stmt2, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ >>> g2.add((stmt2, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
>>> g2.add((stmt2, RDF.predicate, RDF.type))
>>> g2.add((stmt2, RDF.object, RDFS.Class))
>>> g3.add((stmt3, RDF.type, RDF.Statement))
- >>> g3.add((stmt3, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ >>> g3.add((stmt3, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph')))
>>> g3.add((stmt3, RDF.predicate, RDFS.comment))
>>> g3.add((stmt3, RDF.object, Literal("The top-level aggregate graph - The sum of all named graphs within a Store")))
>>> len(list(ConjunctiveGraph(store).subjects(RDF.type, RDF.Statement)))
@@ -105,9 +108,8 @@
>>> len(uniqueGraphNames)
2
-Parsing N3 from StringIO
+Parsing N3 from a string
- >>> from StringIO import StringIO
>>> g2 = Graph()
>>> src = '''
... @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@@ -117,21 +119,19 @@
... rdf:predicate rdfs:label;
... rdf:object "Conjunctive Graph" ] .
... '''
- >>> g2 = g2.parse(StringIO(src), format='n3')
+ >>> g2 = g2.parse(data=src, format='n3')
>>> print(len(g2))
4
Using Namespace class:
>>> RDFLib = Namespace('http://rdflib.net')
>>> RDFLib.ConjunctiveGraph
- rdflib.term.URIRef(u'http://rdflib.netConjunctiveGraph')
+ rdflib.term.URIRef(%(u)s'http://rdflib.netConjunctiveGraph')
>>> RDFLib['Graph']
- rdflib.term.URIRef(u'http://rdflib.netGraph')
-
-"""
+ rdflib.term.URIRef(%(u)s'http://rdflib.netGraph')
-from __future__ import generators
+""")
import logging
_logger = logging.getLogger(__name__)
@@ -588,29 +588,29 @@ def preferredLabel(self, subject, lang=None, default=[],
skos:prefLabel or rdfs:label.
>>> g = ConjunctiveGraph()
- >>> u = URIRef(u'http://example.com/foo')
+ >>> u = URIRef(%(u)s'http://example.com/foo')
>>> g.add([u, RDFS.label, Literal('foo')])
>>> g.add([u, RDFS.label, Literal('bar')])
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
+ [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
rdflib.term.Literal(%(u)s'bar')),
- (rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
+ (rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
rdflib.term.Literal(%(u)s'foo'))]
>>> g.add([u, SKOS.prefLabel, Literal('bla')])
>>> g.preferredLabel(u) #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
+ [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal(%(u)s'bla'))]
>>> g.add([u, SKOS.prefLabel, Literal('blubb', lang='en')])
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
+ [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal(%(u)s'blubb', lang='en')),
- (rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
+ (rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal(%(u)s'bla'))]
>>> g.preferredLabel(u, lang='') #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
+ [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal(%(u)s'bla'))]
>>> g.preferredLabel(u, lang='en') #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
+ [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
rdflib.term.Literal(%(u)s'blubb', lang='en'))]
"""
View
@@ -20,29 +20,15 @@
.. code-block:: pycon
>>> fuxi.ruleBase
- rdflib.term.URIRef(u'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
+ rdflib.term.URIRef(%(u)s'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
>>> fuxi['ruleBase']
- rdflib.term.URIRef(u'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
+ rdflib.term.URIRef(%(u)s'http://metacognition.info/ontologies/FuXi.n3#ruleBase')
Automatic handling of unknown predicates
-----------------------------------------
-As a programming convenience, a namespace binding is automatically created when :class:`rdflib.term.URIRef` predicates are added to the graph:
-
-.. code-block:: pycon
-
- >>> from rdflib import Graph, URIRef
- >>> g = Graph()
- >>> g.add((URIRef("http://example0.com/foo"),
- ... URIRef("http://example1.com/bar"),
- ... URIRef("http://example2.com/baz")))
- >>> print(g.serialize(format="n3"))
- @prefix ns1: <http://example1.com/> .
- <BLANKLINE>
- <http://example0.com/foo> ns1:bar <http://example2.com/baz> .
- <BLANKLINE>
- <BLANKLINE>
- >>>
+As a programming convenience, a namespace binding is automatically
+created when :class:`rdflib.term.URIRef` predicates are added to the graph.
Importable namespaces
-----------------------
@@ -58,7 +44,7 @@
>>> from rdflib import OWL
>>> OWL.seeAlso
- rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#seeAlso')
+ rdflib.term.URIRef(%(u)s'http://www.w3.org/2002/07/owl#seeAlso')
""")
@@ -138,10 +138,10 @@ def join(here, there):
We grok IRIs
- >>> len(u'Andr\\xe9')
+ >>> len(%(u)s'Andr\\xe9')
5
- >>> join('http://example.org/', u'#Andr\\xe9')
+ >>> join('http://example.org/', %(u)s'#Andr\\xe9')
%(u)s'http://example.org/#Andr\\xe9'
"""
@@ -336,7 +336,7 @@ def canonical(str_in):
>>> canonical("foo bar")
%(b)s'foo%%20bar'
- >>> canonical(u'http:')
+ >>> canonical(%(u)s'http:')
%(b)s'http:'
>>> canonical('fran%%c3%%83%%c2%%a7ois')
View
@@ -51,9 +51,10 @@ def format_doctest_out(s):
"%(u)s'abc'" --> "'abc'"
"%(b)s'abc'" --> "b'abc'"
"55%(L)s" --> "55"
+ "unicode(x)" --> "str(x)"
Accepts a string or a function, so it can be used as a decorator."""
- return s % {'u':'', 'b':'b', 'L':''}
+ return s % {'u':'', 'b':'b', 'L':'', 'unicode': 'str'}
def type_cmp(a, b):
"""Python 2 style comparison based on type"""
@@ -89,7 +90,7 @@ def format_doctest_out(s):
"55%(L)s" --> "55L"
Accepts a string or a function, so it can be used as a decorator."""
- return s % {'u':'u', 'b':'', 'L':'L'}
+ return s % {'u':'u', 'b':'', 'L':'L', 'unicode':'unicode'}
def type_cmp(a, b):
# return 1 if a > b else -1 if a < b else 0
View
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from rdflib import py3compat
+
__doc__ = py3compat.format_doctest_out("""
The :class:`~rdflib.resource.Resource` class wraps a :class:`~rdflib.graph.Graph`
and a resource reference (i.e. a :class:`rdflib.term.URIRef` or
@@ -63,7 +64,7 @@
Retrieve some basic facts::
>>> person.identifier
- rdflib.term.URIRef(u'http://example.org/person/some1#self')
+ rdflib.term.URIRef(%(u)s'http://example.org/person/some1#self')
>>> person.value(FOAF.name)
rdflib.term.Literal(%(u)s'Some Body')
@@ -73,7 +74,7 @@
Resources as unicode are represented by their identifiers as unicode::
- >>> unicode(person)
+ >>> %(unicode)s(person)
%(u)s'http://example.org/person/some1#self'
Resource references are also Resources, so you can easily get e.g. a qname
View
@@ -294,7 +294,7 @@ class Literal(Identifier):
>>> lit2006 < Literal('2007-01-01',datatype=XSD.date)
True
>>> Literal(datetime.utcnow()).datatype
- rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#dateTime')
+ rdflib.term.URIRef(%(u)s'http://www.w3.org/2001/XMLSchema#dateTime')
>>> oneInt = Literal(1)
>>> twoInt = Literal(2)
>>> twoInt < oneInt
@@ -319,12 +319,12 @@ class Literal(Identifier):
True
>>> x = Literal("2", datatype=XSD.integer)
>>> x
- rdflib.term.Literal(u'2', datatype=rdflib.term.URIRef(u'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'))
>>> Literal(x) == x
True
>>> x = Literal("cake", lang="en")
>>> x
- rdflib.term.Literal(u'cake', lang='en')
+ rdflib.term.Literal(%(u)s'cake', lang='en')
>>> Literal(x) == x
True
"""
@@ -484,9 +484,9 @@ def __lt__(self, other):
>>> from rdflib.namespace import XSD
>>> Literal("YXNkZg==", datatype=XSD['base64Binary']) < "foo"
True
- >>> u"\xfe" < Literal(u"foo")
+ >>> %(u)s"\xfe" < Literal(%(u)s"foo")
False
- >>> Literal(base64.encodestring(u"\xfe".encode("utf-8")), datatype=URIRef("http://www.w3.org/2001/XMLSchema#base64Binary")) < u"foo"
+ >>> Literal(base64.encodestring(%(u)s"\xfe".encode("utf-8")), datatype=URIRef("http://www.w3.org/2001/XMLSchema#base64Binary")) < %(u)s"foo"
False
"""
View
@@ -1,8 +1,8 @@
[nosetests]
-attr = !known_issue,!slow,!non_core,!sparql,!manual
-verbosity = 2
-#with-doctest = 1
+attr = !known_issue,!non_core,
+verbosity = 1
+with-doctest = 1
View
28 tox.ini
@@ -6,7 +6,7 @@ envlist =
commands =
python setup.py clean --all
python setup.py build
- nosetests -q --with-xunit
+ python run_tests.py --with-xunit
deps =
nose
isodate
@@ -15,10 +15,6 @@ deps =
[testenv:py24]
basepython =
python2.4
-commands =
- python setup.py clean --all
- python setup.py build
- python setup.py nosetests -q
deps =
nose
isodate
@@ -30,30 +26,20 @@ basepython =
commands =
python setup.py clean --all
python setup.py build
- python setup.py nosetests -q --where=./build/src
+ nosetests -q --where=./build/src \
+ --with-doctest \
+ --doctest-extension=.doctest \
+ --doctest-tests
+
deps =
nose
isodate
-[testenv:jython]
-commands =
- jython setup.py clean --all
- jython setup.py build
- nosetests -q --with-xunit
-
-[testenv:pypy]
-basepython =
- pypy
-commands =
- pypy setup.py clean --all
- pypy setup.py build
- pypy setup.py nosetests -q --where=./ --with-xunit
-
[testenv:cover]
basepython =
python2.7
commands =
- nosetests -q --where=./ \
+ python run_tests.py -q --where=./ \
--with-coverage --cover-html --cover-html-dir=./coverage \
--cover-package=rdflib --cover-inclusive
deps =

0 comments on commit 83ae767

Please sign in to comment.