[tests] skip SPARQL tests when python-sparqlwrapper is not installed (closes #279604)
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 24 Nov 2014 10:02:31 +0100
changeset 487 65bce2c06a62
parent 486 5730ee266a8e
child 488 afd0c31334e2
[tests] skip SPARQL tests when python-sparqlwrapper is not installed (closes #279604)
test/test_dataio.py
test/test_ner.py
--- a/test/test_dataio.py	Mon Nov 24 09:57:50 2014 +0100
+++ b/test/test_dataio.py	Mon Nov 24 10:02:31 2014 +0100
@@ -29,7 +29,7 @@
 from nazca.utils.dataio import (HTMLPrettyPrint, ValidXHTMLPrettyPrint,
                                 sparqlquery, sparqljson, _sparqlexecute,
                                 rqlquery, parsefile,
-                                autocast, split_file)
+                                autocast, split_file, SPARQL_ENABLED)
 from nazca.utils.tokenizer import NLTK_AVAILABLE
 from nazca.ner import NerProcess
 from nazca.ner.sources import NerSourceLexicon
@@ -147,6 +147,7 @@
             with open(file2split) as fobj:
                 self.assertEqual(alllines, fobj.readlines())
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_query(self):
         results = sparqlquery(u'http://dbpedia.org/sparql',
                               u'''SELECT DISTINCT ?uri ?designer
@@ -159,6 +160,7 @@
         self.assertEqual(results, [['http://dbpedia.org/resource/Python_(programming_language)', 'http://dbpedia.org/resource/Guido_van_Rossum'],
                                    ['http://dbpedia.org/resource/Python_for_S60', 'http://dbpedia.org/resource/Guido_van_Rossum']])
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_execute(self):
         rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
                                     u'''SELECT DISTINCT ?uri ?designer
@@ -183,6 +185,7 @@
                               'distinct': False,
                               'ordered': True}})
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_execute_no_raise_on_error(self):
         rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
                                     u'''SELECT DISTINCT ?uri
@@ -191,6 +194,7 @@
                                     ?uri rdf:type ?type}''')
         self.assertEqual(rawresults, [])
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_execute_raise_on_error(self):
         with self.assertRaises(RuntimeError):
             rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
@@ -200,6 +204,7 @@
                                         ?uri rdf:type ?type}''',
                                         raise_on_error=True)
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_json(self):
         results = sparqljson(u'http://dbpedia.org/sparql',
                              u'''SELECT DISTINCT ?uri ?designer
@@ -214,6 +219,7 @@
                           'uri': set(['http://dbpedia.org/resource/Python_(programming_language)',
                                       'http://dbpedia.org/resource/Python_for_S60'])})
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_autocast(self):
         alignset = sparqlquery('http://dbpedia.inria.fr/sparql',
                                  'prefix db-owl: <http://dbpedia.org/ontology/>'
@@ -230,6 +236,7 @@
         self.assertEqual(len(alignset), 100)
         self.assertTrue(isinstance(alignset[0][2][0], float))
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_no_autocast(self):
         alignset = sparqlquery('http://dbpedia.inria.fr/sparql',
                                  'prefix db-owl: <http://dbpedia.org/ontology/>'
--- a/test/test_ner.py	Mon Nov 24 09:57:50 2014 +0100
+++ b/test/test_ner.py	Mon Nov 24 10:02:31 2014 +0100
@@ -23,11 +23,12 @@
     import unittest2 as unittest
 
 from nazca.ner.sources import (NerSourceLexicon,
-                                          NerSourceSparql,
-                                          NerSourceRql)
+                               NerSourceSparql,
+                               NerSourceRql)
 from nazca.ner import NerProcess
 from nazca.utils.tokenizer import Token, Sentence, NLTK_AVAILABLE
 from nazca.ner.preprocessors import NerStopwordsFilterPreprocessor
+from nazca.utils.dataio import SPARQL_ENABLED
 
 
 class NerTest(unittest.TestCase):
@@ -54,6 +55,7 @@
                               'Any U LIMIT 1 WHERE X cwuri U, X name "%(word)s"')
         self.assertEqual(source.query_word('apycot'), [u'http://www.cubicweb.org/1310453',])
 
+    @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_source(self):
         """ Test sparql source """
         source = NerSourceSparql(u'http://dbpedia.org/sparql',