[distances] TemporalProcessing should only be available if dateutil is installed (closes #279606)

  • add a skipUnless in corresponding unit tests.
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
changeset8469e97fd36d
branchdefault
phasepublic
hiddenno
parent revision#eb99225b4167 [debian] recommend python-dateutil (closes #279605)
child revision#fdd8990beb40 prepare 0.7.1
files modified by this revision
test/test_distances.py
utils/distances.py
# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1416820712 -3600
# Mon Nov 24 10:18:32 2014 +0100
# Node ID 8469e97fd36d48313dbea07b49eb3dce97a257e5
# Parent eb99225b41675dcbbb08283a82ce6d54908e896c
[distances] TemporalProcessing should only be available if dateutil is installed (closes #279606)

+ add a ``skipUnless`` in corresponding unit tests.

diff --git a/test/test_distances.py b/test/test_distances.py
@@ -28,11 +28,12 @@
1  from nazca.utils.distances import (levenshtein, soundex, soundexcode,
2                                     difflib_match,
3                                     jaccard, euclidean, geographical,
4                                     ExactMatchProcessing, GeographicalProcessing,
5                                     LevenshteinProcessing, SoundexProcessing,
6 -                                   JaccardProcessing, DifflibProcessing, TemporalProcessing)
7 +                                   JaccardProcessing, DifflibProcessing,
8 +                                   DATEUTIL_ENABLED)
9 
10 
11  class DistancesTest(unittest.TestCase):
12 
13      def test_difflib_match(self):
@@ -250,13 +251,15 @@
14          results = [0.099, 0.238, 0.14]
15          for ind, value in enumerate(pdist):
16              self.assertAlmostEqual(results[ind], value, 2)
17 
18 
19 +@unittest.skipUnless(DATEUTIL_ENABLED, 'python-dateutil is not installed')
20  class TemporalTestCase(unittest.TestCase):
21 
22      def test_pdist(self):
23 +        from nazca.utils.distances import TemporalProcessing
24          processing = TemporalProcessing()
25          _input = ['14 aout 1991', '08/14/1991', '08/15/1992']
26          pdist = processing.pdist(_input)
27          self.assertEqual([0., 367, 367], pdist)
28 
diff --git a/utils/distances.py b/utils/distances.py
@@ -526,20 +526,21 @@
29                                                  target_attr_index,
30                                                  difflib_match,
31                                                  weight, matrix_normalized)
32 
33 
34 -class TemporalProcessing(BaseProcessing):
35 -    """ A processing based on the temporal distance.
36 -    """
37 +if DATEUTIL_ENABLED:
38 +    class TemporalProcessing(BaseProcessing):
39 +        """ A processing based on the temporal distance.
40 +        """
41 
42 -    def __init__(self, ref_attr_index=None, target_attr_index=None,
43 -                 granularity=u'days', parserinfo=FrenchParserInfo,
44 -                 dayfirst=True, yearfirst=False,
45 -                 weight=1, matrix_normalized=False):
46 -        distance_callback = partial(temporal, granularity=granularity,
47 -                                    parserinfo=parserinfo,
48 -                                    dayfirst=dayfirst, yearfirst=yearfirst)
49 -        super(TemporalProcessing, self).__init__(ref_attr_index,
50 -                                                target_attr_index,
51 -                                                distance_callback,
52 -                                                weight, matrix_normalized)
53 +        def __init__(self, ref_attr_index=None, target_attr_index=None,
54 +                     granularity=u'days', parserinfo=FrenchParserInfo,
55 +                     dayfirst=True, yearfirst=False,
56 +                     weight=1, matrix_normalized=False):
57 +            distance_callback = partial(temporal, granularity=granularity,
58 +                                        parserinfo=parserinfo,
59 +                                        dayfirst=dayfirst, yearfirst=yearfirst)
60 +            super(TemporalProcessing, self).__init__(ref_attr_index,
61 +                                                    target_attr_index,
62 +                                                    distance_callback,
63 +                                                    weight, matrix_normalized)