Skip to content

Commit

Permalink
Merge branch 'closednamedspace-inheritance-fix'
Browse files Browse the repository at this point in the history
* closednamedspace-inheritance-fix:
  re-introduces special handling for DCTERMS.title and test for it
  • Loading branch information
joernhees committed Nov 28, 2015
2 parents 0d79d7a + 3d89d8e commit ae1f639
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions rdflib/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def __new__(cls, value):
rt = unicode.__new__(cls, value, 'utf-8')
return rt

@property
def title(self):
# overrides unicode.title to allow DCTERMS.title for example
return URIRef(self + 'title')

def term(self, name):
# need to handle slices explicitly because of __getitem__ override
return URIRef(self + (name if isinstance(name, basestring) else ''))
Expand Down
11 changes: 9 additions & 2 deletions test/test_namespace.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import unittest

from rdflib.namespace import DCTERMS
from rdflib.graph import Graph
from rdflib.term import URIRef
from rdflib.py3compat import b


class NamespaceTest(unittest.TestCase):
def test_dcterms_title(self):
self.assertEqual(DCTERMS.title, URIRef(DCTERMS + 'title'))


class NamespacePrefixTest(unittest.TestCase):

def test_compute_qname(self):
Expand All @@ -14,7 +21,7 @@ def test_compute_qname(self):

self.assertEqual(g.compute_qname(URIRef("http://foo/bar#baz")),
("ns2", URIRef("http://foo/bar#"), "baz"))

# should skip to ns4 when ns3 is already assigned
g.bind("ns3", URIRef("http://example.org/"))
self.assertEqual(g.compute_qname(URIRef("http://blip/blop")),
Expand All @@ -28,7 +35,7 @@ def test_n3(self):
n3 = g.serialize(format="n3")
# Gunnar disagrees that this is right:
# self.assertTrue("<http://example.com/foo> ns1:bar <http://example.com/baz> ." in n3)
# as this is much prettier, and ns1 is already defined:
# as this is much prettier, and ns1 is already defined:
self.assertTrue(b("ns1:foo ns1:bar ns1:baz .") in n3)

def test_n32(self):
Expand Down

0 comments on commit ae1f639

Please sign in to comment.