1 | n/a | import calendar |
---|
2 | n/a | import unittest |
---|
3 | n/a | |
---|
4 | n/a | from test import support |
---|
5 | n/a | from test.support.script_helper import assert_python_ok, assert_python_failure |
---|
6 | n/a | import time |
---|
7 | n/a | import locale |
---|
8 | n/a | import sys |
---|
9 | n/a | import datetime |
---|
10 | n/a | import os |
---|
11 | n/a | |
---|
12 | n/a | result_2004_01_text = """\ |
---|
13 | n/a | January 2004 |
---|
14 | n/a | Mo Tu We Th Fr Sa Su |
---|
15 | n/a | 1 2 3 4 |
---|
16 | n/a | 5 6 7 8 9 10 11 |
---|
17 | n/a | 12 13 14 15 16 17 18 |
---|
18 | n/a | 19 20 21 22 23 24 25 |
---|
19 | n/a | 26 27 28 29 30 31 |
---|
20 | n/a | """ |
---|
21 | n/a | |
---|
22 | n/a | result_2004_text = """\ |
---|
23 | n/a | 2004 |
---|
24 | n/a | |
---|
25 | n/a | January February March |
---|
26 | n/a | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
---|
27 | n/a | 1 2 3 4 1 1 2 3 4 5 6 7 |
---|
28 | n/a | 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14 |
---|
29 | n/a | 12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21 |
---|
30 | n/a | 19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28 |
---|
31 | n/a | 26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31 |
---|
32 | n/a | |
---|
33 | n/a | April May June |
---|
34 | n/a | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
---|
35 | n/a | 1 2 3 4 1 2 1 2 3 4 5 6 |
---|
36 | n/a | 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13 |
---|
37 | n/a | 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20 |
---|
38 | n/a | 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27 |
---|
39 | n/a | 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 |
---|
40 | n/a | 31 |
---|
41 | n/a | |
---|
42 | n/a | July August September |
---|
43 | n/a | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
---|
44 | n/a | 1 2 3 4 1 1 2 3 4 5 |
---|
45 | n/a | 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12 |
---|
46 | n/a | 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19 |
---|
47 | n/a | 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26 |
---|
48 | n/a | 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 |
---|
49 | n/a | 30 31 |
---|
50 | n/a | |
---|
51 | n/a | October November December |
---|
52 | n/a | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
---|
53 | n/a | 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 |
---|
54 | n/a | 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12 |
---|
55 | n/a | 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19 |
---|
56 | n/a | 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26 |
---|
57 | n/a | 25 26 27 28 29 30 31 29 30 27 28 29 30 31 |
---|
58 | n/a | """ |
---|
59 | n/a | |
---|
60 | n/a | result_2004_html = """\ |
---|
61 | n/a | <?xml version="1.0" encoding="%(e)s"?> |
---|
62 | n/a | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
---|
63 | n/a | <html> |
---|
64 | n/a | <head> |
---|
65 | n/a | <meta http-equiv="Content-Type" content="text/html; charset=%(e)s" /> |
---|
66 | n/a | <link rel="stylesheet" type="text/css" href="calendar.css" /> |
---|
67 | n/a | <title>Calendar for 2004</title> |
---|
68 | n/a | </head> |
---|
69 | n/a | <body> |
---|
70 | n/a | <table border="0" cellpadding="0" cellspacing="0" class="year"> |
---|
71 | n/a | <tr><th colspan="3" class="year">2004</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
72 | n/a | <tr><th colspan="7" class="month">January</th></tr> |
---|
73 | n/a | <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> |
---|
74 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr> |
---|
75 | n/a | <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> |
---|
76 | n/a | <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> |
---|
77 | n/a | <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> |
---|
78 | n/a | <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"> </td></tr> |
---|
79 | n/a | </table> |
---|
80 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
81 | n/a | <tr><th colspan="7" class="month">February</th></tr> |
---|
82 | n/a | <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> |
---|
83 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="sun">1</td></tr> |
---|
84 | n/a | <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> |
---|
85 | n/a | <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> |
---|
86 | n/a | <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> |
---|
87 | n/a | <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> |
---|
88 | n/a | </table> |
---|
89 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
90 | n/a | <tr><th colspan="7" class="month">March</th></tr> |
---|
91 | n/a | <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> |
---|
92 | n/a | <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> |
---|
93 | n/a | <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> |
---|
94 | n/a | <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> |
---|
95 | n/a | <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> |
---|
96 | n/a | <tr><td class="mon">29</td><td class="tue">30</td><td class="wed">31</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
97 | n/a | </table> |
---|
98 | n/a | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
99 | n/a | <tr><th colspan="7" class="month">April</th></tr> |
---|
100 | n/a | <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> |
---|
101 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr> |
---|
102 | n/a | <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> |
---|
103 | n/a | <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> |
---|
104 | n/a | <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> |
---|
105 | n/a | <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"> </td><td class="noday"> </td></tr> |
---|
106 | n/a | </table> |
---|
107 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
108 | n/a | <tr><th colspan="7" class="month">May</th></tr> |
---|
109 | n/a | <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> |
---|
110 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="sat">1</td><td class="sun">2</td></tr> |
---|
111 | n/a | <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> |
---|
112 | n/a | <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> |
---|
113 | n/a | <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> |
---|
114 | n/a | <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> |
---|
115 | n/a | <tr><td class="mon">31</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
116 | n/a | </table> |
---|
117 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
118 | n/a | <tr><th colspan="7" class="month">June</th></tr> |
---|
119 | n/a | <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> |
---|
120 | n/a | <tr><td class="noday"> </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> |
---|
121 | n/a | <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> |
---|
122 | n/a | <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> |
---|
123 | n/a | <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> |
---|
124 | n/a | <tr><td class="mon">28</td><td class="tue">29</td><td class="wed">30</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
125 | n/a | </table> |
---|
126 | n/a | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
127 | n/a | <tr><th colspan="7" class="month">July</th></tr> |
---|
128 | n/a | <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> |
---|
129 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="thu">1</td><td class="fri">2</td><td class="sat">3</td><td class="sun">4</td></tr> |
---|
130 | n/a | <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> |
---|
131 | n/a | <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> |
---|
132 | n/a | <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> |
---|
133 | n/a | <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"> </td></tr> |
---|
134 | n/a | </table> |
---|
135 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
136 | n/a | <tr><th colspan="7" class="month">August</th></tr> |
---|
137 | n/a | <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> |
---|
138 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="sun">1</td></tr> |
---|
139 | n/a | <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> |
---|
140 | n/a | <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> |
---|
141 | n/a | <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> |
---|
142 | n/a | <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> |
---|
143 | n/a | <tr><td class="mon">30</td><td class="tue">31</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
144 | n/a | </table> |
---|
145 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
146 | n/a | <tr><th colspan="7" class="month">September</th></tr> |
---|
147 | n/a | <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> |
---|
148 | n/a | <tr><td class="noday"> </td><td class="noday"> </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> |
---|
149 | n/a | <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> |
---|
150 | n/a | <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> |
---|
151 | n/a | <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> |
---|
152 | n/a | <tr><td class="mon">27</td><td class="tue">28</td><td class="wed">29</td><td class="thu">30</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
153 | n/a | </table> |
---|
154 | n/a | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
155 | n/a | <tr><th colspan="7" class="month">October</th></tr> |
---|
156 | n/a | <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> |
---|
157 | n/a | <tr><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="fri">1</td><td class="sat">2</td><td class="sun">3</td></tr> |
---|
158 | n/a | <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> |
---|
159 | n/a | <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> |
---|
160 | n/a | <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> |
---|
161 | n/a | <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> |
---|
162 | n/a | </table> |
---|
163 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
164 | n/a | <tr><th colspan="7" class="month">November</th></tr> |
---|
165 | n/a | <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> |
---|
166 | n/a | <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> |
---|
167 | n/a | <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> |
---|
168 | n/a | <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> |
---|
169 | n/a | <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> |
---|
170 | n/a | <tr><td class="mon">29</td><td class="tue">30</td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td><td class="noday"> </td></tr> |
---|
171 | n/a | </table> |
---|
172 | n/a | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
---|
173 | n/a | <tr><th colspan="7" class="month">December</th></tr> |
---|
174 | n/a | <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> |
---|
175 | n/a | <tr><td class="noday"> </td><td class="noday"> </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> |
---|
176 | n/a | <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> |
---|
177 | n/a | <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> |
---|
178 | n/a | <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> |
---|
179 | n/a | <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"> </td><td class="noday"> </td></tr> |
---|
180 | n/a | </table> |
---|
181 | n/a | </td></tr></table></body> |
---|
182 | n/a | </html> |
---|
183 | n/a | """ |
---|
184 | n/a | |
---|
185 | n/a | result_2004_days = [ |
---|
186 | n/a | [[[0, 0, 0, 1, 2, 3, 4], |
---|
187 | n/a | [5, 6, 7, 8, 9, 10, 11], |
---|
188 | n/a | [12, 13, 14, 15, 16, 17, 18], |
---|
189 | n/a | [19, 20, 21, 22, 23, 24, 25], |
---|
190 | n/a | [26, 27, 28, 29, 30, 31, 0]], |
---|
191 | n/a | [[0, 0, 0, 0, 0, 0, 1], |
---|
192 | n/a | [2, 3, 4, 5, 6, 7, 8], |
---|
193 | n/a | [9, 10, 11, 12, 13, 14, 15], |
---|
194 | n/a | [16, 17, 18, 19, 20, 21, 22], |
---|
195 | n/a | [23, 24, 25, 26, 27, 28, 29]], |
---|
196 | n/a | [[1, 2, 3, 4, 5, 6, 7], |
---|
197 | n/a | [8, 9, 10, 11, 12, 13, 14], |
---|
198 | n/a | [15, 16, 17, 18, 19, 20, 21], |
---|
199 | n/a | [22, 23, 24, 25, 26, 27, 28], |
---|
200 | n/a | [29, 30, 31, 0, 0, 0, 0]]], |
---|
201 | n/a | [[[0, 0, 0, 1, 2, 3, 4], |
---|
202 | n/a | [5, 6, 7, 8, 9, 10, 11], |
---|
203 | n/a | [12, 13, 14, 15, 16, 17, 18], |
---|
204 | n/a | [19, 20, 21, 22, 23, 24, 25], |
---|
205 | n/a | [26, 27, 28, 29, 30, 0, 0]], |
---|
206 | n/a | [[0, 0, 0, 0, 0, 1, 2], |
---|
207 | n/a | [3, 4, 5, 6, 7, 8, 9], |
---|
208 | n/a | [10, 11, 12, 13, 14, 15, 16], |
---|
209 | n/a | [17, 18, 19, 20, 21, 22, 23], |
---|
210 | n/a | [24, 25, 26, 27, 28, 29, 30], |
---|
211 | n/a | [31, 0, 0, 0, 0, 0, 0]], |
---|
212 | n/a | [[0, 1, 2, 3, 4, 5, 6], |
---|
213 | n/a | [7, 8, 9, 10, 11, 12, 13], |
---|
214 | n/a | [14, 15, 16, 17, 18, 19, 20], |
---|
215 | n/a | [21, 22, 23, 24, 25, 26, 27], |
---|
216 | n/a | [28, 29, 30, 0, 0, 0, 0]]], |
---|
217 | n/a | [[[0, 0, 0, 1, 2, 3, 4], |
---|
218 | n/a | [5, 6, 7, 8, 9, 10, 11], |
---|
219 | n/a | [12, 13, 14, 15, 16, 17, 18], |
---|
220 | n/a | [19, 20, 21, 22, 23, 24, 25], |
---|
221 | n/a | [26, 27, 28, 29, 30, 31, 0]], |
---|
222 | n/a | [[0, 0, 0, 0, 0, 0, 1], |
---|
223 | n/a | [2, 3, 4, 5, 6, 7, 8], |
---|
224 | n/a | [9, 10, 11, 12, 13, 14, 15], |
---|
225 | n/a | [16, 17, 18, 19, 20, 21, 22], |
---|
226 | n/a | [23, 24, 25, 26, 27, 28, 29], |
---|
227 | n/a | [30, 31, 0, 0, 0, 0, 0]], |
---|
228 | n/a | [[0, 0, 1, 2, 3, 4, 5], |
---|
229 | n/a | [6, 7, 8, 9, 10, 11, 12], |
---|
230 | n/a | [13, 14, 15, 16, 17, 18, 19], |
---|
231 | n/a | [20, 21, 22, 23, 24, 25, 26], |
---|
232 | n/a | [27, 28, 29, 30, 0, 0, 0]]], |
---|
233 | n/a | [[[0, 0, 0, 0, 1, 2, 3], |
---|
234 | n/a | [4, 5, 6, 7, 8, 9, 10], |
---|
235 | n/a | [11, 12, 13, 14, 15, 16, 17], |
---|
236 | n/a | [18, 19, 20, 21, 22, 23, 24], |
---|
237 | n/a | [25, 26, 27, 28, 29, 30, 31]], |
---|
238 | n/a | [[1, 2, 3, 4, 5, 6, 7], |
---|
239 | n/a | [8, 9, 10, 11, 12, 13, 14], |
---|
240 | n/a | [15, 16, 17, 18, 19, 20, 21], |
---|
241 | n/a | [22, 23, 24, 25, 26, 27, 28], |
---|
242 | n/a | [29, 30, 0, 0, 0, 0, 0]], |
---|
243 | n/a | [[0, 0, 1, 2, 3, 4, 5], |
---|
244 | n/a | [6, 7, 8, 9, 10, 11, 12], |
---|
245 | n/a | [13, 14, 15, 16, 17, 18, 19], |
---|
246 | n/a | [20, 21, 22, 23, 24, 25, 26], |
---|
247 | n/a | [27, 28, 29, 30, 31, 0, 0]]] |
---|
248 | n/a | ] |
---|
249 | n/a | |
---|
250 | n/a | result_2004_dates = \ |
---|
251 | n/a | [[['12/29/03 12/30/03 12/31/03 01/01/04 01/02/04 01/03/04 01/04/04', |
---|
252 | n/a | '01/05/04 01/06/04 01/07/04 01/08/04 01/09/04 01/10/04 01/11/04', |
---|
253 | n/a | '01/12/04 01/13/04 01/14/04 01/15/04 01/16/04 01/17/04 01/18/04', |
---|
254 | n/a | '01/19/04 01/20/04 01/21/04 01/22/04 01/23/04 01/24/04 01/25/04', |
---|
255 | n/a | '01/26/04 01/27/04 01/28/04 01/29/04 01/30/04 01/31/04 02/01/04'], |
---|
256 | n/a | ['01/26/04 01/27/04 01/28/04 01/29/04 01/30/04 01/31/04 02/01/04', |
---|
257 | n/a | '02/02/04 02/03/04 02/04/04 02/05/04 02/06/04 02/07/04 02/08/04', |
---|
258 | n/a | '02/09/04 02/10/04 02/11/04 02/12/04 02/13/04 02/14/04 02/15/04', |
---|
259 | n/a | '02/16/04 02/17/04 02/18/04 02/19/04 02/20/04 02/21/04 02/22/04', |
---|
260 | n/a | '02/23/04 02/24/04 02/25/04 02/26/04 02/27/04 02/28/04 02/29/04'], |
---|
261 | n/a | ['03/01/04 03/02/04 03/03/04 03/04/04 03/05/04 03/06/04 03/07/04', |
---|
262 | n/a | '03/08/04 03/09/04 03/10/04 03/11/04 03/12/04 03/13/04 03/14/04', |
---|
263 | n/a | '03/15/04 03/16/04 03/17/04 03/18/04 03/19/04 03/20/04 03/21/04', |
---|
264 | n/a | '03/22/04 03/23/04 03/24/04 03/25/04 03/26/04 03/27/04 03/28/04', |
---|
265 | n/a | '03/29/04 03/30/04 03/31/04 04/01/04 04/02/04 04/03/04 04/04/04']], |
---|
266 | n/a | [['03/29/04 03/30/04 03/31/04 04/01/04 04/02/04 04/03/04 04/04/04', |
---|
267 | n/a | '04/05/04 04/06/04 04/07/04 04/08/04 04/09/04 04/10/04 04/11/04', |
---|
268 | n/a | '04/12/04 04/13/04 04/14/04 04/15/04 04/16/04 04/17/04 04/18/04', |
---|
269 | n/a | '04/19/04 04/20/04 04/21/04 04/22/04 04/23/04 04/24/04 04/25/04', |
---|
270 | n/a | '04/26/04 04/27/04 04/28/04 04/29/04 04/30/04 05/01/04 05/02/04'], |
---|
271 | n/a | ['04/26/04 04/27/04 04/28/04 04/29/04 04/30/04 05/01/04 05/02/04', |
---|
272 | n/a | '05/03/04 05/04/04 05/05/04 05/06/04 05/07/04 05/08/04 05/09/04', |
---|
273 | n/a | '05/10/04 05/11/04 05/12/04 05/13/04 05/14/04 05/15/04 05/16/04', |
---|
274 | n/a | '05/17/04 05/18/04 05/19/04 05/20/04 05/21/04 05/22/04 05/23/04', |
---|
275 | n/a | '05/24/04 05/25/04 05/26/04 05/27/04 05/28/04 05/29/04 05/30/04', |
---|
276 | n/a | '05/31/04 06/01/04 06/02/04 06/03/04 06/04/04 06/05/04 06/06/04'], |
---|
277 | n/a | ['05/31/04 06/01/04 06/02/04 06/03/04 06/04/04 06/05/04 06/06/04', |
---|
278 | n/a | '06/07/04 06/08/04 06/09/04 06/10/04 06/11/04 06/12/04 06/13/04', |
---|
279 | n/a | '06/14/04 06/15/04 06/16/04 06/17/04 06/18/04 06/19/04 06/20/04', |
---|
280 | n/a | '06/21/04 06/22/04 06/23/04 06/24/04 06/25/04 06/26/04 06/27/04', |
---|
281 | n/a | '06/28/04 06/29/04 06/30/04 07/01/04 07/02/04 07/03/04 07/04/04']], |
---|
282 | n/a | [['06/28/04 06/29/04 06/30/04 07/01/04 07/02/04 07/03/04 07/04/04', |
---|
283 | n/a | '07/05/04 07/06/04 07/07/04 07/08/04 07/09/04 07/10/04 07/11/04', |
---|
284 | n/a | '07/12/04 07/13/04 07/14/04 07/15/04 07/16/04 07/17/04 07/18/04', |
---|
285 | n/a | '07/19/04 07/20/04 07/21/04 07/22/04 07/23/04 07/24/04 07/25/04', |
---|
286 | n/a | '07/26/04 07/27/04 07/28/04 07/29/04 07/30/04 07/31/04 08/01/04'], |
---|
287 | n/a | ['07/26/04 07/27/04 07/28/04 07/29/04 07/30/04 07/31/04 08/01/04', |
---|
288 | n/a | '08/02/04 08/03/04 08/04/04 08/05/04 08/06/04 08/07/04 08/08/04', |
---|
289 | n/a | '08/09/04 08/10/04 08/11/04 08/12/04 08/13/04 08/14/04 08/15/04', |
---|
290 | n/a | '08/16/04 08/17/04 08/18/04 08/19/04 08/20/04 08/21/04 08/22/04', |
---|
291 | n/a | '08/23/04 08/24/04 08/25/04 08/26/04 08/27/04 08/28/04 08/29/04', |
---|
292 | n/a | '08/30/04 08/31/04 09/01/04 09/02/04 09/03/04 09/04/04 09/05/04'], |
---|
293 | n/a | ['08/30/04 08/31/04 09/01/04 09/02/04 09/03/04 09/04/04 09/05/04', |
---|
294 | n/a | '09/06/04 09/07/04 09/08/04 09/09/04 09/10/04 09/11/04 09/12/04', |
---|
295 | n/a | '09/13/04 09/14/04 09/15/04 09/16/04 09/17/04 09/18/04 09/19/04', |
---|
296 | n/a | '09/20/04 09/21/04 09/22/04 09/23/04 09/24/04 09/25/04 09/26/04', |
---|
297 | n/a | '09/27/04 09/28/04 09/29/04 09/30/04 10/01/04 10/02/04 10/03/04']], |
---|
298 | n/a | [['09/27/04 09/28/04 09/29/04 09/30/04 10/01/04 10/02/04 10/03/04', |
---|
299 | n/a | '10/04/04 10/05/04 10/06/04 10/07/04 10/08/04 10/09/04 10/10/04', |
---|
300 | n/a | '10/11/04 10/12/04 10/13/04 10/14/04 10/15/04 10/16/04 10/17/04', |
---|
301 | n/a | '10/18/04 10/19/04 10/20/04 10/21/04 10/22/04 10/23/04 10/24/04', |
---|
302 | n/a | '10/25/04 10/26/04 10/27/04 10/28/04 10/29/04 10/30/04 10/31/04'], |
---|
303 | n/a | ['11/01/04 11/02/04 11/03/04 11/04/04 11/05/04 11/06/04 11/07/04', |
---|
304 | n/a | '11/08/04 11/09/04 11/10/04 11/11/04 11/12/04 11/13/04 11/14/04', |
---|
305 | n/a | '11/15/04 11/16/04 11/17/04 11/18/04 11/19/04 11/20/04 11/21/04', |
---|
306 | n/a | '11/22/04 11/23/04 11/24/04 11/25/04 11/26/04 11/27/04 11/28/04', |
---|
307 | n/a | '11/29/04 11/30/04 12/01/04 12/02/04 12/03/04 12/04/04 12/05/04'], |
---|
308 | n/a | ['11/29/04 11/30/04 12/01/04 12/02/04 12/03/04 12/04/04 12/05/04', |
---|
309 | n/a | '12/06/04 12/07/04 12/08/04 12/09/04 12/10/04 12/11/04 12/12/04', |
---|
310 | n/a | '12/13/04 12/14/04 12/15/04 12/16/04 12/17/04 12/18/04 12/19/04', |
---|
311 | n/a | '12/20/04 12/21/04 12/22/04 12/23/04 12/24/04 12/25/04 12/26/04', |
---|
312 | n/a | '12/27/04 12/28/04 12/29/04 12/30/04 12/31/04 01/01/05 01/02/05']]] |
---|
313 | n/a | |
---|
314 | n/a | |
---|
315 | n/a | class OutputTestCase(unittest.TestCase): |
---|
316 | n/a | def normalize_calendar(self, s): |
---|
317 | n/a | # Filters out locale dependent strings |
---|
318 | n/a | def neitherspacenordigit(c): |
---|
319 | n/a | return not c.isspace() and not c.isdigit() |
---|
320 | n/a | |
---|
321 | n/a | lines = [] |
---|
322 | n/a | for line in s.splitlines(keepends=False): |
---|
323 | n/a | # Drop texts, as they are locale dependent |
---|
324 | n/a | if line and not filter(neitherspacenordigit, line): |
---|
325 | n/a | lines.append(line) |
---|
326 | n/a | return lines |
---|
327 | n/a | |
---|
328 | n/a | def check_htmlcalendar_encoding(self, req, res): |
---|
329 | n/a | cal = calendar.HTMLCalendar() |
---|
330 | n/a | self.assertEqual( |
---|
331 | n/a | cal.formatyearpage(2004, encoding=req), |
---|
332 | n/a | (result_2004_html % {'e': res}).encode(res) |
---|
333 | n/a | ) |
---|
334 | n/a | |
---|
335 | n/a | def test_output(self): |
---|
336 | n/a | self.assertEqual( |
---|
337 | n/a | self.normalize_calendar(calendar.calendar(2004)), |
---|
338 | n/a | self.normalize_calendar(result_2004_text) |
---|
339 | n/a | ) |
---|
340 | n/a | |
---|
341 | n/a | def test_output_textcalendar(self): |
---|
342 | n/a | self.assertEqual( |
---|
343 | n/a | calendar.TextCalendar().formatyear(2004), |
---|
344 | n/a | result_2004_text |
---|
345 | n/a | ) |
---|
346 | n/a | |
---|
347 | n/a | def test_output_htmlcalendar_encoding_ascii(self): |
---|
348 | n/a | self.check_htmlcalendar_encoding('ascii', 'ascii') |
---|
349 | n/a | |
---|
350 | n/a | def test_output_htmlcalendar_encoding_utf8(self): |
---|
351 | n/a | self.check_htmlcalendar_encoding('utf-8', 'utf-8') |
---|
352 | n/a | |
---|
353 | n/a | def test_output_htmlcalendar_encoding_default(self): |
---|
354 | n/a | self.check_htmlcalendar_encoding(None, sys.getdefaultencoding()) |
---|
355 | n/a | |
---|
356 | n/a | def test_yeardatescalendar(self): |
---|
357 | n/a | def shrink(cal): |
---|
358 | n/a | return [[[' '.join('{:02d}/{:02d}/{}'.format( |
---|
359 | n/a | d.month, d.day, str(d.year)[-2:]) for d in z) |
---|
360 | n/a | for z in y] for y in x] for x in cal] |
---|
361 | n/a | self.assertEqual( |
---|
362 | n/a | shrink(calendar.Calendar().yeardatescalendar(2004)), |
---|
363 | n/a | result_2004_dates |
---|
364 | n/a | ) |
---|
365 | n/a | |
---|
366 | n/a | def test_yeardayscalendar(self): |
---|
367 | n/a | self.assertEqual( |
---|
368 | n/a | calendar.Calendar().yeardayscalendar(2004), |
---|
369 | n/a | result_2004_days |
---|
370 | n/a | ) |
---|
371 | n/a | |
---|
372 | n/a | def test_formatweekheader_short(self): |
---|
373 | n/a | self.assertEqual( |
---|
374 | n/a | calendar.TextCalendar().formatweekheader(2), |
---|
375 | n/a | 'Mo Tu We Th Fr Sa Su' |
---|
376 | n/a | ) |
---|
377 | n/a | |
---|
378 | n/a | def test_formatweekheader_long(self): |
---|
379 | n/a | self.assertEqual( |
---|
380 | n/a | calendar.TextCalendar().formatweekheader(9), |
---|
381 | n/a | ' Monday Tuesday Wednesday Thursday ' |
---|
382 | n/a | ' Friday Saturday Sunday ' |
---|
383 | n/a | ) |
---|
384 | n/a | |
---|
385 | n/a | def test_formatmonth(self): |
---|
386 | n/a | self.assertEqual( |
---|
387 | n/a | calendar.TextCalendar().formatmonth(2004, 1), |
---|
388 | n/a | result_2004_01_text |
---|
389 | n/a | ) |
---|
390 | n/a | |
---|
391 | n/a | def test_formatmonthname_with_year(self): |
---|
392 | n/a | self.assertEqual( |
---|
393 | n/a | calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=True), |
---|
394 | n/a | '<tr><th colspan="7" class="month">January 2004</th></tr>' |
---|
395 | n/a | ) |
---|
396 | n/a | |
---|
397 | n/a | def test_formatmonthname_without_year(self): |
---|
398 | n/a | self.assertEqual( |
---|
399 | n/a | calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=False), |
---|
400 | n/a | '<tr><th colspan="7" class="month">January</th></tr>' |
---|
401 | n/a | ) |
---|
402 | n/a | |
---|
403 | n/a | def test_prweek(self): |
---|
404 | n/a | with support.captured_stdout() as out: |
---|
405 | n/a | week = [(1,0), (2,1), (3,2), (4,3), (5,4), (6,5), (7,6)] |
---|
406 | n/a | calendar.TextCalendar().prweek(week, 1) |
---|
407 | n/a | self.assertEqual(out.getvalue(), " 1 2 3 4 5 6 7") |
---|
408 | n/a | |
---|
409 | n/a | def test_prmonth(self): |
---|
410 | n/a | with support.captured_stdout() as out: |
---|
411 | n/a | calendar.TextCalendar().prmonth(2004, 1) |
---|
412 | n/a | self.assertEqual(out.getvalue(), result_2004_01_text) |
---|
413 | n/a | |
---|
414 | n/a | def test_pryear(self): |
---|
415 | n/a | with support.captured_stdout() as out: |
---|
416 | n/a | calendar.TextCalendar().pryear(2004) |
---|
417 | n/a | self.assertEqual(out.getvalue(), result_2004_text) |
---|
418 | n/a | |
---|
419 | n/a | def test_format(self): |
---|
420 | n/a | with support.captured_stdout() as out: |
---|
421 | n/a | calendar.format(["1", "2", "3"], colwidth=3, spacing=1) |
---|
422 | n/a | self.assertEqual(out.getvalue().strip(), "1 2 3") |
---|
423 | n/a | |
---|
424 | n/a | class CalendarTestCase(unittest.TestCase): |
---|
425 | n/a | def test_isleap(self): |
---|
426 | n/a | # Make sure that the return is right for a few years, and |
---|
427 | n/a | # ensure that the return values are 1 or 0, not just true or |
---|
428 | n/a | # false (see SF bug #485794). Specific additional tests may |
---|
429 | n/a | # be appropriate; this tests a single "cycle". |
---|
430 | n/a | self.assertEqual(calendar.isleap(2000), 1) |
---|
431 | n/a | self.assertEqual(calendar.isleap(2001), 0) |
---|
432 | n/a | self.assertEqual(calendar.isleap(2002), 0) |
---|
433 | n/a | self.assertEqual(calendar.isleap(2003), 0) |
---|
434 | n/a | |
---|
435 | n/a | def test_setfirstweekday(self): |
---|
436 | n/a | self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber') |
---|
437 | n/a | self.assertRaises(ValueError, calendar.setfirstweekday, -1) |
---|
438 | n/a | self.assertRaises(ValueError, calendar.setfirstweekday, 200) |
---|
439 | n/a | orig = calendar.firstweekday() |
---|
440 | n/a | calendar.setfirstweekday(calendar.SUNDAY) |
---|
441 | n/a | self.assertEqual(calendar.firstweekday(), calendar.SUNDAY) |
---|
442 | n/a | calendar.setfirstweekday(calendar.MONDAY) |
---|
443 | n/a | self.assertEqual(calendar.firstweekday(), calendar.MONDAY) |
---|
444 | n/a | calendar.setfirstweekday(orig) |
---|
445 | n/a | |
---|
446 | n/a | def test_illegal_weekday_reported(self): |
---|
447 | n/a | with self.assertRaisesRegex(calendar.IllegalWeekdayError, '123'): |
---|
448 | n/a | calendar.setfirstweekday(123) |
---|
449 | n/a | |
---|
450 | n/a | def test_enumerate_weekdays(self): |
---|
451 | n/a | self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10) |
---|
452 | n/a | self.assertRaises(IndexError, calendar.day_name.__getitem__, 10) |
---|
453 | n/a | self.assertEqual(len([d for d in calendar.day_abbr]), 7) |
---|
454 | n/a | |
---|
455 | n/a | def test_days(self): |
---|
456 | n/a | for attr in "day_name", "day_abbr": |
---|
457 | n/a | value = getattr(calendar, attr) |
---|
458 | n/a | self.assertEqual(len(value), 7) |
---|
459 | n/a | self.assertEqual(len(value[:]), 7) |
---|
460 | n/a | # ensure they're all unique |
---|
461 | n/a | self.assertEqual(len(set(value)), 7) |
---|
462 | n/a | # verify it "acts like a sequence" in two forms of iteration |
---|
463 | n/a | self.assertEqual(value[::-1], list(reversed(value))) |
---|
464 | n/a | |
---|
465 | n/a | def test_months(self): |
---|
466 | n/a | for attr in "month_name", "month_abbr": |
---|
467 | n/a | value = getattr(calendar, attr) |
---|
468 | n/a | self.assertEqual(len(value), 13) |
---|
469 | n/a | self.assertEqual(len(value[:]), 13) |
---|
470 | n/a | self.assertEqual(value[0], "") |
---|
471 | n/a | # ensure they're all unique |
---|
472 | n/a | self.assertEqual(len(set(value)), 13) |
---|
473 | n/a | # verify it "acts like a sequence" in two forms of iteration |
---|
474 | n/a | self.assertEqual(value[::-1], list(reversed(value))) |
---|
475 | n/a | |
---|
476 | n/a | def test_locale_calendars(self): |
---|
477 | n/a | # ensure that Locale{Text,HTML}Calendar resets the locale properly |
---|
478 | n/a | # (it is still not thread-safe though) |
---|
479 | n/a | old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) |
---|
480 | n/a | try: |
---|
481 | n/a | cal = calendar.LocaleTextCalendar(locale='') |
---|
482 | n/a | local_weekday = cal.formatweekday(1, 10) |
---|
483 | n/a | local_month = cal.formatmonthname(2010, 10, 10) |
---|
484 | n/a | except locale.Error: |
---|
485 | n/a | # cannot set the system default locale -- skip rest of test |
---|
486 | n/a | raise unittest.SkipTest('cannot set the system default locale') |
---|
487 | n/a | self.assertIsInstance(local_weekday, str) |
---|
488 | n/a | self.assertIsInstance(local_month, str) |
---|
489 | n/a | self.assertEqual(len(local_weekday), 10) |
---|
490 | n/a | self.assertGreaterEqual(len(local_month), 10) |
---|
491 | n/a | cal = calendar.LocaleHTMLCalendar(locale='') |
---|
492 | n/a | local_weekday = cal.formatweekday(1) |
---|
493 | n/a | local_month = cal.formatmonthname(2010, 10) |
---|
494 | n/a | self.assertIsInstance(local_weekday, str) |
---|
495 | n/a | self.assertIsInstance(local_month, str) |
---|
496 | n/a | new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) |
---|
497 | n/a | self.assertEqual(old_october, new_october) |
---|
498 | n/a | |
---|
499 | n/a | def test_itermonthdates(self): |
---|
500 | n/a | # ensure itermonthdates doesn't overflow after datetime.MAXYEAR |
---|
501 | n/a | # see #15421 |
---|
502 | n/a | list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) |
---|
503 | n/a | |
---|
504 | n/a | def test_itermonthdays(self): |
---|
505 | n/a | for firstweekday in range(7): |
---|
506 | n/a | cal = calendar.Calendar(firstweekday) |
---|
507 | n/a | # Test the extremes, see #28253 and #26650 |
---|
508 | n/a | for y, m in [(1, 1), (9999, 12)]: |
---|
509 | n/a | days = list(cal.itermonthdays(y, m)) |
---|
510 | n/a | self.assertIn(len(days), (35, 42)) |
---|
511 | n/a | # Test a short month |
---|
512 | n/a | cal = calendar.Calendar(firstweekday=3) |
---|
513 | n/a | days = list(cal.itermonthdays(2001, 2)) |
---|
514 | n/a | self.assertEqual(days, list(range(1, 29))) |
---|
515 | n/a | |
---|
516 | n/a | def test_itermonthdays2(self): |
---|
517 | n/a | for firstweekday in range(7): |
---|
518 | n/a | cal = calendar.Calendar(firstweekday) |
---|
519 | n/a | # Test the extremes, see #28253 and #26650 |
---|
520 | n/a | for y, m in [(1, 1), (9999, 12)]: |
---|
521 | n/a | days = list(cal.itermonthdays2(y, m)) |
---|
522 | n/a | self.assertEqual(days[0][1], firstweekday) |
---|
523 | n/a | self.assertEqual(days[-1][1], (firstweekday - 1) % 7) |
---|
524 | n/a | |
---|
525 | n/a | |
---|
526 | n/a | class MonthCalendarTestCase(unittest.TestCase): |
---|
527 | n/a | def setUp(self): |
---|
528 | n/a | self.oldfirstweekday = calendar.firstweekday() |
---|
529 | n/a | calendar.setfirstweekday(self.firstweekday) |
---|
530 | n/a | |
---|
531 | n/a | def tearDown(self): |
---|
532 | n/a | calendar.setfirstweekday(self.oldfirstweekday) |
---|
533 | n/a | |
---|
534 | n/a | def check_weeks(self, year, month, weeks): |
---|
535 | n/a | cal = calendar.monthcalendar(year, month) |
---|
536 | n/a | self.assertEqual(len(cal), len(weeks)) |
---|
537 | n/a | for i in range(len(weeks)): |
---|
538 | n/a | self.assertEqual(weeks[i], sum(day != 0 for day in cal[i])) |
---|
539 | n/a | |
---|
540 | n/a | |
---|
541 | n/a | class MondayTestCase(MonthCalendarTestCase): |
---|
542 | n/a | firstweekday = calendar.MONDAY |
---|
543 | n/a | |
---|
544 | n/a | def test_february(self): |
---|
545 | n/a | # A 28-day february starting on monday (7+7+7+7 days) |
---|
546 | n/a | self.check_weeks(1999, 2, (7, 7, 7, 7)) |
---|
547 | n/a | |
---|
548 | n/a | # A 28-day february starting on tuesday (6+7+7+7+1 days) |
---|
549 | n/a | self.check_weeks(2005, 2, (6, 7, 7, 7, 1)) |
---|
550 | n/a | |
---|
551 | n/a | # A 28-day february starting on sunday (1+7+7+7+6 days) |
---|
552 | n/a | self.check_weeks(1987, 2, (1, 7, 7, 7, 6)) |
---|
553 | n/a | |
---|
554 | n/a | # A 29-day february starting on monday (7+7+7+7+1 days) |
---|
555 | n/a | self.check_weeks(1988, 2, (7, 7, 7, 7, 1)) |
---|
556 | n/a | |
---|
557 | n/a | # A 29-day february starting on tuesday (6+7+7+7+2 days) |
---|
558 | n/a | self.check_weeks(1972, 2, (6, 7, 7, 7, 2)) |
---|
559 | n/a | |
---|
560 | n/a | # A 29-day february starting on sunday (1+7+7+7+7 days) |
---|
561 | n/a | self.check_weeks(2004, 2, (1, 7, 7, 7, 7)) |
---|
562 | n/a | |
---|
563 | n/a | def test_april(self): |
---|
564 | n/a | # A 30-day april starting on monday (7+7+7+7+2 days) |
---|
565 | n/a | self.check_weeks(1935, 4, (7, 7, 7, 7, 2)) |
---|
566 | n/a | |
---|
567 | n/a | # A 30-day april starting on tuesday (6+7+7+7+3 days) |
---|
568 | n/a | self.check_weeks(1975, 4, (6, 7, 7, 7, 3)) |
---|
569 | n/a | |
---|
570 | n/a | # A 30-day april starting on sunday (1+7+7+7+7+1 days) |
---|
571 | n/a | self.check_weeks(1945, 4, (1, 7, 7, 7, 7, 1)) |
---|
572 | n/a | |
---|
573 | n/a | # A 30-day april starting on saturday (2+7+7+7+7 days) |
---|
574 | n/a | self.check_weeks(1995, 4, (2, 7, 7, 7, 7)) |
---|
575 | n/a | |
---|
576 | n/a | # A 30-day april starting on friday (3+7+7+7+6 days) |
---|
577 | n/a | self.check_weeks(1994, 4, (3, 7, 7, 7, 6)) |
---|
578 | n/a | |
---|
579 | n/a | def test_december(self): |
---|
580 | n/a | # A 31-day december starting on monday (7+7+7+7+3 days) |
---|
581 | n/a | self.check_weeks(1980, 12, (7, 7, 7, 7, 3)) |
---|
582 | n/a | |
---|
583 | n/a | # A 31-day december starting on tuesday (6+7+7+7+4 days) |
---|
584 | n/a | self.check_weeks(1987, 12, (6, 7, 7, 7, 4)) |
---|
585 | n/a | |
---|
586 | n/a | # A 31-day december starting on sunday (1+7+7+7+7+2 days) |
---|
587 | n/a | self.check_weeks(1968, 12, (1, 7, 7, 7, 7, 2)) |
---|
588 | n/a | |
---|
589 | n/a | # A 31-day december starting on thursday (4+7+7+7+6 days) |
---|
590 | n/a | self.check_weeks(1988, 12, (4, 7, 7, 7, 6)) |
---|
591 | n/a | |
---|
592 | n/a | # A 31-day december starting on friday (3+7+7+7+7 days) |
---|
593 | n/a | self.check_weeks(2017, 12, (3, 7, 7, 7, 7)) |
---|
594 | n/a | |
---|
595 | n/a | # A 31-day december starting on saturday (2+7+7+7+7+1 days) |
---|
596 | n/a | self.check_weeks(2068, 12, (2, 7, 7, 7, 7, 1)) |
---|
597 | n/a | |
---|
598 | n/a | |
---|
599 | n/a | class SundayTestCase(MonthCalendarTestCase): |
---|
600 | n/a | firstweekday = calendar.SUNDAY |
---|
601 | n/a | |
---|
602 | n/a | def test_february(self): |
---|
603 | n/a | # A 28-day february starting on sunday (7+7+7+7 days) |
---|
604 | n/a | self.check_weeks(2009, 2, (7, 7, 7, 7)) |
---|
605 | n/a | |
---|
606 | n/a | # A 28-day february starting on monday (6+7+7+7+1 days) |
---|
607 | n/a | self.check_weeks(1999, 2, (6, 7, 7, 7, 1)) |
---|
608 | n/a | |
---|
609 | n/a | # A 28-day february starting on saturday (1+7+7+7+6 days) |
---|
610 | n/a | self.check_weeks(1997, 2, (1, 7, 7, 7, 6)) |
---|
611 | n/a | |
---|
612 | n/a | # A 29-day february starting on sunday (7+7+7+7+1 days) |
---|
613 | n/a | self.check_weeks(2004, 2, (7, 7, 7, 7, 1)) |
---|
614 | n/a | |
---|
615 | n/a | # A 29-day february starting on monday (6+7+7+7+2 days) |
---|
616 | n/a | self.check_weeks(1960, 2, (6, 7, 7, 7, 2)) |
---|
617 | n/a | |
---|
618 | n/a | # A 29-day february starting on saturday (1+7+7+7+7 days) |
---|
619 | n/a | self.check_weeks(1964, 2, (1, 7, 7, 7, 7)) |
---|
620 | n/a | |
---|
621 | n/a | def test_april(self): |
---|
622 | n/a | # A 30-day april starting on sunday (7+7+7+7+2 days) |
---|
623 | n/a | self.check_weeks(1923, 4, (7, 7, 7, 7, 2)) |
---|
624 | n/a | |
---|
625 | n/a | # A 30-day april starting on monday (6+7+7+7+3 days) |
---|
626 | n/a | self.check_weeks(1918, 4, (6, 7, 7, 7, 3)) |
---|
627 | n/a | |
---|
628 | n/a | # A 30-day april starting on saturday (1+7+7+7+7+1 days) |
---|
629 | n/a | self.check_weeks(1950, 4, (1, 7, 7, 7, 7, 1)) |
---|
630 | n/a | |
---|
631 | n/a | # A 30-day april starting on friday (2+7+7+7+7 days) |
---|
632 | n/a | self.check_weeks(1960, 4, (2, 7, 7, 7, 7)) |
---|
633 | n/a | |
---|
634 | n/a | # A 30-day april starting on thursday (3+7+7+7+6 days) |
---|
635 | n/a | self.check_weeks(1909, 4, (3, 7, 7, 7, 6)) |
---|
636 | n/a | |
---|
637 | n/a | def test_december(self): |
---|
638 | n/a | # A 31-day december starting on sunday (7+7+7+7+3 days) |
---|
639 | n/a | self.check_weeks(2080, 12, (7, 7, 7, 7, 3)) |
---|
640 | n/a | |
---|
641 | n/a | # A 31-day december starting on monday (6+7+7+7+4 days) |
---|
642 | n/a | self.check_weeks(1941, 12, (6, 7, 7, 7, 4)) |
---|
643 | n/a | |
---|
644 | n/a | # A 31-day december starting on saturday (1+7+7+7+7+2 days) |
---|
645 | n/a | self.check_weeks(1923, 12, (1, 7, 7, 7, 7, 2)) |
---|
646 | n/a | |
---|
647 | n/a | # A 31-day december starting on wednesday (4+7+7+7+6 days) |
---|
648 | n/a | self.check_weeks(1948, 12, (4, 7, 7, 7, 6)) |
---|
649 | n/a | |
---|
650 | n/a | # A 31-day december starting on thursday (3+7+7+7+7 days) |
---|
651 | n/a | self.check_weeks(1927, 12, (3, 7, 7, 7, 7)) |
---|
652 | n/a | |
---|
653 | n/a | # A 31-day december starting on friday (2+7+7+7+7+1 days) |
---|
654 | n/a | self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1)) |
---|
655 | n/a | |
---|
656 | n/a | class TimegmTestCase(unittest.TestCase): |
---|
657 | n/a | TIMESTAMPS = [0, 10, 100, 1000, 10000, 100000, 1000000, |
---|
658 | n/a | 1234567890, 1262304000, 1275785153,] |
---|
659 | n/a | def test_timegm(self): |
---|
660 | n/a | for secs in self.TIMESTAMPS: |
---|
661 | n/a | tuple = time.gmtime(secs) |
---|
662 | n/a | self.assertEqual(secs, calendar.timegm(tuple)) |
---|
663 | n/a | |
---|
664 | n/a | class MonthRangeTestCase(unittest.TestCase): |
---|
665 | n/a | def test_january(self): |
---|
666 | n/a | # Tests valid lower boundary case. |
---|
667 | n/a | self.assertEqual(calendar.monthrange(2004,1), (3,31)) |
---|
668 | n/a | |
---|
669 | n/a | def test_february_leap(self): |
---|
670 | n/a | # Tests February during leap year. |
---|
671 | n/a | self.assertEqual(calendar.monthrange(2004,2), (6,29)) |
---|
672 | n/a | |
---|
673 | n/a | def test_february_nonleap(self): |
---|
674 | n/a | # Tests February in non-leap year. |
---|
675 | n/a | self.assertEqual(calendar.monthrange(2010,2), (0,28)) |
---|
676 | n/a | |
---|
677 | n/a | def test_december(self): |
---|
678 | n/a | # Tests valid upper boundary case. |
---|
679 | n/a | self.assertEqual(calendar.monthrange(2004,12), (2,31)) |
---|
680 | n/a | |
---|
681 | n/a | def test_zeroth_month(self): |
---|
682 | n/a | # Tests low invalid boundary case. |
---|
683 | n/a | with self.assertRaises(calendar.IllegalMonthError): |
---|
684 | n/a | calendar.monthrange(2004, 0) |
---|
685 | n/a | |
---|
686 | n/a | def test_thirteenth_month(self): |
---|
687 | n/a | # Tests high invalid boundary case. |
---|
688 | n/a | with self.assertRaises(calendar.IllegalMonthError): |
---|
689 | n/a | calendar.monthrange(2004, 13) |
---|
690 | n/a | |
---|
691 | n/a | def test_illegal_month_reported(self): |
---|
692 | n/a | with self.assertRaisesRegex(calendar.IllegalMonthError, '65'): |
---|
693 | n/a | calendar.monthrange(2004, 65) |
---|
694 | n/a | |
---|
695 | n/a | class LeapdaysTestCase(unittest.TestCase): |
---|
696 | n/a | def test_no_range(self): |
---|
697 | n/a | # test when no range i.e. two identical years as args |
---|
698 | n/a | self.assertEqual(calendar.leapdays(2010,2010), 0) |
---|
699 | n/a | |
---|
700 | n/a | def test_no_leapdays(self): |
---|
701 | n/a | # test when no leap years in range |
---|
702 | n/a | self.assertEqual(calendar.leapdays(2010,2011), 0) |
---|
703 | n/a | |
---|
704 | n/a | def test_no_leapdays_upper_boundary(self): |
---|
705 | n/a | # test no leap years in range, when upper boundary is a leap year |
---|
706 | n/a | self.assertEqual(calendar.leapdays(2010,2012), 0) |
---|
707 | n/a | |
---|
708 | n/a | def test_one_leapday_lower_boundary(self): |
---|
709 | n/a | # test when one leap year in range, lower boundary is leap year |
---|
710 | n/a | self.assertEqual(calendar.leapdays(2012,2013), 1) |
---|
711 | n/a | |
---|
712 | n/a | def test_several_leapyears_in_range(self): |
---|
713 | n/a | self.assertEqual(calendar.leapdays(1997,2020), 5) |
---|
714 | n/a | |
---|
715 | n/a | |
---|
716 | n/a | def conv(s): |
---|
717 | n/a | return s.replace('\n', os.linesep).encode() |
---|
718 | n/a | |
---|
719 | n/a | class CommandLineTestCase(unittest.TestCase): |
---|
720 | n/a | def run_ok(self, *args): |
---|
721 | n/a | return assert_python_ok('-m', 'calendar', *args)[1] |
---|
722 | n/a | |
---|
723 | n/a | def assertFailure(self, *args): |
---|
724 | n/a | rc, stdout, stderr = assert_python_failure('-m', 'calendar', *args) |
---|
725 | n/a | self.assertIn(b'usage:', stderr) |
---|
726 | n/a | self.assertEqual(rc, 2) |
---|
727 | n/a | |
---|
728 | n/a | def test_help(self): |
---|
729 | n/a | stdout = self.run_ok('-h') |
---|
730 | n/a | self.assertIn(b'usage:', stdout) |
---|
731 | n/a | self.assertIn(b'calendar.py', stdout) |
---|
732 | n/a | self.assertIn(b'--help', stdout) |
---|
733 | n/a | |
---|
734 | n/a | def test_illegal_arguments(self): |
---|
735 | n/a | self.assertFailure('-z') |
---|
736 | n/a | self.assertFailure('spam') |
---|
737 | n/a | self.assertFailure('2004', 'spam') |
---|
738 | n/a | self.assertFailure('-t', 'html', '2004', '1') |
---|
739 | n/a | |
---|
740 | n/a | def test_output_current_year(self): |
---|
741 | n/a | stdout = self.run_ok() |
---|
742 | n/a | year = datetime.datetime.now().year |
---|
743 | n/a | self.assertIn((' %s' % year).encode(), stdout) |
---|
744 | n/a | self.assertIn(b'January', stdout) |
---|
745 | n/a | self.assertIn(b'Mo Tu We Th Fr Sa Su', stdout) |
---|
746 | n/a | |
---|
747 | n/a | def test_output_year(self): |
---|
748 | n/a | stdout = self.run_ok('2004') |
---|
749 | n/a | self.assertEqual(stdout, conv(result_2004_text)) |
---|
750 | n/a | |
---|
751 | n/a | def test_output_month(self): |
---|
752 | n/a | stdout = self.run_ok('2004', '1') |
---|
753 | n/a | self.assertEqual(stdout, conv(result_2004_01_text)) |
---|
754 | n/a | |
---|
755 | n/a | def test_option_encoding(self): |
---|
756 | n/a | self.assertFailure('-e') |
---|
757 | n/a | self.assertFailure('--encoding') |
---|
758 | n/a | stdout = self.run_ok('--encoding', 'utf-16-le', '2004') |
---|
759 | n/a | self.assertEqual(stdout, result_2004_text.encode('utf-16-le')) |
---|
760 | n/a | |
---|
761 | n/a | def test_option_locale(self): |
---|
762 | n/a | self.assertFailure('-L') |
---|
763 | n/a | self.assertFailure('--locale') |
---|
764 | n/a | self.assertFailure('-L', 'en') |
---|
765 | n/a | lang, enc = locale.getdefaultlocale() |
---|
766 | n/a | lang = lang or 'C' |
---|
767 | n/a | enc = enc or 'UTF-8' |
---|
768 | n/a | try: |
---|
769 | n/a | oldlocale = locale.getlocale(locale.LC_TIME) |
---|
770 | n/a | try: |
---|
771 | n/a | locale.setlocale(locale.LC_TIME, (lang, enc)) |
---|
772 | n/a | finally: |
---|
773 | n/a | locale.setlocale(locale.LC_TIME, oldlocale) |
---|
774 | n/a | except (locale.Error, ValueError): |
---|
775 | n/a | self.skipTest('cannot set the system default locale') |
---|
776 | n/a | stdout = self.run_ok('--locale', lang, '--encoding', enc, '2004') |
---|
777 | n/a | self.assertIn('2004'.encode(enc), stdout) |
---|
778 | n/a | |
---|
779 | n/a | def test_option_width(self): |
---|
780 | n/a | self.assertFailure('-w') |
---|
781 | n/a | self.assertFailure('--width') |
---|
782 | n/a | self.assertFailure('-w', 'spam') |
---|
783 | n/a | stdout = self.run_ok('--width', '3', '2004') |
---|
784 | n/a | self.assertIn(b'Mon Tue Wed Thu Fri Sat Sun', stdout) |
---|
785 | n/a | |
---|
786 | n/a | def test_option_lines(self): |
---|
787 | n/a | self.assertFailure('-l') |
---|
788 | n/a | self.assertFailure('--lines') |
---|
789 | n/a | self.assertFailure('-l', 'spam') |
---|
790 | n/a | stdout = self.run_ok('--lines', '2', '2004') |
---|
791 | n/a | self.assertIn(conv('December\n\nMo Tu We'), stdout) |
---|
792 | n/a | |
---|
793 | n/a | def test_option_spacing(self): |
---|
794 | n/a | self.assertFailure('-s') |
---|
795 | n/a | self.assertFailure('--spacing') |
---|
796 | n/a | self.assertFailure('-s', 'spam') |
---|
797 | n/a | stdout = self.run_ok('--spacing', '8', '2004') |
---|
798 | n/a | self.assertIn(b'Su Mo', stdout) |
---|
799 | n/a | |
---|
800 | n/a | def test_option_months(self): |
---|
801 | n/a | self.assertFailure('-m') |
---|
802 | n/a | self.assertFailure('--month') |
---|
803 | n/a | self.assertFailure('-m', 'spam') |
---|
804 | n/a | stdout = self.run_ok('--months', '1', '2004') |
---|
805 | n/a | self.assertIn(conv('\nMo Tu We Th Fr Sa Su\n'), stdout) |
---|
806 | n/a | |
---|
807 | n/a | def test_option_type(self): |
---|
808 | n/a | self.assertFailure('-t') |
---|
809 | n/a | self.assertFailure('--type') |
---|
810 | n/a | self.assertFailure('-t', 'spam') |
---|
811 | n/a | stdout = self.run_ok('--type', 'text', '2004') |
---|
812 | n/a | self.assertEqual(stdout, conv(result_2004_text)) |
---|
813 | n/a | stdout = self.run_ok('--type', 'html', '2004') |
---|
814 | n/a | self.assertEqual(stdout[:6], b'<?xml ') |
---|
815 | n/a | self.assertIn(b'<title>Calendar for 2004</title>', stdout) |
---|
816 | n/a | |
---|
817 | n/a | def test_html_output_current_year(self): |
---|
818 | n/a | stdout = self.run_ok('--type', 'html') |
---|
819 | n/a | year = datetime.datetime.now().year |
---|
820 | n/a | self.assertIn(('<title>Calendar for %s</title>' % year).encode(), |
---|
821 | n/a | stdout) |
---|
822 | n/a | self.assertIn(b'<tr><th colspan="7" class="month">January</th></tr>', |
---|
823 | n/a | stdout) |
---|
824 | n/a | |
---|
825 | n/a | def test_html_output_year_encoding(self): |
---|
826 | n/a | stdout = self.run_ok('-t', 'html', '--encoding', 'ascii', '2004') |
---|
827 | n/a | self.assertEqual(stdout, |
---|
828 | n/a | (result_2004_html % {'e': 'ascii'}).encode('ascii')) |
---|
829 | n/a | |
---|
830 | n/a | def test_html_output_year_css(self): |
---|
831 | n/a | self.assertFailure('-t', 'html', '-c') |
---|
832 | n/a | self.assertFailure('-t', 'html', '--css') |
---|
833 | n/a | stdout = self.run_ok('-t', 'html', '--css', 'custom.css', '2004') |
---|
834 | n/a | self.assertIn(b'<link rel="stylesheet" type="text/css" ' |
---|
835 | n/a | b'href="custom.css" />', stdout) |
---|
836 | n/a | |
---|
837 | n/a | |
---|
838 | n/a | class MiscTestCase(unittest.TestCase): |
---|
839 | n/a | def test__all__(self): |
---|
840 | n/a | blacklist = {'mdays', 'January', 'February', 'EPOCH', |
---|
841 | n/a | 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', |
---|
842 | n/a | 'SATURDAY', 'SUNDAY', 'different_locale', 'c', |
---|
843 | n/a | 'prweek', 'week', 'format', 'formatstring', 'main'} |
---|
844 | n/a | support.check__all__(self, calendar, blacklist=blacklist) |
---|
845 | n/a | |
---|
846 | n/a | |
---|
847 | n/a | if __name__ == "__main__": |
---|
848 | n/a | unittest.main() |
---|