Mercurial > kallithea
comparison rhodecode/tests/test_libs.py @ 3644:71860d0737e7 beta
- age tests cannot be dynamic, there are cases when age calculation
doesn't work
- use parametrized to test age
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 31 Mar 2013 19:31:50 +0200 |
parents | a9adca4ba3c9 |
children |
comparison
equal
deleted
inserted
replaced
3643:2a7cbc53f65a | 3644:71860d0737e7 |
---|---|
112 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john', | 112 'first', 'marcink', 'lukaszb', 'one_more22', 'MARCIN', 'maRCiN', 'john', |
113 'marian.user', 'marco-polo', 'marco_polo' | 113 'marian.user', 'marco-polo', 'marco_polo' |
114 ], key=lambda k: k.lower()) | 114 ], key=lambda k: k.lower()) |
115 self.assertEqual(s, extract_mentioned_users(sample)) | 115 self.assertEqual(s, extract_mentioned_users(sample)) |
116 | 116 |
117 def test_age(self): | 117 @parameterized.expand([ |
118 (dict(), u'just now'), | |
119 (dict(seconds= -1), u'1 second ago'), | |
120 (dict(seconds= -60 * 2), u'2 minutes ago'), | |
121 (dict(hours= -1), u'1 hour ago'), | |
122 (dict(hours= -24), u'1 day ago'), | |
123 (dict(hours= -24 * 5), u'5 days ago'), | |
124 (dict(months= -1), u'1 month ago'), | |
125 (dict(months= -1, days= -2), u'1 month and 2 days ago'), | |
126 (dict(years= -1, months= -1), u'1 year and 1 month ago'), | |
127 ]) | |
128 def test_age(self, age_args, expected): | |
118 from rhodecode.lib.utils2 import age | 129 from rhodecode.lib.utils2 import age |
119 from dateutil import relativedelta | 130 from dateutil import relativedelta |
120 n = datetime.datetime.now() | 131 n = datetime.datetime(year=2012, month=5, day=17) |
121 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) | 132 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) |
122 | 133 self.assertEqual(age(n + delt(**age_args), now=n), expected) |
123 self.assertEqual(age(n), u'just now') | 134 |
124 self.assertEqual(age(n + delt(seconds=-1)), u'1 second ago') | 135 @parameterized.expand([ |
125 self.assertEqual(age(n + delt(seconds=-60 * 2)), u'2 minutes ago') | 136 |
126 self.assertEqual(age(n + delt(hours=-1)), u'1 hour ago') | 137 (dict(), u'just now'), |
127 self.assertEqual(age(n + delt(hours=-24)), u'1 day ago') | 138 (dict(seconds=1), u'in 1 second'), |
128 self.assertEqual(age(n + delt(hours=-24 * 5)), u'5 days ago') | 139 (dict(seconds=60 * 2), u'in 2 minutes'), |
129 self.assertEqual(age(n + delt(months=-1)), u'1 month ago') | 140 (dict(hours=1), u'in 1 hour'), |
130 self.assertEqual(age(n + delt(months=-1, days=-2)), u'1 month and 2 days ago') | 141 (dict(hours=24), u'in 1 day'), |
131 self.assertEqual(age(n + delt(years=-1, months=-1)), u'1 year and 1 month ago') | 142 (dict(hours=24 * 5), u'in 5 days'), |
132 | 143 (dict(months=1), u'in 1 month'), |
133 def test_age_in_future(self): | 144 (dict(months=1, days=1), u'in 1 month and 1 day'), |
145 (dict(years=1, months=1), u'in 1 year and 1 month') | |
146 ]) | |
147 def test_age_in_future(self, age_args, expected): | |
134 from rhodecode.lib.utils2 import age | 148 from rhodecode.lib.utils2 import age |
135 from dateutil import relativedelta | 149 from dateutil import relativedelta |
136 n = datetime.datetime.now() | 150 n = datetime.datetime(year=2012, month=5, day=17) |
137 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) | 151 delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) |
138 | 152 self.assertEqual(age(n + delt(**age_args), now=n), expected) |
139 self.assertEqual(age(n), u'just now') | |
140 self.assertEqual(age(n + delt(seconds=1)), u'in 1 second') | |
141 self.assertEqual(age(n + delt(seconds=60 * 2)), u'in 2 minutes') | |
142 self.assertEqual(age(n + delt(hours=1)), u'in 1 hour') | |
143 self.assertEqual(age(n + delt(hours=24)), u'in 1 day') | |
144 self.assertEqual(age(n + delt(hours=24 * 5)), u'in 5 days') | |
145 self.assertEqual(age(n + delt(months=1)), u'in 1 month') | |
146 self.assertEqual(age(n + delt(months=1, days=1)), u'in 1 month and 1 day') | |
147 self.assertEqual(age(n + delt(years=1, months=1)), u'in 1 year and 1 month') | |
148 | 153 |
149 def test_tag_exctrator(self): | 154 def test_tag_exctrator(self): |
150 sample = ( | 155 sample = ( |
151 "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]" | 156 "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]" |
152 "[requires] [stale] [see<>=>] [see => http://url.com]" | 157 "[requires] [stale] [see<>=>] [see => http://url.com]" |
214 Changes `some text url[foo]` => `some text <a href="/">foo</a> | 219 Changes `some text url[foo]` => `some text <a href="/">foo</a> |
215 | 220 |
216 :param text: | 221 :param text: |
217 """ | 222 """ |
218 import re | 223 import re |
219 #quickly change expected url[] into a link | 224 # quickly change expected url[] into a link |
220 URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])') | 225 URL_PAT = re.compile(r'(?:url\[)(.+?)(?:\])') |
221 | 226 |
222 def url_func(match_obj): | 227 def url_func(match_obj): |
223 _url = match_obj.groups()[0] | 228 _url = match_obj.groups()[0] |
224 return tmpl % (url_ or '/some-url', _url) | 229 return tmpl % (url_ or '/some-url', _url) |