move sections
[python/dscho.git] / Lib / test / test_calendar.py
blobfad517c3f5efa6e92b3aee29c8d676b967dcdbb6
1 import calendar
2 import unittest
4 from test import test_support
7 result_2004_text = """
8 2004
10 January February March
11 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
12 1 2 3 4 1 1 2 3 4 5 6 7
13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
14 12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
15 19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
16 26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
18 April May June
19 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
20 1 2 3 4 1 2 1 2 3 4 5 6
21 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
22 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
23 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
24 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
27 July August September
28 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
29 1 2 3 4 1 1 2 3 4 5
30 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
31 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
32 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
33 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
34 30 31
36 October November December
37 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
38 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
39 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
40 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
41 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
42 25 26 27 28 29 30 31 29 30 27 28 29 30 31
43 """
45 result_2004_html = """
46 <?xml version="1.0" encoding="ascii"?>
47 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
48 <html>
49 <head>
50 <meta http-equiv="Content-Type" content="text/html; charset=ascii" />
51 <link rel="stylesheet" type="text/css" href="calendar.css" />
52 <title>Calendar for 2004</title>
53 </head>
54 <body>
55 <table border="0" cellpadding="0" cellspacing="0" class="year">
56 <tr><th colspan="3" class="year">2004</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
57 <tr><th colspan="7" class="month">January</th></tr>
58 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
59 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr>
60 <tr><td class="mon">5</td><td class="tue">6</td><td class="wed">7</td><td class="thu">8</td><td class="fri">9</td><td class="sat">10</td><td class="sun">11</td></tr>
61 <tr><td class="mon">12</td><td class="tue">13</td><td class="wed">14</td><td class="thu">15</td><td class="fri">16</td><td class="sat">17</td><td class="sun">18</td></tr>
62 <tr><td class="mon">19</td><td class="tue">20</td><td class="wed">21</td><td class="thu">22</td><td class="fri">23</td><td class="sat">24</td><td class="sun">25</td></tr>
63 <tr><td class="mon">26</td><td class="tue">27</td><td class="wed">28</td><td class="thu">29</td><td class="fri">30</td><td class="sat">31</td><td class="noday">&nbsp;</td></tr>
64 </table>
65 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
66 <tr><th colspan="7" class="month">February</th></tr>
67 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
68 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="sun">1</td></tr>
69 <tr><td class="mon">2</td><td class="tue">3</td><td class="wed">4</td><td class="thu">5</td><td class="fri">6</td><td class="sat">7</td><td class="sun">8</td></tr>
70 <tr><td class="mon">9</td><td class="tue">10</td><td class="wed">11</td><td class="thu">12</td><td class="fri">13</td><td class="sat">14</td><td class="sun">15</td></tr>
71 <tr><td class="mon">16</td><td class="tue">17</td><td class="wed">18</td><td class="thu">19</td><td class="fri">20</td><td class="sat">21</td><td class="sun">22</td></tr>
72 <tr><td class="mon">23</td><td class="tue">24</td><td class="wed">25</td><td class="thu">26</td><td class="fri">27</td><td class="sat">28</td><td class="sun">29</td></tr>
73 </table>
74 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
75 <tr><th colspan="7" class="month">March</th></tr>
76 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
77 <tr><td class="mon">1</td><td class="tue">2</td><td class="wed">3</td><td class="thu">4</td><td class="fri">5</td><td class="sat">6</td><td class="sun">7</td></tr>
78 <tr><td class="mon">8</td><td class="tue">9</td><td class="wed">10</td><td class="thu">11</td><td class="fri">12</td><td class="sat">13</td><td class="sun">14</td></tr>
79 <tr><td class="mon">15</td><td class="tue">16</td><td class="wed">17</td><td class="thu">18</td><td class="fri">19</td><td class="sat">20</td><td class="sun">21</td></tr>
80 <tr><td class="mon">22</td><td class="tue">23</td><td class="wed">24</td><td class="thu">25</td><td class="fri">26</td><td class="sat">27</td><td class="sun">28</td></tr>
81 <tr><td class="mon">29</td><td class="tue">30</td><td class="wed">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
82 </table>
83 </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
84 <tr><th colspan="7" class="month">April</th></tr>
85 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
86 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr>
87 <tr><td class="mon">5</td><td class="tue">6</td><td class="wed">7</td><td class="thu">8</td><td class="fri">9</td><td class="sat">10</td><td class="sun">11</td></tr>
88 <tr><td class="mon">12</td><td class="tue">13</td><td class="wed">14</td><td class="thu">15</td><td class="fri">16</td><td class="sat">17</td><td class="sun">18</td></tr>
89 <tr><td class="mon">19</td><td class="tue">20</td><td class="wed">21</td><td class="thu">22</td><td class="fri">23</td><td class="sat">24</td><td class="sun">25</td></tr>
90 <tr><td class="mon">26</td><td class="tue">27</td><td class="wed">28</td><td class="thu">29</td><td class="fri">30</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
91 </table>
92 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
93 <tr><th colspan="7" class="month">May</th></tr>
94 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
95 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="sat">1</td><td class="sun">2</td></tr>
96 <tr><td class="mon">3</td><td class="tue">4</td><td class="wed">5</td><td class="thu">6</td><td class="fri">7</td><td class="sat">8</td><td class="sun">9</td></tr>
97 <tr><td class="mon">10</td><td class="tue">11</td><td class="wed">12</td><td class="thu">13</td><td class="fri">14</td><td class="sat">15</td><td class="sun">16</td></tr>
98 <tr><td class="mon">17</td><td class="tue">18</td><td class="wed">19</td><td class="thu">20</td><td class="fri">21</td><td class="sat">22</td><td class="sun">23</td></tr>
99 <tr><td class="mon">24</td><td class="tue">25</td><td class="wed">26</td><td class="thu">27</td><td class="fri">28</td><td class="sat">29</td><td class="sun">30</td></tr>
100 <tr><td class="mon">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
101 </table>
102 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
103 <tr><th colspan="7" class="month">June</th></tr>
104 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
105 <tr><td class="noday">&nbsp;</td><td class="tue">1</td><td class="wed">2</td><td class="thu">3</td><td class="fri">4</td><td class="sat">5</td><td class="sun">6</td></tr>
106 <tr><td class="mon">7</td><td class="tue">8</td><td class="wed">9</td><td class="thu">10</td><td class="fri">11</td><td class="sat">12</td><td class="sun">13</td></tr>
107 <tr><td class="mon">14</td><td class="tue">15</td><td class="wed">16</td><td class="thu">17</td><td class="fri">18</td><td class="sat">19</td><td class="sun">20</td></tr>
108 <tr><td class="mon">21</td><td class="tue">22</td><td class="wed">23</td><td class="thu">24</td><td class="fri">25</td><td class="sat">26</td><td class="sun">27</td></tr>
109 <tr><td class="mon">28</td><td class="tue">29</td><td class="wed">30</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
110 </table>
111 </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
112 <tr><th colspan="7" class="month">July</th></tr>
113 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
114 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr>
115 <tr><td class="mon">5</td><td class="tue">6</td><td class="wed">7</td><td class="thu">8</td><td class="fri">9</td><td class="sat">10</td><td class="sun">11</td></tr>
116 <tr><td class="mon">12</td><td class="tue">13</td><td class="wed">14</td><td class="thu">15</td><td class="fri">16</td><td class="sat">17</td><td class="sun">18</td></tr>
117 <tr><td class="mon">19</td><td class="tue">20</td><td class="wed">21</td><td class="thu">22</td><td class="fri">23</td><td class="sat">24</td><td class="sun">25</td></tr>
118 <tr><td class="mon">26</td><td class="tue">27</td><td class="wed">28</td><td class="thu">29</td><td class="fri">30</td><td class="sat">31</td><td class="noday">&nbsp;</td></tr>
119 </table>
120 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
121 <tr><th colspan="7" class="month">August</th></tr>
122 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
123 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="sun">1</td></tr>
124 <tr><td class="mon">2</td><td class="tue">3</td><td class="wed">4</td><td class="thu">5</td><td class="fri">6</td><td class="sat">7</td><td class="sun">8</td></tr>
125 <tr><td class="mon">9</td><td class="tue">10</td><td class="wed">11</td><td class="thu">12</td><td class="fri">13</td><td class="sat">14</td><td class="sun">15</td></tr>
126 <tr><td class="mon">16</td><td class="tue">17</td><td class="wed">18</td><td class="thu">19</td><td class="fri">20</td><td class="sat">21</td><td class="sun">22</td></tr>
127 <tr><td class="mon">23</td><td class="tue">24</td><td class="wed">25</td><td class="thu">26</td><td class="fri">27</td><td class="sat">28</td><td class="sun">29</td></tr>
128 <tr><td class="mon">30</td><td class="tue">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
129 </table>
130 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
131 <tr><th colspan="7" class="month">September</th></tr>
132 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
133 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="wed">1</td><td class="thu">2</td><td class="fri">3</td><td class="sat">4</td><td class="sun">5</td></tr>
134 <tr><td class="mon">6</td><td class="tue">7</td><td class="wed">8</td><td class="thu">9</td><td class="fri">10</td><td class="sat">11</td><td class="sun">12</td></tr>
135 <tr><td class="mon">13</td><td class="tue">14</td><td class="wed">15</td><td class="thu">16</td><td class="fri">17</td><td class="sat">18</td><td class="sun">19</td></tr>
136 <tr><td class="mon">20</td><td class="tue">21</td><td class="wed">22</td><td class="thu">23</td><td class="fri">24</td><td class="sat">25</td><td class="sun">26</td></tr>
137 <tr><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
138 </table>
139 </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month">
140 <tr><th colspan="7" class="month">October</th></tr>
141 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
142 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="fri">1</td><td class="sat">2</td><td class="sun">3</td></tr>
143 <tr><td class="mon">4</td><td class="tue">5</td><td class="wed">6</td><td class="thu">7</td><td class="fri">8</td><td class="sat">9</td><td class="sun">10</td></tr>
144 <tr><td class="mon">11</td><td class="tue">12</td><td class="wed">13</td><td class="thu">14</td><td class="fri">15</td><td class="sat">16</td><td class="sun">17</td></tr>
145 <tr><td class="mon">18</td><td class="tue">19</td><td class="wed">20</td><td class="thu">21</td><td class="fri">22</td><td class="sat">23</td><td class="sun">24</td></tr>
146 <tr><td class="mon">25</td><td class="tue">26</td><td class="wed">27</td><td class="thu">28</td><td class="fri">29</td><td class="sat">30</td><td class="sun">31</td></tr>
147 </table>
148 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
149 <tr><th colspan="7" class="month">November</th></tr>
150 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
151 <tr><td class="mon">1</td><td class="tue">2</td><td class="wed">3</td><td class="thu">4</td><td class="fri">5</td><td class="sat">6</td><td class="sun">7</td></tr>
152 <tr><td class="mon">8</td><td class="tue">9</td><td class="wed">10</td><td class="thu">11</td><td class="fri">12</td><td class="sat">13</td><td class="sun">14</td></tr>
153 <tr><td class="mon">15</td><td class="tue">16</td><td class="wed">17</td><td class="thu">18</td><td class="fri">19</td><td class="sat">20</td><td class="sun">21</td></tr>
154 <tr><td class="mon">22</td><td class="tue">23</td><td class="wed">24</td><td class="thu">25</td><td class="fri">26</td><td class="sat">27</td><td class="sun">28</td></tr>
155 <tr><td class="mon">29</td><td class="tue">30</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
156 </table>
157 </td><td><table border="0" cellpadding="0" cellspacing="0" class="month">
158 <tr><th colspan="7" class="month">December</th></tr>
159 <tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
160 <tr><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="wed">1</td><td class="thu">2</td><td class="fri">3</td><td class="sat">4</td><td class="sun">5</td></tr>
161 <tr><td class="mon">6</td><td class="tue">7</td><td class="wed">8</td><td class="thu">9</td><td class="fri">10</td><td class="sat">11</td><td class="sun">12</td></tr>
162 <tr><td class="mon">13</td><td class="tue">14</td><td class="wed">15</td><td class="thu">16</td><td class="fri">17</td><td class="sat">18</td><td class="sun">19</td></tr>
163 <tr><td class="mon">20</td><td class="tue">21</td><td class="wed">22</td><td class="thu">23</td><td class="fri">24</td><td class="sat">25</td><td class="sun">26</td></tr>
164 <tr><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td><td class="fri">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
165 </table>
166 </td></tr></table></body>
167 </html>
171 class OutputTestCase(unittest.TestCase):
172 def normalize_calendar(self, s):
173 # Filters out locale dependent strings
174 def neitherspacenordigit(c):
175 return not c.isspace() and not c.isdigit()
177 lines = []
178 for line in s.splitlines(False):
179 # Drop texts, as they are locale dependent
180 if line and not filter(neitherspacenordigit, line):
181 lines.append(line)
182 return lines
184 def test_output(self):
185 self.assertEqual(
186 self.normalize_calendar(calendar.calendar(2004)),
187 self.normalize_calendar(result_2004_text)
190 def test_output_textcalendar(self):
191 self.assertEqual(
192 calendar.TextCalendar().formatyear(2004).strip(),
193 result_2004_text.strip()
196 def test_output_htmlcalendar(self):
197 self.assertEqual(
198 calendar.HTMLCalendar().formatyearpage(2004).strip(),
199 result_2004_html.strip()
203 class CalendarTestCase(unittest.TestCase):
204 def test_isleap(self):
205 # Make sure that the return is right for a few years, and
206 # ensure that the return values are 1 or 0, not just true or
207 # false (see SF bug #485794). Specific additional tests may
208 # be appropriate; this tests a single "cycle".
209 self.assertEqual(calendar.isleap(2000), 1)
210 self.assertEqual(calendar.isleap(2001), 0)
211 self.assertEqual(calendar.isleap(2002), 0)
212 self.assertEqual(calendar.isleap(2003), 0)
214 def test_setfirstweekday(self):
215 self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
216 self.assertRaises(ValueError, calendar.setfirstweekday, -1)
217 self.assertRaises(ValueError, calendar.setfirstweekday, 200)
218 orig = calendar.firstweekday()
219 calendar.setfirstweekday(calendar.SUNDAY)
220 self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
221 calendar.setfirstweekday(calendar.MONDAY)
222 self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
223 calendar.setfirstweekday(orig)
225 def test_enumerateweekdays(self):
226 self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10)
227 self.assertRaises(IndexError, calendar.day_name.__getitem__, 10)
228 self.assertEqual(len([d for d in calendar.day_abbr]), 7)
230 def test_days(self):
231 for attr in "day_name", "day_abbr":
232 value = getattr(calendar, attr)
233 self.assertEqual(len(value), 7)
234 self.assertEqual(len(value[:]), 7)
235 # ensure they're all unique
236 self.assertEqual(len(set(value)), 7)
237 # verify it "acts like a sequence" in two forms of iteration
238 self.assertEqual(value[::-1], list(reversed(value)))
240 def test_months(self):
241 for attr in "month_name", "month_abbr":
242 value = getattr(calendar, attr)
243 self.assertEqual(len(value), 13)
244 self.assertEqual(len(value[:]), 13)
245 self.assertEqual(value[0], "")
246 # ensure they're all unique
247 self.assertEqual(len(set(value)), 13)
248 # verify it "acts like a sequence" in two forms of iteration
249 self.assertEqual(value[::-1], list(reversed(value)))
252 class MonthCalendarTestCase(unittest.TestCase):
253 def setUp(self):
254 self.oldfirstweekday = calendar.firstweekday()
255 calendar.setfirstweekday(self.firstweekday)
257 def tearDown(self):
258 calendar.setfirstweekday(self.oldfirstweekday)
260 def check_weeks(self, year, month, weeks):
261 cal = calendar.monthcalendar(year, month)
262 self.assertEqual(len(cal), len(weeks))
263 for i in xrange(len(weeks)):
264 self.assertEqual(weeks[i], sum(day != 0 for day in cal[i]))
267 class MondayTestCase(MonthCalendarTestCase):
268 firstweekday = calendar.MONDAY
270 def test_february(self):
271 # A 28-day february starting on monday (7+7+7+7 days)
272 self.check_weeks(1999, 2, (7, 7, 7, 7))
274 # A 28-day february starting on tuesday (6+7+7+7+1 days)
275 self.check_weeks(2005, 2, (6, 7, 7, 7, 1))
277 # A 28-day february starting on sunday (1+7+7+7+6 days)
278 self.check_weeks(1987, 2, (1, 7, 7, 7, 6))
280 # A 29-day february starting on monday (7+7+7+7+1 days)
281 self.check_weeks(1988, 2, (7, 7, 7, 7, 1))
283 # A 29-day february starting on tuesday (6+7+7+7+2 days)
284 self.check_weeks(1972, 2, (6, 7, 7, 7, 2))
286 # A 29-day february starting on sunday (1+7+7+7+7 days)
287 self.check_weeks(2004, 2, (1, 7, 7, 7, 7))
289 def test_april(self):
290 # A 30-day april starting on monday (7+7+7+7+2 days)
291 self.check_weeks(1935, 4, (7, 7, 7, 7, 2))
293 # A 30-day april starting on tuesday (6+7+7+7+3 days)
294 self.check_weeks(1975, 4, (6, 7, 7, 7, 3))
296 # A 30-day april starting on sunday (1+7+7+7+7+1 days)
297 self.check_weeks(1945, 4, (1, 7, 7, 7, 7, 1))
299 # A 30-day april starting on saturday (2+7+7+7+7 days)
300 self.check_weeks(1995, 4, (2, 7, 7, 7, 7))
302 # A 30-day april starting on friday (3+7+7+7+6 days)
303 self.check_weeks(1994, 4, (3, 7, 7, 7, 6))
305 def test_december(self):
306 # A 31-day december starting on monday (7+7+7+7+3 days)
307 self.check_weeks(1980, 12, (7, 7, 7, 7, 3))
309 # A 31-day december starting on tuesday (6+7+7+7+4 days)
310 self.check_weeks(1987, 12, (6, 7, 7, 7, 4))
312 # A 31-day december starting on sunday (1+7+7+7+7+2 days)
313 self.check_weeks(1968, 12, (1, 7, 7, 7, 7, 2))
315 # A 31-day december starting on thursday (4+7+7+7+6 days)
316 self.check_weeks(1988, 12, (4, 7, 7, 7, 6))
318 # A 31-day december starting on friday (3+7+7+7+7 days)
319 self.check_weeks(2017, 12, (3, 7, 7, 7, 7))
321 # A 31-day december starting on saturday (2+7+7+7+7+1 days)
322 self.check_weeks(2068, 12, (2, 7, 7, 7, 7, 1))
325 class SundayTestCase(MonthCalendarTestCase):
326 firstweekday = calendar.SUNDAY
328 def test_february(self):
329 # A 28-day february starting on sunday (7+7+7+7 days)
330 self.check_weeks(2009, 2, (7, 7, 7, 7))
332 # A 28-day february starting on monday (6+7+7+7+1 days)
333 self.check_weeks(1999, 2, (6, 7, 7, 7, 1))
335 # A 28-day february starting on saturday (1+7+7+7+6 days)
336 self.check_weeks(1997, 2, (1, 7, 7, 7, 6))
338 # A 29-day february starting on sunday (7+7+7+7+1 days)
339 self.check_weeks(2004, 2, (7, 7, 7, 7, 1))
341 # A 29-day february starting on monday (6+7+7+7+2 days)
342 self.check_weeks(1960, 2, (6, 7, 7, 7, 2))
344 # A 29-day february starting on saturday (1+7+7+7+7 days)
345 self.check_weeks(1964, 2, (1, 7, 7, 7, 7))
347 def test_april(self):
348 # A 30-day april starting on sunday (7+7+7+7+2 days)
349 self.check_weeks(1923, 4, (7, 7, 7, 7, 2))
351 # A 30-day april starting on monday (6+7+7+7+3 days)
352 self.check_weeks(1918, 4, (6, 7, 7, 7, 3))
354 # A 30-day april starting on saturday (1+7+7+7+7+1 days)
355 self.check_weeks(1950, 4, (1, 7, 7, 7, 7, 1))
357 # A 30-day april starting on friday (2+7+7+7+7 days)
358 self.check_weeks(1960, 4, (2, 7, 7, 7, 7))
360 # A 30-day april starting on thursday (3+7+7+7+6 days)
361 self.check_weeks(1909, 4, (3, 7, 7, 7, 6))
363 def test_december(self):
364 # A 31-day december starting on sunday (7+7+7+7+3 days)
365 self.check_weeks(2080, 12, (7, 7, 7, 7, 3))
367 # A 31-day december starting on monday (6+7+7+7+4 days)
368 self.check_weeks(1941, 12, (6, 7, 7, 7, 4))
370 # A 31-day december starting on saturday (1+7+7+7+7+2 days)
371 self.check_weeks(1923, 12, (1, 7, 7, 7, 7, 2))
373 # A 31-day december starting on wednesday (4+7+7+7+6 days)
374 self.check_weeks(1948, 12, (4, 7, 7, 7, 6))
376 # A 31-day december starting on thursday (3+7+7+7+7 days)
377 self.check_weeks(1927, 12, (3, 7, 7, 7, 7))
379 # A 31-day december starting on friday (2+7+7+7+7+1 days)
380 self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1))
383 def test_main():
384 test_support.run_unittest(
385 OutputTestCase,
386 CalendarTestCase,
387 MondayTestCase,
388 SundayTestCase
392 if __name__ == "__main__":
393 test_main()