summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Higgins <gjh-github@bel-epa.com>2012-02-18 21:16:01 +0000
committerGraham Higgins <gjh-github@bel-epa.com>2012-02-18 21:16:01 +0000
commit83ae767d949387129baf5a0c6d1b9895be5bfd8a (patch)
treeafcae6615f5a9308a68d82080a4c945e3c82e80b
parent79723c77e205b10afa40558c63a4e6f057eae537 (diff)
downloadrdflib-83ae767d949387129baf5a0c6d1b9895be5bfd8a.tar.gz
Re-enable doctests, adjust docstrings for use with py3compat.
-rw-r--r--rdflib/collection.py2
-rw-r--r--rdflib/compare.py6
-rw-r--r--rdflib/graph.py44
-rw-r--r--rdflib/namespace.py24
-rw-r--r--rdflib/plugins/parsers/notation3.py6
-rw-r--r--rdflib/py3compat.py5
-rw-r--r--rdflib/resource.py5
-rw-r--r--rdflib/term.py10
-rw-r--r--setup.cfg6
-rw-r--r--tox.ini28
10 files changed, 57 insertions, 79 deletions
diff --git a/rdflib/collection.py b/rdflib/collection.py
index 438cd534..24f3b3b3 100644
--- a/rdflib/collection.py
+++ b/rdflib/collection.py
@@ -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)
diff --git a/rdflib/compare.py b/rdflib/compare.py
index 3afd67c5..d64070ba 100644
--- a/rdflib/compare.py
+++ b/rdflib/compare.py
@@ -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 @@ Only in second::
<http://example.org> <http://example.org/ns#rel> _:cb558f30e21ddfc05ca53108348338ade8 .
_:cb558f30e21ddfc05ca53108348338ade8 <http://example.org/ns#label> "B" .
"""
+else:
+ __doc__ = """"""
# ======================================================================
# FAIL: Doctest: rdflib.compare
diff --git a/rdflib/graph.py b/rdflib/graph.py
index f9d344cd..e8742cb7 100644
--- a/rdflib/graph.py
+++ b/rdflib/graph.py
@@ -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 @@ Instantiating Graphs with Sleepycat store and an identifier -
>>> 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 @@ via triple pattern:
>>> 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 @@ the same store:
>>> 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 @@ in which the triple was asserted:
>>> 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,7 +119,7 @@ Parsing N3 from StringIO
... 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
@@ -125,13 +127,11 @@ 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 @@ class Graph(Node):
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'))]
"""
diff --git a/rdflib/namespace.py b/rdflib/namespace.py
index 19396d78..e9848adc 100644
--- a/rdflib/namespace.py
+++ b/rdflib/namespace.py
@@ -20,29 +20,15 @@ Fully qualified URIs in the namespace can be constructed either by attribute or
.. 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 @@ The following namespaces are available by directly importing from rdflib:
>>> 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')
""")
diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py
index 24073b73..50e1ce73 100644
--- a/rdflib/plugins/parsers/notation3.py
+++ b/rdflib/plugins/parsers/notation3.py
@@ -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')
diff --git a/rdflib/py3compat.py b/rdflib/py3compat.py
index 821341e7..d75eb7a5 100644
--- a/rdflib/py3compat.py
+++ b/rdflib/py3compat.py
@@ -51,9 +51,10 @@ if PY3:
"%(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 @@ else:
"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
diff --git a/rdflib/resource.py b/rdflib/resource.py
index 7b77f7dc..6fb371b6 100644
--- a/rdflib/resource.py
+++ b/rdflib/resource.py
@@ -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 @@ Create a Resource::
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 @@ Retrieve some basic facts::
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
diff --git a/rdflib/term.py b/rdflib/term.py
index 512c85bf..d62bac22 100644
--- a/rdflib/term.py
+++ b/rdflib/term.py
@@ -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 @@ class Literal(Identifier):
>>> 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
"""
diff --git a/setup.cfg b/setup.cfg
index 3263bb46..94b85968 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/tox.ini b/tox.ini
index 7752d916..16e58f64 100644
--- a/tox.ini
+++ b/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 =