[distances] TemporalProcessing should only be available if dateutil is installed (closes #279606)
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 24 Nov 2014 10:18:32 +0100
changeset 491 8469e97fd36d
parent 490 eb99225b4167
child 492 fdd8990beb40
[distances] TemporalProcessing should only be available if dateutil is installed (closes #279606) + add a ``skipUnless`` in corresponding unit tests.
test/test_distances.py
utils/distances.py
--- a/test/test_distances.py	Mon Nov 24 10:11:45 2014 +0100
+++ b/test/test_distances.py	Mon Nov 24 10:18:32 2014 +0100
@@ -30,7 +30,8 @@
                                    jaccard, euclidean, geographical,
                                    ExactMatchProcessing, GeographicalProcessing,
                                    LevenshteinProcessing, SoundexProcessing,
-                                   JaccardProcessing, DifflibProcessing, TemporalProcessing)
+                                   JaccardProcessing, DifflibProcessing,
+                                   DATEUTIL_ENABLED)
 
 
 class DistancesTest(unittest.TestCase):
@@ -252,9 +253,11 @@
             self.assertAlmostEqual(results[ind], value, 2)
 
 
+@unittest.skipUnless(DATEUTIL_ENABLED, 'python-dateutil is not installed')
 class TemporalTestCase(unittest.TestCase):
 
     def test_pdist(self):
+        from nazca.utils.distances import TemporalProcessing
         processing = TemporalProcessing()
         _input = ['14 aout 1991', '08/14/1991', '08/15/1992']
         pdist = processing.pdist(_input)
--- a/utils/distances.py	Mon Nov 24 10:11:45 2014 +0100
+++ b/utils/distances.py	Mon Nov 24 10:18:32 2014 +0100
@@ -528,18 +528,19 @@
                                                 weight, matrix_normalized)
 
 
-class TemporalProcessing(BaseProcessing):
-    """ A processing based on the temporal distance.
-    """
+if DATEUTIL_ENABLED:
+    class TemporalProcessing(BaseProcessing):
+        """ A processing based on the temporal distance.
+        """
 
-    def __init__(self, ref_attr_index=None, target_attr_index=None,
-                 granularity=u'days', parserinfo=FrenchParserInfo,
-                 dayfirst=True, yearfirst=False,
-                 weight=1, matrix_normalized=False):
-        distance_callback = partial(temporal, granularity=granularity,
-                                    parserinfo=parserinfo,
-                                    dayfirst=dayfirst, yearfirst=yearfirst)
-        super(TemporalProcessing, self).__init__(ref_attr_index,
-                                                target_attr_index,
-                                                distance_callback,
-                                                weight, matrix_normalized)
+        def __init__(self, ref_attr_index=None, target_attr_index=None,
+                     granularity=u'days', parserinfo=FrenchParserInfo,
+                     dayfirst=True, yearfirst=False,
+                     weight=1, matrix_normalized=False):
+            distance_callback = partial(temporal, granularity=granularity,
+                                        parserinfo=parserinfo,
+                                        dayfirst=dayfirst, yearfirst=yearfirst)
+            super(TemporalProcessing, self).__init__(ref_attr_index,
+                                                    target_attr_index,
+                                                    distance_callback,
+                                                    weight, matrix_normalized)