Minor tweaks to deal with the older version of librdf on ubuntu 10.04
[htsworkflow.git] / htsworkflow / util / test / test_rdfhelp.py
index 2643aef22029d48d00df0df58959a8dbf3fc42db..dfa4b971c70c1bcd28723d8b3b416c331d6d84c5 100644 (file)
@@ -6,12 +6,19 @@ import types
 from datetime import datetime
 
 from htsworkflow.util.rdfhelp import \
+     add_default_schemas, \
      blankOrUri, \
+     dcNS, \
      dump_model, \
      fromTypedNode, \
      get_model, \
+     guess_parser, \
+     guess_parser_by_extension, \
      load_string_into_model, \
+     owlNS, \
+     rdfNS, \
      rdfsNS, \
+     remove_schemas, \
      toTypedNode, \
      stripNamespace, \
      simplify_uri, \
@@ -144,7 +151,8 @@ try:
 
         def test_owl_import(self):
             path, name = os.path.split(__file__)
-            loc = 'file://'+os.path.abspath(path)+'/'
+            #loc = 'file://'+os.path.abspath(path)+'/'
+            loc = os.path.abspath(path)+'/'
             model = get_model()
             fragment = '''
 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@@ -194,6 +202,59 @@ _:a owl:imports "{loc}extra.turtle" .
             hostile_result = """hi <b>there</b>"""
             self.failUnlessEqual(str(hostile_sanitized), hostile_result)
 
+        def test_guess_parser_from_file(self):
+            DATA = [
+                ('/a/b/c.rdf', 'rdfxml'),
+                ('/a/b/c.xml', 'rdfxml'),
+                ('/a/b/c.html', 'rdfa'),
+                ('/a/b/c.turtle', 'turtle'),
+                ('http://foo.bar/bleem.turtle', 'turtle')]
+            for path, parser in DATA:
+                self.assertEqual(guess_parser_by_extension(path), parser)
+                self.assertEqual(guess_parser(None, path), parser)
+
+            DATA = [
+                ('application/rdf+xml', 'http://a.org/b/c', 'rdfxml'),
+                ('application/x-turtle', 'http://a.org/b/c', 'turtle'),
+                ('text/html', 'http://a.org/b/c', 'rdfa'),
+                ('text/html', 'http://a.org/b/c.html', 'rdfa'),
+                ('text/plain', 'http://a.org/b/c.turtle', 'turtle'),
+                ('text/plain', 'http://a.org/b/c', 'guess')
+            ]
+            for contenttype, url, parser in DATA:
+                self.assertEqual(guess_parser(contenttype, url), parser)
+
+    class TestRDFSchemas(unittest.TestCase):
+        def test_rdf_schema(self):
+            """Does it basically work?
+            """
+            model = get_model()
+            self.assertEqual(model.size(), 0)
+            add_default_schemas(model)
+            self.assertTrue(model.size() > 0)
+            remove_schemas(model)
+            self.assertEqual(model.size(), 0)
+
+        def test_included_schemas(self):
+            model = get_model()
+            add_default_schemas(model)
+
+            # rdf test
+            s = RDF.Statement(rdfNS[''], dcNS['title'], None)
+            title = model.get_target(rdfNS[''], dcNS['title'])
+            self.assertTrue(title is not None)
+
+            s = RDF.Statement(rdfNS['Property'], rdfNS['type'], rdfsNS['Class'])
+            self.assertTrue(model.contains_statement(s))
+
+            # rdfs test
+            s = RDF.Statement(rdfsNS['Class'], rdfNS['type'], rdfsNS['Class'])
+            self.assertTrue(model.contains_statement(s))
+
+            s = RDF.Statement(owlNS['inverseOf'], rdfNS['type'],
+                              rdfNS['Property'])
+            self.assertTrue(model.contains_statement(s))
+
 
     def suite():
         return unittest.makeSuite(TestRDFHelp, 'test')