summaryrefslogtreecommitdiff
path: root/tests/regressiontests/utils
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-09-20 01:55:53 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-09-20 01:55:53 +0000
commit94c320d8a982ce30f6dd4e7556f2696229b761c7 (patch)
tree165ff89b8b262118430ea2f7c1d26cc5af864c09 /tests/regressiontests/utils
parent28a4aa6f49b11881d43a585f118a3d0537ba9084 (diff)
queryset-refactor: Merged to [6381]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/utils')
-rw-r--r--tests/regressiontests/utils/tests.py10
-rw-r--r--tests/regressiontests/utils/timesince.py77
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py
index 258aea697e..fe0b226adc 100644
--- a/tests/regressiontests/utils/tests.py
+++ b/tests/regressiontests/utils/tests.py
@@ -6,6 +6,8 @@ from unittest import TestCase
from django.utils import html
+from timesince import timesince_tests
+
class TestUtilsHtml(TestCase):
def check_output(self, function, value, output=None):
@@ -113,3 +115,11 @@ class TestUtilsHtml(TestCase):
)
for value, output in items:
self.check_output(f, value, output)
+
+__test__ = {
+ 'timesince_tests': timesince_tests,
+}
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py
new file mode 100644
index 0000000000..30200be6e9
--- /dev/null
+++ b/tests/regressiontests/utils/timesince.py
@@ -0,0 +1,77 @@
+timesince_tests = """
+>>> from datetime import datetime, timedelta
+>>> from django.utils.timesince import timesince
+
+>>> t = datetime(2007, 8, 14, 13, 46, 0)
+
+>>> onemicrosecond = timedelta(microseconds=1)
+>>> onesecond = timedelta(seconds=1)
+>>> oneminute = timedelta(minutes=1)
+>>> onehour = timedelta(hours=1)
+>>> oneday = timedelta(days=1)
+>>> oneweek = timedelta(days=7)
+>>> onemonth = timedelta(days=30)
+>>> oneyear = timedelta(days=365)
+
+# equal datetimes.
+>>> timesince(t, t)
+u'0 minutes'
+
+# Microseconds and seconds are ignored.
+>>> timesince(t, t+onemicrosecond)
+u'0 minutes'
+>>> timesince(t, t+onesecond)
+u'0 minutes'
+
+# Test other units.
+>>> timesince(t, t+oneminute)
+u'1 minute'
+>>> timesince(t, t+onehour)
+u'1 hour'
+>>> timesince(t, t+oneday)
+u'1 day'
+>>> timesince(t, t+oneweek)
+u'1 week'
+>>> timesince(t, t+onemonth)
+u'1 month'
+>>> timesince(t, t+oneyear)
+u'1 year'
+
+# Test multiple units.
+>>> timesince(t, t+2*oneday+6*onehour)
+u'2 days, 6 hours'
+>>> timesince(t, t+2*oneweek+2*oneday)
+u'2 weeks, 2 days'
+
+# If the two differing units aren't adjacent, only the first unit is displayed.
+>>> timesince(t, t+2*oneweek+3*onehour+4*oneminute)
+u'2 weeks'
+>>> timesince(t, t+4*oneday+5*oneminute)
+u'4 days'
+
+# When the second date occurs before the first, we should always get 0 minutes.
+>>> timesince(t, t-onemicrosecond)
+u'0 minutes'
+>>> timesince(t, t-onesecond)
+u'0 minutes'
+>>> timesince(t, t-oneminute)
+u'0 minutes'
+>>> timesince(t, t-onehour)
+u'0 minutes'
+>>> timesince(t, t-oneday)
+u'0 minutes'
+>>> timesince(t, t-oneweek)
+u'0 minutes'
+>>> timesince(t, t-onemonth)
+u'0 minutes'
+>>> timesince(t, t-oneyear)
+u'0 minutes'
+>>> timesince(t, t-2*oneday-6*onehour)
+u'0 minutes'
+>>> timesince(t, t-2*oneweek-2*oneday)
+u'0 minutes'
+>>> timesince(t, t-2*oneweek-3*onehour-4*oneminute)
+u'0 minutes'
+>>> timesince(t, t-4*oneday-5*oneminute)
+u'0 minutes'
+"""