From 93a5ba4927d5343fee799f2cfc73c660a93ded8b Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Thu, 10 Jul 2014 14:32:41 -0700 Subject: [PATCH 1/5] tst: issue379 allow hash with @base directive --- test/test_issue379.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test_issue379.py diff --git a/test/test_issue379.py b/test/test_issue379.py new file mode 100644 index 000000000..2cb87b6ef --- /dev/null +++ b/test/test_issue379.py @@ -0,0 +1,46 @@ +import unittest + +import rdflib + + +prefix_data = """ + @prefix rdf: . + @prefix : . + + a rdf:class .""" + +base_data = """ + @prefix rdf: . + @base . + + a rdf:class . + """ + + +class TestBaseAllowsHash(unittest.TestCase): + """ + GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379 + """ + def setUp(self): + self.g = rdflib.Graph() + + def test_parse_successful_prefix_with_hash(self): + """ + Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is + permitted for an IRIREF: + http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID + """ + self.g.parse(data=prefix_data, format='n3') + #self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) + + def test_parse_successful_base_with_hash(self): + """ + Test parse of '@base' namespace directive to allow a trailing hash '#', as is + permitted for an '@prefix' since both allow an IRIREF: + http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base + """ + self.g.parse(data=base_data, format='n3') + #self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From ac64868df0d1419a1473f994605bc57a7e31cf8b Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Thu, 10 Jul 2014 14:33:50 -0700 Subject: [PATCH 2/5] fix: issue379 comment out base hash check --- rdflib/plugins/parsers/notation3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 rdflib/plugins/parsers/notation3.py diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py old mode 100644 new mode 100755 index 46594dd4e..966eea068 --- a/rdflib/plugins/parsers/notation3.py +++ b/rdflib/plugins/parsers/notation3.py @@ -109,8 +109,8 @@ def join(here, there): %(u)s'http://example.org/#Andr\\xe9' """ - assert(here.find("#") < 0), \ - "Base may not contain hash: '%s'" % here # why must caller splitFrag? +# assert(here.find("#") < 0), \ +# "Base may not contain hash: '%s'" % here # why must caller splitFrag? slashl = there.find('/') colonl = there.find(':') From 3f33bba6cfbb78e2671310dc481b88b2ceb64642 Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Thu, 10 Jul 2014 14:43:53 -0700 Subject: [PATCH 3/5] tst: check that the file parsed --- test/test_issue379.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_issue379.py b/test/test_issue379.py index 2cb87b6ef..d66e831f2 100644 --- a/test/test_issue379.py +++ b/test/test_issue379.py @@ -2,7 +2,6 @@ import rdflib - prefix_data = """ @prefix rdf: . @prefix : . @@ -31,7 +30,7 @@ def test_parse_successful_prefix_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID """ self.g.parse(data=prefix_data, format='n3') - #self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) + self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) def test_parse_successful_base_with_hash(self): """ @@ -40,7 +39,7 @@ def test_parse_successful_base_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base """ self.g.parse(data=base_data, format='n3') - #self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) + self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) if __name__ == "__main__": unittest.main() \ No newline at end of file From cf4a67cb25925e6247477d35edb5a7db25c943e3 Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Thu, 10 Jul 2014 15:16:29 -0700 Subject: [PATCH 4/5] tst: drop assertIsInstance check as not in py 2.6 --- test/test_issue379.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_issue379.py b/test/test_issue379.py index d66e831f2..576c480a7 100644 --- a/test/test_issue379.py +++ b/test/test_issue379.py @@ -30,7 +30,6 @@ def test_parse_successful_prefix_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID """ self.g.parse(data=prefix_data, format='n3') - self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) def test_parse_successful_base_with_hash(self): """ @@ -39,7 +38,6 @@ def test_parse_successful_base_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base """ self.g.parse(data=base_data, format='n3') - self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From bbc486fc3413a1dc8dbf2833f438fd56db3af3c3 Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Fri, 11 Jul 2014 12:05:33 -0700 Subject: [PATCH 5/5] tst: add py2.6 support for isInstance check. --- test/test_issue379.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test_issue379.py b/test/test_issue379.py index 576c480a7..42857aa40 100644 --- a/test/test_issue379.py +++ b/test/test_issue379.py @@ -16,7 +16,18 @@ """ -class TestBaseAllowsHash(unittest.TestCase): +class TestCase(unittest.TestCase): + def assertIsInstance(self, obj, cls, msg=None, *args, **kwargs): + """Python < v2.7 compatibility. Assert 'obj' is instance of 'cls'""" + try: + f = super(TestCase, self).assertIsInstance + except AttributeError: + self.assertTrue(isinstance(obj, cls), *args, **kwargs) + else: + f(obj, cls, *args, **kwargs) + + +class TestBaseAllowsHash(TestCase): """ GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379 """ @@ -30,6 +41,7 @@ def test_parse_successful_prefix_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID """ self.g.parse(data=prefix_data, format='n3') + self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) def test_parse_successful_base_with_hash(self): """ @@ -38,6 +50,7 @@ def test_parse_successful_base_with_hash(self): http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base """ self.g.parse(data=base_data, format='n3') + self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef) if __name__ == "__main__": unittest.main()