Changeset 391 for python/trunk/Lib/test/test_calendar.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_calendar.py
r2 r391 3 3 4 4 from test import test_support 5 import locale 6 import datetime 5 7 6 8 … … 249 251 self.assertEqual(value[::-1], list(reversed(value))) 250 252 253 def test_localecalendars(self): 254 # ensure that Locale{Text,HTML}Calendar resets the locale properly 255 # (it is still not thread-safe though) 256 old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) 257 try: 258 cal = calendar.LocaleTextCalendar(locale='') 259 local_weekday = cal.formatweekday(1, 10) 260 local_month = cal.formatmonthname(2010, 10, 10) 261 except locale.Error: 262 # cannot set the system default locale -- skip rest of test 263 raise unittest.SkipTest('cannot set the system default locale') 264 # should be encodable 265 local_weekday.encode('utf-8') 266 local_month.encode('utf-8') 267 self.assertEqual(len(local_weekday), 10) 268 self.assertGreaterEqual(len(local_month), 10) 269 cal = calendar.LocaleHTMLCalendar(locale='') 270 local_weekday = cal.formatweekday(1) 271 local_month = cal.formatmonthname(2010, 10) 272 # should be encodable 273 local_weekday.encode('utf-8') 274 local_month.encode('utf-8') 275 new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) 276 self.assertEqual(old_october, new_october) 277 278 def test_itermonthdates(self): 279 # ensure itermonthdates doesn't overflow after datetime.MAXYEAR 280 # see #15421 281 list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) 282 251 283 252 284 class MonthCalendarTestCase(unittest.TestCase): … … 381 413 382 414 415 class MonthRangeTestCase(unittest.TestCase): 416 def test_january(self): 417 # Tests valid lower boundary case. 418 self.assertEqual(calendar.monthrange(2004,1), (3,31)) 419 420 def test_february_leap(self): 421 # Tests February during leap year. 422 self.assertEqual(calendar.monthrange(2004,2), (6,29)) 423 424 def test_february_nonleap(self): 425 # Tests February in non-leap year. 426 self.assertEqual(calendar.monthrange(2010,2), (0,28)) 427 428 def test_december(self): 429 # Tests valid upper boundary case. 430 self.assertEqual(calendar.monthrange(2004,12), (2,31)) 431 432 def test_zeroth_month(self): 433 # Tests low invalid boundary case. 434 with self.assertRaises(calendar.IllegalMonthError): 435 calendar.monthrange(2004, 0) 436 437 def test_thirteenth_month(self): 438 # Tests high invalid boundary case. 439 with self.assertRaises(calendar.IllegalMonthError): 440 calendar.monthrange(2004, 13) 441 442 class LeapdaysTestCase(unittest.TestCase): 443 def test_no_range(self): 444 # test when no range i.e. two identical years as args 445 self.assertEqual(calendar.leapdays(2010,2010), 0) 446 447 def test_no_leapdays(self): 448 # test when no leap years in range 449 self.assertEqual(calendar.leapdays(2010,2011), 0) 450 451 def test_no_leapdays_upper_boundary(self): 452 # test no leap years in range, when upper boundary is a leap year 453 self.assertEqual(calendar.leapdays(2010,2012), 0) 454 455 def test_one_leapday_lower_boundary(self): 456 # test when one leap year in range, lower boundary is leap year 457 self.assertEqual(calendar.leapdays(2012,2013), 1) 458 459 def test_several_leapyears_in_range(self): 460 self.assertEqual(calendar.leapdays(1997,2020), 5) 461 462 383 463 def test_main(): 384 464 test_support.run_unittest( … … 386 466 CalendarTestCase, 387 467 MondayTestCase, 388 SundayTestCase 468 SundayTestCase, 469 MonthRangeTestCase, 470 LeapdaysTestCase, 389 471 ) 390 472
Note:
See TracChangeset
for help on using the changeset viewer.