[Python-modules-commits] [isodate] 02/07: Imported Upstream version 0.5.4

Maximiliano Curia maxy at moszumanska.debian.org
Thu Oct 1 15:04:04 UTC 2015


This is an automated email from the git hooks/post-receive script.

maxy pushed a commit to branch master
in repository isodate.

commit b5e4fc8142930a91b2a0e14ecd831e747c8e49d0
Author: Maximiliano Curia <maxy at gnuservers.com.ar>
Date:   Thu Oct 1 14:21:55 2015 +0200

    Imported Upstream version 0.5.4
---
 CHANGES.txt                        |  8 ++++
 PKG-INFO                           | 26 ++++++++-----
 README.rst                         | 14 +++----
 setup.cfg                          |  2 +-
 setup.py                           |  4 +-
 src/isodate.egg-info/PKG-INFO      | 26 ++++++++-----
 src/isodate/__init__.py            | 28 +++++++-------
 src/isodate/duration.py            | 54 +++++++++++++++++++-------
 src/isodate/isoduration.py         | 13 ++++---
 src/isodate/isotime.py             | 20 +++++-----
 src/isodate/tests/test_duration.py | 78 +++++++++++++++++++++++++++++++++++++-
 11 files changed, 201 insertions(+), 72 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 40ae79c..31af061 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,14 @@
 CHANGES
 =======
 
+0.5.4 (2015-08-06)
+------------------
+
+- Fix parsing of Periods (Fabien Bochu)
+- Make Duration objects hashable (Geoffrey Fairchild)
+- Add multiplication to duration (Reinoud Elhorst)
+
+
 0.5.1 (2014-11-07)
 ------------------
 
diff --git a/PKG-INFO b/PKG-INFO
index 648e11f..f609f9b 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,7 +1,7 @@
 Metadata-Version: 1.1
 Name: isodate
-Version: 0.5.1
-Summary: An ISO 8601 date/time/duration parser and formater
+Version: 0.5.4
+Summary: An ISO 8601 date/time/duration parser and formatter
 Home-page: http://cheeseshop.python.org/pypi/isodate
 Author: Gerhard Weis
 Author-email: gerhard.weis at proclos.com
@@ -10,19 +10,19 @@ Description:
         ISO 8601 date/time parser
         =========================
         
-        .. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+        .. image:: https://travis-ci.org/gweis/isodate.svg?branch=master
             :target: https://travis-ci.org/gweis/isodate
             :alt: Travis-CI
-        .. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+        .. image:: https://coveralls.io/repos/gweis/isodate/badge.svg?branch=master
             :target: https://coveralls.io/r/gweis/isodate?branch=master
             :alt: Coveralls
-        .. image:: https://pypip.in/v/isodate/badge.png
+        .. image:: https://pypip.in/version/isodate/badge.svg
             :target: https://pypi.python.org/pypi/isodate/
             :alt: Latest Version
-        .. image:: https://pypip.in/d/isodate/badge.png
-            :target: https://pypi.python.org/pypi//isodate/
+        .. image:: https://pypip.in/download/isodate/badge.svg
+            :target: https://pypi.python.org/pypi/isodate/
             :alt: Downloads
-        .. image:: https://pypip.in/license/isodate/badge.png
+        .. image:: https://pypip.in/license/isodate/badge.svg
             :target: https://pypi.python.org/pypi/isodate/
             :alt: License
         
@@ -68,7 +68,7 @@ Description:
         which can be used almost like a *timedelta* object (with some limitations).
         However, a *Duration* object can be converted into a *timedelta* object.
         
-        There are also ISO formating methods for all supported data types. Each
+        There are also ISO formatting methods for all supported data types. Each
         *xxx_isoformat* method accepts a format parameter. The default format is
         always the ISO 8601 expanded format. This is the same format used by
         *datetime.isoformat*:
@@ -129,6 +129,14 @@ Description:
         CHANGES
         =======
         
+        0.5.4 (2015-08-06)
+        ------------------
+        
+        - Fix parsing of Periods (Fabien Bochu)
+        - Make Duration objects hashable (Geoffrey Fairchild)
+        - Add multiplication to duration (Reinoud Elhorst)
+        
+        
         0.5.1 (2014-11-07)
         ------------------
         
diff --git a/README.rst b/README.rst
index 67a0e51..084c8c6 100644
--- a/README.rst
+++ b/README.rst
@@ -2,19 +2,19 @@
 ISO 8601 date/time parser
 =========================
 
-.. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+.. image:: https://travis-ci.org/gweis/isodate.svg?branch=master
     :target: https://travis-ci.org/gweis/isodate
     :alt: Travis-CI
-.. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+.. image:: https://coveralls.io/repos/gweis/isodate/badge.svg?branch=master
     :target: https://coveralls.io/r/gweis/isodate?branch=master
     :alt: Coveralls
-.. image:: https://pypip.in/v/isodate/badge.png
+.. image:: https://pypip.in/version/isodate/badge.svg
     :target: https://pypi.python.org/pypi/isodate/
     :alt: Latest Version
-.. image:: https://pypip.in/d/isodate/badge.png
-    :target: https://pypi.python.org/pypi//isodate/
+.. image:: https://pypip.in/download/isodate/badge.svg
+    :target: https://pypi.python.org/pypi/isodate/
     :alt: Downloads
-.. image:: https://pypip.in/license/isodate/badge.png
+.. image:: https://pypip.in/license/isodate/badge.svg
     :target: https://pypi.python.org/pypi/isodate/
     :alt: License
 
@@ -60,7 +60,7 @@ does not handle years and months, this module provides a *Duration* class,
 which can be used almost like a *timedelta* object (with some limitations).
 However, a *Duration* object can be converted into a *timedelta* object.
 
-There are also ISO formating methods for all supported data types. Each
+There are also ISO formatting methods for all supported data types. Each
 *xxx_isoformat* method accepts a format parameter. The default format is
 always the ISO 8601 expanded format. This is the same format used by
 *datetime.isoformat*:
diff --git a/setup.cfg b/setup.cfg
index 6bc2ff3..ebbec92 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [egg_info]
-tag_date = 0
 tag_build = 
 tag_svn_revision = 0
+tag_date = 0
 
diff --git a/setup.py b/setup.py
index 9ab0855..3fc0075 100644
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@ def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 setup(name='isodate',
-      version='0.5.1',
+      version='0.5.4',
       packages=['isodate', 'isodate.tests'],
       package_dir={'': 'src'},
 
@@ -56,7 +56,7 @@ setup(name='isodate',
       # PyPI metadata
       author='Gerhard Weis',
       author_email='gerhard.weis at proclos.com',
-      description='An ISO 8601 date/time/duration parser and formater',
+      description='An ISO 8601 date/time/duration parser and formatter',
       license='BSD',
       # keywords = '',
       url='http://cheeseshop.python.org/pypi/isodate',
diff --git a/src/isodate.egg-info/PKG-INFO b/src/isodate.egg-info/PKG-INFO
index 648e11f..f609f9b 100644
--- a/src/isodate.egg-info/PKG-INFO
+++ b/src/isodate.egg-info/PKG-INFO
@@ -1,7 +1,7 @@
 Metadata-Version: 1.1
 Name: isodate
-Version: 0.5.1
-Summary: An ISO 8601 date/time/duration parser and formater
+Version: 0.5.4
+Summary: An ISO 8601 date/time/duration parser and formatter
 Home-page: http://cheeseshop.python.org/pypi/isodate
 Author: Gerhard Weis
 Author-email: gerhard.weis at proclos.com
@@ -10,19 +10,19 @@ Description:
         ISO 8601 date/time parser
         =========================
         
-        .. image:: https://travis-ci.org/gweis/isodate.png?branch=master
+        .. image:: https://travis-ci.org/gweis/isodate.svg?branch=master
             :target: https://travis-ci.org/gweis/isodate
             :alt: Travis-CI
-        .. image:: https://coveralls.io/repos/gweis/isodate/badge.png?branch=master
+        .. image:: https://coveralls.io/repos/gweis/isodate/badge.svg?branch=master
             :target: https://coveralls.io/r/gweis/isodate?branch=master
             :alt: Coveralls
-        .. image:: https://pypip.in/v/isodate/badge.png
+        .. image:: https://pypip.in/version/isodate/badge.svg
             :target: https://pypi.python.org/pypi/isodate/
             :alt: Latest Version
-        .. image:: https://pypip.in/d/isodate/badge.png
-            :target: https://pypi.python.org/pypi//isodate/
+        .. image:: https://pypip.in/download/isodate/badge.svg
+            :target: https://pypi.python.org/pypi/isodate/
             :alt: Downloads
-        .. image:: https://pypip.in/license/isodate/badge.png
+        .. image:: https://pypip.in/license/isodate/badge.svg
             :target: https://pypi.python.org/pypi/isodate/
             :alt: License
         
@@ -68,7 +68,7 @@ Description:
         which can be used almost like a *timedelta* object (with some limitations).
         However, a *Duration* object can be converted into a *timedelta* object.
         
-        There are also ISO formating methods for all supported data types. Each
+        There are also ISO formatting methods for all supported data types. Each
         *xxx_isoformat* method accepts a format parameter. The default format is
         always the ISO 8601 expanded format. This is the same format used by
         *datetime.isoformat*:
@@ -129,6 +129,14 @@ Description:
         CHANGES
         =======
         
+        0.5.4 (2015-08-06)
+        ------------------
+        
+        - Fix parsing of Periods (Fabien Bochu)
+        - Make Duration objects hashable (Geoffrey Fairchild)
+        - Add multiplication to duration (Reinoud Elhorst)
+        
+        
         0.5.1 (2014-11-07)
         ------------------
         
diff --git a/src/isodate/__init__.py b/src/isodate/__init__.py
index 26604c2..83c8cf8 100644
--- a/src/isodate/__init__.py
+++ b/src/isodate/__init__.py
@@ -54,17 +54,17 @@ from isodate.isostrf import DT_BAS_WEEK_COMPLETE, DT_EXT_WEEK_COMPLETE
 from isodate.isostrf import D_DEFAULT, D_WEEK, D_ALT_EXT, D_ALT_BAS
 from isodate.isostrf import D_ALT_BAS_ORD, D_ALT_EXT_ORD
 
-__all__ = (parse_date, date_isoformat, parse_time, time_isoformat,
-           parse_datetime, datetime_isoformat, parse_duration,
-           duration_isoformat, ISO8601Error, parse_tzinfo,
-           tz_isoformat, UTC, FixedOffset, LOCAL, Duration,
-           strftime, DATE_BAS_COMPLETE, DATE_BAS_ORD_COMPLETE,
-           DATE_BAS_WEEK, DATE_BAS_WEEK_COMPLETE, DATE_CENTURY,
-           DATE_EXT_COMPLETE, DATE_EXT_ORD_COMPLETE, DATE_EXT_WEEK,
-           DATE_EXT_WEEK_COMPLETE, DATE_MONTH, DATE_YEAR,
-           TIME_BAS_COMPLETE, TIME_BAS_MINUTE, TIME_EXT_COMPLETE,
-           TIME_EXT_MINUTE, TIME_HOUR, TZ_BAS, TZ_EXT, TZ_HOUR,
-           DT_BAS_COMPLETE, DT_EXT_COMPLETE, DT_BAS_ORD_COMPLETE,
-           DT_EXT_ORD_COMPLETE, DT_BAS_WEEK_COMPLETE,
-           DT_EXT_WEEK_COMPLETE, D_DEFAULT, D_WEEK, D_ALT_EXT,
-           D_ALT_BAS, D_ALT_BAS_ORD, D_ALT_EXT_ORD)
+__all__ = ['parse_date', 'date_isoformat', 'parse_time', 'time_isoformat',
+           'parse_datetime', 'datetime_isoformat', 'parse_duration',
+           'duration_isoformat', 'ISO8601Error', 'parse_tzinfo',
+           'tz_isoformat', 'UTC', 'FixedOffset', 'LOCAL', 'Duration',
+           'strftime', 'DATE_BAS_COMPLETE', 'DATE_BAS_ORD_COMPLETE',
+           'DATE_BAS_WEEK', 'DATE_BAS_WEEK_COMPLETE', 'DATE_CENTURY',
+           'DATE_EXT_COMPLETE', 'DATE_EXT_ORD_COMPLETE', 'DATE_EXT_WEEK',
+           'DATE_EXT_WEEK_COMPLETE', 'DATE_MONTH', 'DATE_YEAR',
+           'TIME_BAS_COMPLETE', 'TIME_BAS_MINUTE', 'TIME_EXT_COMPLETE',
+           'TIME_EXT_MINUTE', 'TIME_HOUR', 'TZ_BAS', 'TZ_EXT', 'TZ_HOUR',
+           'DT_BAS_COMPLETE', 'DT_EXT_COMPLETE', 'DT_BAS_ORD_COMPLETE',
+           'DT_EXT_ORD_COMPLETE', 'DT_BAS_WEEK_COMPLETE',
+           'DT_EXT_WEEK_COMPLETE', 'D_DEFAULT', 'D_WEEK', 'D_ALT_EXT',
+           'D_ALT_BAS', 'D_ALT_BAS_ORD', 'D_ALT_EXT_ORD']
diff --git a/src/isodate/duration.py b/src/isodate/duration.py
index b44faa8..a901865 100644
--- a/src/isodate/duration.py
+++ b/src/isodate/duration.py
@@ -134,6 +134,13 @@ class Duration(object):
             self.tdelta.days, self.tdelta.seconds,
             self.tdelta.microseconds, self.years, self.months)
 
+    def __hash__(self):
+        '''
+        Return a hash of this instance so that it can be used in, for
+        example, dicts and sets.
+        '''
+        return hash((self.tdelta, self.months, self.years))
+
     def __neg__(self):
         """
         A simple unary minus.
@@ -159,8 +166,8 @@ class Duration(object):
             newduration.tdelta = self.tdelta + other.tdelta
             return newduration
         if isinstance(other, (date, datetime)):
-            if (not(float(self.years).is_integer()
-                    and float(self.months).is_integer())):
+            if (not(float(self.years).is_integer() and
+                    float(self.months).is_integer())):
                 raise ValueError('fractional years or months not supported'
                                  ' for date calculations')
             newmonth = other.month + self.months
@@ -185,8 +192,8 @@ class Duration(object):
             newduration.tdelta = self.tdelta + other
             return newduration
         if isinstance(other, (date, datetime)):
-            if (not(float(self.years).is_integer()
-                    and float(self.months).is_integer())):
+            if (not(float(self.years).is_integer() and
+                    float(self.months).is_integer())):
                 raise ValueError('fractional years or months not supported'
                                  ' for date calculations')
             newmonth = other.month + self.months
@@ -202,6 +209,27 @@ class Duration(object):
         raise TypeError('unsupported operand type(s) for +: %s and %s' %
                         (other.__class__, self.__class__))
 
+    def __mul__(self, other):
+        if isinstance(other, int):
+            newduration = Duration(
+                years=self.years * other,
+                months=self.months * other)
+            newduration.tdelta = self.tdelta * other
+            return newduration
+        raise TypeError('unsupported operand type(s) for +: %s and %s' %
+                        (self.__class__, other.__class__))
+
+    def __rmul__(self, other):
+
+        if isinstance(other, int):
+            newduration = Duration(
+                years=self.years * other,
+                months=self.months * other)
+            newduration.tdelta = self.tdelta * other
+            return newduration
+        raise TypeError('unsupported operand type(s) for +: %s and %s' %
+                        (other.__class__, self.__class__))
+
     def __sub__(self, other):
         '''
         It is possible to subtract Duration and timedelta objects from Duration
@@ -226,8 +254,8 @@ class Duration(object):
         '''
         # print '__rsub__:', self, other
         if isinstance(other, (date, datetime)):
-            if (not(float(self.years).is_integer()
-                    and float(self.months).is_integer())):
+            if (not(float(self.years).is_integer() and
+                    float(self.months).is_integer())):
                 raise ValueError('fractional years or months not supported'
                                  ' for date calculations')
             newmonth = other.month - self.months
@@ -258,8 +286,8 @@ class Duration(object):
         if not isinstance(other, Duration):
             return NotImplemented
         if (((self.years * 12 + self.months) ==
-             (other.years * 12 + other.months)
-             and self.tdelta == other.tdelta)):
+             (other.years * 12 + other.months) and
+             self.tdelta == other.tdelta)):
             return True
         return False
 
@@ -268,15 +296,15 @@ class Duration(object):
         If the years, month part or the timedelta part is not equal, then
         the two Durations are considered not equal.
         '''
-        if ((isinstance(other, timedelta)
-             and self.years == 0
-             and self.months == 0)):
+        if ((isinstance(other, timedelta) and
+             self.years == 0 and
+             self.months == 0)):
             return self.tdelta != other
         if not isinstance(other, Duration):
             return NotImplemented
         if (((self.years * 12 + self.months) !=
-             (other.years * 12 + other.months)
-             or self.tdelta != other.tdelta)):
+             (other.years * 12 + other.months) or
+             self.tdelta != other.tdelta)):
             return True
         return False
 
diff --git a/src/isodate/isoduration.py b/src/isodate/isoduration.py
index af44661..6da69f5 100644
--- a/src/isodate/isoduration.py
+++ b/src/isodate/isoduration.py
@@ -41,7 +41,8 @@ from isodate.isostrf import strftime, D_DEFAULT
 
 ISO8601_PERIOD_REGEX = re.compile(
     r"^(?P<sign>[+-])?"
-    r"P(?P<years>[0-9]+([,.][0-9]+)?Y)?"
+    r"P(?!\b)"
+    r"(?P<years>[0-9]+([,.][0-9]+)?Y)?"
     r"(?P<months>[0-9]+([,.][0-9]+)?M)?"
     r"(?P<weeks>[0-9]+([,.][0-9]+)?W)?"
     r"(?P<days>[0-9]+([,.][0-9]+)?D)?"
@@ -136,11 +137,11 @@ def duration_isoformat(tduration, format=D_DEFAULT):
     '''
     # TODO: implement better decision for negative Durations.
     #       should be done in Duration class in consistent way with timedelta.
-    if (((isinstance(tduration, Duration)
-          and (tduration.years < 0 or tduration.months < 0
-               or tduration.tdelta < timedelta(0)))
-         or (isinstance(tduration, timedelta)
-             and (tduration < timedelta(0))))):
+    if (((isinstance(tduration, Duration) and
+          (tduration.years < 0 or tduration.months < 0 or
+           tduration.tdelta < timedelta(0))) or
+        (isinstance(tduration, timedelta) and
+         (tduration < timedelta(0))))):
         ret = '-'
     else:
         ret = ''
diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py
index 2b268d0..9650cda 100644
--- a/src/isodate/isotime.py
+++ b/src/isodate/isotime.py
@@ -71,25 +71,25 @@ def build_time_regexps():
         #    hh:mm:ss.ss ... extended format
         TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):"
                                            r"(?P<minute>[0-9]{2}):"
-                                           r"(?P<second>[0-9]{2}([,.][0-9]+)?)"
-                                           + TZ_REGEX))
+                                           r"(?P<second>[0-9]{2}"
+                                           r"([,.][0-9]+)?)" + TZ_REGEX))
         #    hhmmss.ss ... basic format
         TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2})"
                                            r"(?P<minute>[0-9]{2})"
-                                           r"(?P<second>[0-9]{2}([,.][0-9]+)?)"
-                                           + TZ_REGEX))
+                                           r"(?P<second>[0-9]{2}"
+                                           r"([,.][0-9]+)?)" + TZ_REGEX))
         # 2. reduced accuracy:
         #    hh:mm.mm ... extended format
         TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):"
-                                           r"(?P<minute>[0-9]{2}([,.][0-9]+)?)"
-                                           + TZ_REGEX))
+                                           r"(?P<minute>[0-9]{2}"
+                                           r"([,.][0-9]+)?)" + TZ_REGEX))
         #    hhmm.mm ... basic format
         TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2})"
-                                           r"(?P<minute>[0-9]{2}([,.][0-9]+)?)"
-                                           + TZ_REGEX))
+                                           r"(?P<minute>[0-9]{2}"
+                                           r"([,.][0-9]+)?)" + TZ_REGEX))
         #    hh.hh ... basic format
-        TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}([,.][0-9]+)?)"
-                                           + TZ_REGEX))
+        TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}"
+                                           r"([,.][0-9]+)?)" + TZ_REGEX))
     return TIME_REGEX_CACHE
 
 
diff --git a/src/isodate/tests/test_duration.py b/src/isodate/tests/test_duration.py
index 6cf6b65..0b80a54 100644
--- a/src/isodate/tests/test_duration.py
+++ b/src/isodate/tests/test_duration.py
@@ -231,6 +231,31 @@ DATE_CALC_TEST_CASES = (
     #  date(2001, 2, 14)),
     )
 
+# A list of test cases of multiplications of durations
+# are compared against a given expected result.
+DATE_MUL_TEST_CASES = (
+    (Duration(years=1, months=1),
+     3,
+     Duration(years=3, months=3)),
+    (Duration(years=1, months=1),
+     -3,
+     Duration(years=-3, months=-3)),
+    (3,
+     Duration(years=1, months=1),
+     Duration(years=3, months=3)),
+    (-3,
+     Duration(years=1, months=1),
+     Duration(years=-3, months=-3)),
+    (5,
+     Duration(years=2, minutes=40),
+     Duration(years=10, hours=3, minutes=20)),
+    (-5,
+     Duration(years=2, minutes=40),
+     Duration(years=-10, hours=-3, minutes=-20)),
+    (7,
+     Duration(years=1, months=2, weeks=40),
+     Duration(years=8, months=2, weeks=280)))
+
 
 class DurationTest(unittest.TestCase):
     '''
@@ -263,6 +288,16 @@ class DurationTest(unittest.TestCase):
                           'raise exception')
         self.assertRaises(TypeError, operator.add, 'raise exception',
                           Duration(years=1, months=1, weeks=5))
+        self.assertRaises(TypeError, operator.mul,
+                          Duration(years=1, months=1, weeks=5),
+                          'raise exception')
+        self.assertRaises(TypeError, operator.mul, 'raise exception',
+                          Duration(years=1, months=1, weeks=5))
+        self.assertRaises(TypeError, operator.mul,
+                          Duration(years=1, months=1, weeks=5),
+                          3.14)
+        self.assertRaises(TypeError, operator.mul, 3.14,
+                          Duration(years=1, months=1, weeks=5))
 
     def test_parseerror(self):
         '''
@@ -272,13 +307,30 @@ class DurationTest(unittest.TestCase):
 
     def test_repr(self):
         '''
-        Test __repr__ and __str__ for Duration obqects.
+        Test __repr__ and __str__ for Duration objects.
         '''
         dur = Duration(10, 10, years=10, months=10)
         self.assertEqual('10 years, 10 months, 10 days, 0:00:10', str(dur))
         self.assertEqual('isodate.duration.Duration(10, 10, 0,'
                          ' years=10, months=10)', repr(dur))
 
+    def test_hash(self):
+        '''
+        Test __hash__ for Duration objects.
+        '''
+        dur1 = Duration(10, 10, years=10, months=10)
+        dur2 = Duration(9, 9, years=9, months=9)
+        dur3 = Duration(10, 10, years=10, months=10)
+        self.assertNotEqual(hash(dur1), hash(dur2))
+        self.assertNotEqual(id(dur1), id(dur2))
+        self.assertEqual(hash(dur1), hash(dur3))
+        self.assertNotEqual(id(dur1), id(dur3))
+        durSet = set()
+        durSet.add(dur1)
+        durSet.add(dur2)
+        durSet.add(dur3)
+        self.assertEqual(len(durSet), 2)
+
     def test_neg(self):
         '''
         Test __neg__ for Duration objects.
@@ -498,6 +550,28 @@ def create_datecalctestcase(start, duration, expectation):
     return unittest.TestLoader().loadTestsFromTestCase(TestDateCalc)
 
 
+def create_datemultestcase(operand1, operand2, expectation):
+    """
+    Create a TestCase class for a specific test.
+
+    This allows having a separate TestCase for each test tuple from the
+    DATE_CALC_TEST_CASES list, so that a failed test won't stop other tests.
+    """
+
+    class TestDateMul(unittest.TestCase):
+        '''
+        A test case template test addition operators for Duration objects.
+        '''
+
+        def test_mul(self):
+            '''
+            Test operator *.
+            '''
+            self.assertEqual(operand1 * operand2, expectation)
+
+    return unittest.TestLoader().loadTestsFromTestCase(TestDateMul)
+
+
 def test_suite():
     '''
     Return a test suite containing all test defined above.
@@ -513,6 +587,8 @@ def test_suite():
         suite.addTest(create_datetestcase(*testdata))
     for testdata in DATE_CALC_TEST_CASES:
         suite.addTest(create_datecalctestcase(*testdata))
+    for testdata in DATE_MUL_TEST_CASES:
+        suite.addTest(create_datemultestcase(*testdata))
     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DurationTest))
     return suite
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/isodate.git



More information about the Python-modules-commits mailing list