MCPcopy Index your code
hub / github.com/python/cpython / test_isocalendar

Method test_isocalendar

Lib/test/datetimetester.py:1503–1531  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1501 self.assertEqual(self.theclass(1956, 1, 2+i).isoweekday(), i+1)
1502
1503 def test_isocalendar(self):
1504 # Check examples from
1505 # http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
1506 week_mondays = [
1507 ((2003, 12, 22), (2003, 52, 1)),
1508 ((2003, 12, 29), (2004, 1, 1)),
1509 ((2004, 1, 5), (2004, 2, 1)),
1510 ((2009, 12, 21), (2009, 52, 1)),
1511 ((2009, 12, 28), (2009, 53, 1)),
1512 ((2010, 1, 4), (2010, 1, 1)),
1513 ]
1514
1515 test_cases = []
1516 for cal_date, iso_date in week_mondays:
1517 base_date = self.theclass(*cal_date)
1518 # Adds one test case for every day of the specified weeks
1519 for i in range(7):
1520 new_date = base_date + timedelta(i)
1521 new_iso = iso_date[0:2] + (iso_date[2] + i,)
1522 test_cases.append((new_date, new_iso))
1523
1524 for d, exp_iso in test_cases:
1525 with self.subTest(d=d, comparison="tuple"):
1526 self.assertEqual(d.isocalendar(), exp_iso)
1527
1528 # Check that the tuple contents are accessible by field name
1529 with self.subTest(d=d, comparison="fields"):
1530 t = d.isocalendar()
1531 self.assertEqual((t.year, t.week, t.weekday), exp_iso)
1532
1533 def test_isocalendar_pickling(self):
1534 """Test that the result of datetime.isocalendar() can be pickled.

Callers

nothing calls this directly

Calls 5

timedeltaClass · 0.90
isocalendarMethod · 0.80
appendMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected