ยปCore Development>Code coverage>Lib/test/test_calendar.py

Python code coverage for Lib/test/test_calendar.py

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