Mercurial > babel > old > mirror
comparison babel/tests/dates.py @ 514:b226c4d5386e
add tests from r563 to trunk
author | fschwarz |
---|---|
date | Fri, 04 Mar 2011 22:36:22 +0000 |
parents | a3ddb13ff2a6 |
children | e4d08b21c49b |
comparison
equal
deleted
inserted
replaced
508:db2bf9d221fc | 514:b226c4d5386e |
---|---|
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://babel.edgewall.org/log/. | 12 # history and logs, available at http://babel.edgewall.org/log/. |
13 | 13 |
14 from datetime import date, datetime, time | 14 from datetime import date, datetime, time |
15 import doctest | 15 import doctest |
16 import new | |
16 import unittest | 17 import unittest |
17 | 18 |
18 from pytz import timezone | 19 from pytz import timezone |
19 | 20 |
20 from babel import dates | 21 from babel import dates |
22 from babel.util import FixedOffsetTimezone | |
21 | 23 |
22 | 24 |
23 class DateTimeFormatTestCase(unittest.TestCase): | 25 class DateTimeFormatTestCase(unittest.TestCase): |
24 | 26 |
25 def test_quarter_format(self): | 27 def test_quarter_format(self): |
260 string = dates.format_timedelta(timedelta(seconds=42), | 262 string = dates.format_timedelta(timedelta(seconds=42), |
261 granularity='hour', locale='en') | 263 granularity='hour', locale='en') |
262 self.assertEqual('1 hour', string) | 264 self.assertEqual('1 hour', string) |
263 | 265 |
264 | 266 |
267 class TimeZoneAdjustTestCase(unittest.TestCase): | |
268 def _utc(self): | |
269 UTC = FixedOffsetTimezone(0, 'UTC') | |
270 def fake_localize(self, dt, is_dst=False): | |
271 raise NotImplementedError() | |
272 UTC.localize = new.instancemethod(fake_localize, UTC, UTC.__class__) | |
273 # This is important to trigger the actual bug (#257) | |
274 self.assertEqual(False, hasattr(UTC, 'normalize')) | |
275 return UTC | |
276 | |
277 def test_can_format_time_with_non_pytz_timezone(self): | |
278 # regression test for #257 | |
279 utc = self._utc() | |
280 t = datetime(2007, 4, 1, 15, 30, tzinfo=utc) | |
281 formatted_time = dates.format_time(t, 'long', tzinfo=utc, locale='en') | |
282 self.assertEqual('3:30:00 PM +0000', formatted_time) | |
283 | |
284 | |
265 def suite(): | 285 def suite(): |
266 suite = unittest.TestSuite() | 286 suite = unittest.TestSuite() |
267 suite.addTest(doctest.DocTestSuite(dates)) | 287 suite.addTest(doctest.DocTestSuite(dates)) |
268 suite.addTest(unittest.makeSuite(DateTimeFormatTestCase)) | 288 suite.addTest(unittest.makeSuite(DateTimeFormatTestCase)) |
269 suite.addTest(unittest.makeSuite(FormatDateTestCase)) | 289 suite.addTest(unittest.makeSuite(FormatDateTestCase)) |
270 suite.addTest(unittest.makeSuite(FormatTimeTestCase)) | 290 suite.addTest(unittest.makeSuite(FormatTimeTestCase)) |
291 suite.addTest(unittest.makeSuite(TimeZoneAdjustTestCase)) | |
271 return suite | 292 return suite |
272 | 293 |
273 | 294 |
274 if __name__ == '__main__': | 295 if __name__ == '__main__': |
275 unittest.main(defaultTest='suite') | 296 unittest.main(defaultTest='suite') |