From b108de64948f27da7a44bc538f12e3e0a5e64bf5 Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Wed, 19 Nov 2003 22:53:15 +0000 Subject: [PATCH] - Add tests for Interval.pretty(). - Fix 'ago' and 'in' not being added to years. - Fix docstrings for emacs. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1999 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/date.py | 14 +++++++------- test/test_dates.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/roundup/date.py b/roundup/date.py index d4f5f36..b9fd398 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: date.py,v 1.56 2003-11-04 12:35:47 anthonybaxter Exp $ +# $Id: date.py,v 1.57 2003-11-19 22:53:15 jlgijsbers Exp $ __doc__ = """ Date, time and time interval handling. @@ -514,11 +514,11 @@ class Interval: raise TypeError, "Can't add %r"%other def __div__(self, other): - ''' Divide this interval by an int value. + """ Divide this interval by an int value. Can't divide years and months sensibly in the _same_ calculation as days/time, so raise an error in that situation. - ''' + """ try: other = float(other) except TypeError: @@ -564,9 +564,9 @@ class Interval: ''' if self.year: if self.year == 1: - return _('1 year') + s = _('1 year') else: - return _('%(number)s years')%{'number': self.year} + s = _('%(number)s years')%{'number': self.year} elif self.month or self.day > 13: days = (self.month * 30) + self.day if days > 28: @@ -623,13 +623,13 @@ class Interval: self.day, self.hour, self.minute, self.second) def fixTimeOverflow(time): - ''' Handle the overflow in the time portion (H, M, S) of "time": + """ Handle the overflow in the time portion (H, M, S) of "time": (sign, y,m,d,H,M,S) Overflow and underflow will at most affect the _days_ portion of the date. We do not overflow days to months as we don't know _how_ to, generally. - ''' + """ # XXX we could conceivably use this function for handling regular dates # XXX too - we just need to interrogate the month/year for the day # XXX overflow... diff --git a/test/test_dates.py b/test/test_dates.py index d924ab3..2c92aca 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -15,7 +15,8 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_dates.py,v 1.29 2003-11-04 12:35:47 anthonybaxter Exp $ +# $Id: test_dates.py,v 1.30 2003-11-19 22:53:14 jlgijsbers Exp $ +from __future__ import nested_scopes import unittest, time @@ -335,6 +336,39 @@ class DateTestCase(unittest.TestCase): ae(str(Date('2003-5', add_granularity=1)), '2003-05-31.23:59:59') ae(str(Interval('+1w', add_granularity=1)), '+ 14d') ae(str(Interval('-2m 3w', add_granularity=1)), '- 2m 14d') + + def testIntervalPretty(self): + def ae(spec, pretty): + self.assertEqual(Interval(spec).pretty(), pretty) + ae('2y', 'in 2 years') + ae('1y', 'in 1 year') + ae('2m', 'in 2 months') + ae('1m 30d', 'in 2 months') + ae('60d', 'in 2 months') + ae('59d', 'in 1 month') + ae('1m', 'in 1 month') + ae('29d', 'in 1 month') + ae('28d', 'in 4 weeks') + ae('8d', 'in 1 week') + ae('7d', 'in 7 days') + ae('1w', 'in 7 days') + ae('2d', 'in 2 days') + ae('1d', 'tomorrow') + ae('02:00:00', 'in 2 hours') + ae('01:59:00', 'in 1 3/4 hours') + ae('01:45:00', 'in 1 3/4 hours') + ae('01:30:00', 'in 1 1/2 hours') + ae('01:29:00', 'in 1 1/4 hours') + ae('01:00:00', 'in an hour') + ae('00:30:00', 'in 1/2 an hour') + ae('00:15:00', 'in 1/4 hour') + ae('00:02:00', 'in 2 minutes') + ae('00:01:00', 'in 1 minute') + ae('00:00:30', 'in a moment') + ae('-00:00:30', 'just now') + ae('-1d', 'yesterday') + ae('-1y', '1 year ago') + ae('-2y', '2 years ago') def test_suite(): suite = unittest.TestSuite() -- 2.30.2