changeset 4756:e7812c9f6062

utils: more test cases for age, including short form
author Aras Pranckevicius <aras@unity3d.com>
date Sun, 04 Jan 2015 13:44:51 +0200
parents 244c9b103cff
children 2982360d2547
files kallithea/tests/other/test_libs.py
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/other/test_libs.py	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/tests/other/test_libs.py	Sun Jan 04 13:44:51 2015 +0200
@@ -126,7 +126,12 @@
         (dict(hours= -24 * 5), u'5 days ago'),
         (dict(months= -1), u'1 month ago'),
         (dict(months= -1, days= -2), u'1 month and 2 days ago'),
+        (dict(months= -1, days= -20), u'1 month and 19 days ago'),
         (dict(years= -1, months= -1), u'1 year and 1 month ago'),
+        (dict(years= -1, months= -10), u'1 year and 10 months ago'),
+        (dict(years= -2, months= -4), u'2 years and 4 months ago'),
+        (dict(years= -2, months= -11), u'2 years and 11 months ago'),
+        (dict(years= -3, months= -2), u'3 years and 2 months ago'),
     ])
     def test_age(self, age_args, expected):
         from kallithea.lib.utils2 import age
@@ -136,7 +141,29 @@
         self.assertEqual(age(n + delt(**age_args), now=n), expected)
 
     @parameterized.expand([
+        (dict(), u'just now'),
+        (dict(seconds= -1), u'1 second ago'),
+        (dict(seconds= -60 * 2), u'2 minutes ago'),
+        (dict(hours= -1), u'1 hour ago'),
+        (dict(hours= -24), u'1 day ago'),
+        (dict(hours= -24 * 5), u'5 days ago'),
+        (dict(months= -1), u'1 month ago'),
+        (dict(months= -1, days= -2), u'1 month ago'),
+        (dict(months= -1, days= -20), u'1 month ago'),
+        (dict(years= -1, months= -1), u'1 year ago'),
+        (dict(years= -1, months= -10), u'1 year ago'),
+        (dict(years= -2, months= -4), u'2 years ago'),
+        (dict(years= -2, months= -11), u'2 years ago'),
+        (dict(years= -3, months= -2), u'3 years ago'),
+    ])
+    def test_age_short(self, age_args, expected):
+        from kallithea.lib.utils2 import age
+        from dateutil import relativedelta
+        n = datetime.datetime(year=2012, month=5, day=17)
+        delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
+        self.assertEqual(age(n + delt(**age_args), show_short_version=True, now=n), expected)
 
+    @parameterized.expand([
         (dict(), u'just now'),
         (dict(seconds=1), u'in 1 second'),
         (dict(seconds=60 * 2), u'in 2 minutes'),
@@ -339,7 +366,6 @@
       ("_21/121", '21'),
       ("/_21/_12", '21'),
       ("_21/rc/foo", '21'),
-
     ])
     def test_get_repo_by_id(self, test, expected):
         from kallithea.lib.utils import _extract_id_from_repo_name