Skip to content

Commit 03e21cf

Browse files
PonteIneptiquemwatts15
authored andcommitted
Fixing a bug where the empty prefix's namespace could not be retrieved
- Also, using UTF-8 as the default charset in MySQL schema creation for testing on Travis-CI Resolves: #37
1 parent f092459 commit 03e21cf

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ before_script:
1414
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS test;' -U postgres;
1515
psql -c 'create database test;' -U postgres; export DBURI='postgresql+psycopg2://postgres@localhost/test';
1616
fi"
17-
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE IF NOT EXISTS test';
17+
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE SCHEMA test DEFAULT CHARACTER SET utf8;';
1818
export DBURI='mysql+mysqldb://test@localhost/test?charset=utf8'; fi"
1919
- sh -c "if [ '$DB' = 'sqlite' ]; then export DBURI='sqlite:///%(here)s/test.sqlite';
2020
fi"

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Contributors to the rdflib-sqlalchemy project:
88
* Yves-Marie Haussonne - https://github.com/ymph
99
* Graham Higgins - https://github.com/gjhiggins
1010
* Ryan Shaw - https://github.com/rybesh
11+
* Thibault Clérice - https://github.com/ponteineptique

rdflib_sqlalchemy/store.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ def prefix(self, namespace):
660660
res = connection.execute(s)
661661
rt = [rtTuple[0] for rtTuple in res.fetchall()]
662662
res.close()
663-
return rt and rt[0] or None
663+
if rt and (rt[0] or rt[0] == ""):
664+
return rt[0]
665+
return None
664666

665667
def namespace(self, prefix):
666668
res = None

test/graph_case.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class GraphTestCase(unittest.TestCase):
2222
pizza = URIRef(u"pizza")
2323
cheese = URIRef(u"cheese")
2424

25+
namespace_dc = "http://purl.org/dc/elements/1.1/"
26+
namespace_dct = "http://purl.org/dc/terms/"
27+
namespace_saws = "http://purl.org/saws/ontology#"
28+
2529
def setUp(self, uri="sqlite://", storename=None):
2630
store = plugin.get(storename, Store)(identifier=self.identifier)
2731
self.graph = Graph(store, identifier=self.identifier)
@@ -297,6 +301,24 @@ def testStoreLiteralsXmlQuote(self):
297301
o = objs[0]
298302
self.assertEquals(o, (bob, says, imtheone))
299303

304+
def testBindNamespace(self):
305+
""" Check that bound namespaced with prefix (including empty ones) are correctly kept """
306+
self.graph.bind("", self.namespace_dc)
307+
self.graph.bind("dct", self.namespace_dct)
308+
self.assertEqual(
309+
self.graph.qname(self.namespace_dct + u"title"), "dct:title",
310+
"Prefixed namespace should be stored and retrieved"
311+
)
312+
self.assertEqual(
313+
self.graph.qname(self.namespace_dc + u"title"), "title",
314+
"Empty prefixes for namespace should be stored and retrieved"
315+
)
316+
self.assertEqual(
317+
self.graph.qname(self.namespace_saws + u"title"), "ns1:title",
318+
"Unknown prefixes for namespace should be transformed to nsX"
319+
)
320+
321+
300322
xmltestdoc = """<?xml version="1.0" encoding="UTF-8"?>
301323
<rdf:RDF
302324
xmlns="http://example.org/"

0 commit comments

Comments
 (0)