Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 1 | import calendar |
| 2 | import unittest |
| 3 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 4 | from test import support |
Senthil Kumaran | 962fed9 | 2011-08-11 09:22:52 +0800 | [diff] [blame] | 5 | from test.script_helper import assert_python_ok |
Alexander Belopolsky | 43ca710 | 2010-06-14 17:32:03 +0000 | [diff] [blame] | 6 | import time |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 7 | import locale |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 8 | import sys |
Ezio Melotti | 85710a4 | 2012-09-21 17:26:35 +0300 | [diff] [blame] | 9 | import datetime |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 10 | |
| 11 | result_2004_01_text = """ |
| 12 | January 2004 |
| 13 | Mo Tu We Th Fr Sa Su |
| 14 | 1 2 3 4 |
| 15 | 5 6 7 8 9 10 11 |
| 16 | 12 13 14 15 16 17 18 |
| 17 | 19 20 21 22 23 24 25 |
| 18 | 26 27 28 29 30 31 |
| 19 | """ |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 20 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 21 | result_2004_text = """ |
| 22 | 2004 |
| 23 | |
| 24 | January February March |
| 25 | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
| 26 | 1 2 3 4 1 1 2 3 4 5 6 7 |
| 27 | 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14 |
| 28 | 12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21 |
| 29 | 19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28 |
| 30 | 26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31 |
| 31 | |
| 32 | April May June |
| 33 | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
| 34 | 1 2 3 4 1 2 1 2 3 4 5 6 |
| 35 | 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13 |
| 36 | 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20 |
| 37 | 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27 |
| 38 | 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 |
| 39 | 31 |
| 40 | |
| 41 | July August September |
| 42 | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
| 43 | 1 2 3 4 1 1 2 3 4 5 |
| 44 | 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12 |
| 45 | 12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19 |
| 46 | 19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26 |
| 47 | 26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 |
| 48 | 30 31 |
| 49 | |
| 50 | October November December |
| 51 | Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su |
| 52 | 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 |
| 53 | 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12 |
| 54 | 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19 |
| 55 | 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26 |
| 56 | 25 26 27 28 29 30 31 29 30 27 28 29 30 31 |
| 57 | """ |
| 58 | |
| 59 | result_2004_html = """ |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 60 | <?xml version="1.0" encoding="%(e)s"?> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 61 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 62 | <html> |
| 63 | <head> |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 64 | <meta http-equiv="Content-Type" content="text/html; charset=%(e)s" /> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 65 | <link rel="stylesheet" type="text/css" href="calendar.css" /> |
Thomas Wouters | 47b49bf | 2007-08-30 22:15:33 +0000 | [diff] [blame] | 66 | <title>Calendar for 2004</title> |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 67 | </head> |
| 68 | <body> |
| 69 | <table border="0" cellpadding="0" cellspacing="0" class="year"> |
| 70 | <tr><th colspan="3" class="year">2004</th></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 71 | <tr><th colspan="7" class="month">January</th></tr> |
| 72 | <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> |
| 73 | <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> |
| 74 | <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> |
| 75 | <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> |
| 76 | <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> |
| 77 | <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> |
| 78 | </table> |
| 79 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 80 | <tr><th colspan="7" class="month">February</th></tr> |
| 81 | <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> |
| 82 | <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> |
| 83 | <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> |
| 84 | <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> |
| 85 | <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> |
| 86 | <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> |
| 87 | </table> |
| 88 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 89 | <tr><th colspan="7" class="month">March</th></tr> |
| 90 | <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> |
| 91 | <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> |
| 92 | <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> |
| 93 | <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> |
| 94 | <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> |
| 95 | <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> |
| 96 | </table> |
| 97 | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 98 | <tr><th colspan="7" class="month">April</th></tr> |
| 99 | <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> |
| 100 | <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> |
| 101 | <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> |
| 102 | <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> |
| 103 | <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> |
| 104 | <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> |
| 105 | </table> |
| 106 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 107 | <tr><th colspan="7" class="month">May</th></tr> |
| 108 | <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> |
| 109 | <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> |
| 110 | <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> |
| 111 | <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> |
| 112 | <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> |
| 113 | <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> |
| 114 | <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> |
| 115 | </table> |
| 116 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 117 | <tr><th colspan="7" class="month">June</th></tr> |
| 118 | <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> |
| 119 | <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> |
| 120 | <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> |
| 121 | <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> |
| 122 | <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> |
| 123 | <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> |
| 124 | </table> |
| 125 | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 126 | <tr><th colspan="7" class="month">July</th></tr> |
| 127 | <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> |
| 128 | <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> |
| 129 | <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> |
| 130 | <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> |
| 131 | <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> |
| 132 | <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> |
| 133 | </table> |
| 134 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 135 | <tr><th colspan="7" class="month">August</th></tr> |
| 136 | <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> |
| 137 | <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> |
| 138 | <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> |
| 139 | <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> |
| 140 | <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> |
| 141 | <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> |
| 142 | <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> |
| 143 | </table> |
| 144 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 145 | <tr><th colspan="7" class="month">September</th></tr> |
| 146 | <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> |
| 147 | <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> |
| 148 | <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> |
| 149 | <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> |
| 150 | <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> |
| 151 | <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> |
| 152 | </table> |
| 153 | </td></tr><tr><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 154 | <tr><th colspan="7" class="month">October</th></tr> |
| 155 | <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> |
| 156 | <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> |
| 157 | <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> |
| 158 | <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> |
| 159 | <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> |
| 160 | <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> |
| 161 | </table> |
| 162 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 163 | <tr><th colspan="7" class="month">November</th></tr> |
| 164 | <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> |
| 165 | <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> |
| 166 | <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> |
| 167 | <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> |
| 168 | <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> |
| 169 | <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> |
| 170 | </table> |
| 171 | </td><td><table border="0" cellpadding="0" cellspacing="0" class="month"> |
| 172 | <tr><th colspan="7" class="month">December</th></tr> |
| 173 | <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> |
| 174 | <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> |
| 175 | <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> |
| 176 | <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> |
| 177 | <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> |
| 178 | <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> |
| 179 | </table> |
| 180 | </td></tr></table></body> |
| 181 | </html> |
| 182 | """ |
| 183 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 184 | result_2004_days = [ |
| 185 | [[[0, 0, 0, 1, 2, 3, 4], |
| 186 | [5, 6, 7, 8, 9, 10, 11], |
| 187 | [12, 13, 14, 15, 16, 17, 18], |
| 188 | [19, 20, 21, 22, 23, 24, 25], |
| 189 | [26, 27, 28, 29, 30, 31, 0]], |
| 190 | [[0, 0, 0, 0, 0, 0, 1], |
| 191 | [2, 3, 4, 5, 6, 7, 8], |
| 192 | [9, 10, 11, 12, 13, 14, 15], |
| 193 | [16, 17, 18, 19, 20, 21, 22], |
| 194 | [23, 24, 25, 26, 27, 28, 29]], |
| 195 | [[1, 2, 3, 4, 5, 6, 7], |
| 196 | [8, 9, 10, 11, 12, 13, 14], |
| 197 | [15, 16, 17, 18, 19, 20, 21], |
| 198 | [22, 23, 24, 25, 26, 27, 28], |
| 199 | [29, 30, 31, 0, 0, 0, 0]]], |
| 200 | [[[0, 0, 0, 1, 2, 3, 4], |
| 201 | [5, 6, 7, 8, 9, 10, 11], |
| 202 | [12, 13, 14, 15, 16, 17, 18], |
| 203 | [19, 20, 21, 22, 23, 24, 25], |
| 204 | [26, 27, 28, 29, 30, 0, 0]], |
| 205 | [[0, 0, 0, 0, 0, 1, 2], |
| 206 | [3, 4, 5, 6, 7, 8, 9], |
| 207 | [10, 11, 12, 13, 14, 15, 16], |
| 208 | [17, 18, 19, 20, 21, 22, 23], |
| 209 | [24, 25, 26, 27, 28, 29, 30], |
| 210 | [31, 0, 0, 0, 0, 0, 0]], |
| 211 | [[0, 1, 2, 3, 4, 5, 6], |
| 212 | [7, 8, 9, 10, 11, 12, 13], |
| 213 | [14, 15, 16, 17, 18, 19, 20], |
| 214 | [21, 22, 23, 24, 25, 26, 27], |
| 215 | [28, 29, 30, 0, 0, 0, 0]]], |
| 216 | [[[0, 0, 0, 1, 2, 3, 4], |
| 217 | [5, 6, 7, 8, 9, 10, 11], |
| 218 | [12, 13, 14, 15, 16, 17, 18], |
| 219 | [19, 20, 21, 22, 23, 24, 25], |
| 220 | [26, 27, 28, 29, 30, 31, 0]], |
| 221 | [[0, 0, 0, 0, 0, 0, 1], |
| 222 | [2, 3, 4, 5, 6, 7, 8], |
| 223 | [9, 10, 11, 12, 13, 14, 15], |
| 224 | [16, 17, 18, 19, 20, 21, 22], |
| 225 | [23, 24, 25, 26, 27, 28, 29], |
| 226 | [30, 31, 0, 0, 0, 0, 0]], |
| 227 | [[0, 0, 1, 2, 3, 4, 5], |
| 228 | [6, 7, 8, 9, 10, 11, 12], |
| 229 | [13, 14, 15, 16, 17, 18, 19], |
| 230 | [20, 21, 22, 23, 24, 25, 26], |
| 231 | [27, 28, 29, 30, 0, 0, 0]]], |
| 232 | [[[0, 0, 0, 0, 1, 2, 3], |
| 233 | [4, 5, 6, 7, 8, 9, 10], |
| 234 | [11, 12, 13, 14, 15, 16, 17], |
| 235 | [18, 19, 20, 21, 22, 23, 24], |
| 236 | [25, 26, 27, 28, 29, 30, 31]], |
| 237 | [[1, 2, 3, 4, 5, 6, 7], |
| 238 | [8, 9, 10, 11, 12, 13, 14], |
| 239 | [15, 16, 17, 18, 19, 20, 21], |
| 240 | [22, 23, 24, 25, 26, 27, 28], |
| 241 | [29, 30, 0, 0, 0, 0, 0]], |
| 242 | [[0, 0, 1, 2, 3, 4, 5], |
| 243 | [6, 7, 8, 9, 10, 11, 12], |
| 244 | [13, 14, 15, 16, 17, 18, 19], |
| 245 | [20, 21, 22, 23, 24, 25, 26], |
| 246 | [27, 28, 29, 30, 31, 0, 0]]] |
| 247 | ] |
| 248 | |
| 249 | result_2004_dates = \ |
| 250 | [[['12/29/03 12/30/03 12/31/03 01/01/04 01/02/04 01/03/04 01/04/04', |
| 251 | '01/05/04 01/06/04 01/07/04 01/08/04 01/09/04 01/10/04 01/11/04', |
| 252 | '01/12/04 01/13/04 01/14/04 01/15/04 01/16/04 01/17/04 01/18/04', |
| 253 | '01/19/04 01/20/04 01/21/04 01/22/04 01/23/04 01/24/04 01/25/04', |
| 254 | '01/26/04 01/27/04 01/28/04 01/29/04 01/30/04 01/31/04 02/01/04'], |
| 255 | ['01/26/04 01/27/04 01/28/04 01/29/04 01/30/04 01/31/04 02/01/04', |
| 256 | '02/02/04 02/03/04 02/04/04 02/05/04 02/06/04 02/07/04 02/08/04', |
| 257 | '02/09/04 02/10/04 02/11/04 02/12/04 02/13/04 02/14/04 02/15/04', |
| 258 | '02/16/04 02/17/04 02/18/04 02/19/04 02/20/04 02/21/04 02/22/04', |
| 259 | '02/23/04 02/24/04 02/25/04 02/26/04 02/27/04 02/28/04 02/29/04'], |
| 260 | ['03/01/04 03/02/04 03/03/04 03/04/04 03/05/04 03/06/04 03/07/04', |
| 261 | '03/08/04 03/09/04 03/10/04 03/11/04 03/12/04 03/13/04 03/14/04', |
| 262 | '03/15/04 03/16/04 03/17/04 03/18/04 03/19/04 03/20/04 03/21/04', |
| 263 | '03/22/04 03/23/04 03/24/04 03/25/04 03/26/04 03/27/04 03/28/04', |
| 264 | '03/29/04 03/30/04 03/31/04 04/01/04 04/02/04 04/03/04 04/04/04']], |
| 265 | [['03/29/04 03/30/04 03/31/04 04/01/04 04/02/04 04/03/04 04/04/04', |
| 266 | '04/05/04 04/06/04 04/07/04 04/08/04 04/09/04 04/10/04 04/11/04', |
| 267 | '04/12/04 04/13/04 04/14/04 04/15/04 04/16/04 04/17/04 04/18/04', |
| 268 | '04/19/04 04/20/04 04/21/04 04/22/04 04/23/04 04/24/04 04/25/04', |
| 269 | '04/26/04 04/27/04 04/28/04 04/29/04 04/30/04 05/01/04 05/02/04'], |
| 270 | ['04/26/04 04/27/04 04/28/04 04/29/04 04/30/04 05/01/04 05/02/04', |
| 271 | '05/03/04 05/04/04 05/05/04 05/06/04 05/07/04 05/08/04 05/09/04', |
| 272 | '05/10/04 05/11/04 05/12/04 05/13/04 05/14/04 05/15/04 05/16/04', |
| 273 | '05/17/04 05/18/04 05/19/04 05/20/04 05/21/04 05/22/04 05/23/04', |
| 274 | '05/24/04 05/25/04 05/26/04 05/27/04 05/28/04 05/29/04 05/30/04', |
| 275 | '05/31/04 06/01/04 06/02/04 06/03/04 06/04/04 06/05/04 06/06/04'], |
| 276 | ['05/31/04 06/01/04 06/02/04 06/03/04 06/04/04 06/05/04 06/06/04', |
| 277 | '06/07/04 06/08/04 06/09/04 06/10/04 06/11/04 06/12/04 06/13/04', |
| 278 | '06/14/04 06/15/04 06/16/04 06/17/04 06/18/04 06/19/04 06/20/04', |
| 279 | '06/21/04 06/22/04 06/23/04 06/24/04 06/25/04 06/26/04 06/27/04', |
| 280 | '06/28/04 06/29/04 06/30/04 07/01/04 07/02/04 07/03/04 07/04/04']], |
| 281 | [['06/28/04 06/29/04 06/30/04 07/01/04 07/02/04 07/03/04 07/04/04', |
| 282 | '07/05/04 07/06/04 07/07/04 07/08/04 07/09/04 07/10/04 07/11/04', |
| 283 | '07/12/04 07/13/04 07/14/04 07/15/04 07/16/04 07/17/04 07/18/04', |
| 284 | '07/19/04 07/20/04 07/21/04 07/22/04 07/23/04 07/24/04 07/25/04', |
| 285 | '07/26/04 07/27/04 07/28/04 07/29/04 07/30/04 07/31/04 08/01/04'], |
| 286 | ['07/26/04 07/27/04 07/28/04 07/29/04 07/30/04 07/31/04 08/01/04', |
| 287 | '08/02/04 08/03/04 08/04/04 08/05/04 08/06/04 08/07/04 08/08/04', |
| 288 | '08/09/04 08/10/04 08/11/04 08/12/04 08/13/04 08/14/04 08/15/04', |
| 289 | '08/16/04 08/17/04 08/18/04 08/19/04 08/20/04 08/21/04 08/22/04', |
| 290 | '08/23/04 08/24/04 08/25/04 08/26/04 08/27/04 08/28/04 08/29/04', |
| 291 | '08/30/04 08/31/04 09/01/04 09/02/04 09/03/04 09/04/04 09/05/04'], |
| 292 | ['08/30/04 08/31/04 09/01/04 09/02/04 09/03/04 09/04/04 09/05/04', |
| 293 | '09/06/04 09/07/04 09/08/04 09/09/04 09/10/04 09/11/04 09/12/04', |
| 294 | '09/13/04 09/14/04 09/15/04 09/16/04 09/17/04 09/18/04 09/19/04', |
| 295 | '09/20/04 09/21/04 09/22/04 09/23/04 09/24/04 09/25/04 09/26/04', |
| 296 | '09/27/04 09/28/04 09/29/04 09/30/04 10/01/04 10/02/04 10/03/04']], |
| 297 | [['09/27/04 09/28/04 09/29/04 09/30/04 10/01/04 10/02/04 10/03/04', |
| 298 | '10/04/04 10/05/04 10/06/04 10/07/04 10/08/04 10/09/04 10/10/04', |
| 299 | '10/11/04 10/12/04 10/13/04 10/14/04 10/15/04 10/16/04 10/17/04', |
| 300 | '10/18/04 10/19/04 10/20/04 10/21/04 10/22/04 10/23/04 10/24/04', |
| 301 | '10/25/04 10/26/04 10/27/04 10/28/04 10/29/04 10/30/04 10/31/04'], |
| 302 | ['11/01/04 11/02/04 11/03/04 11/04/04 11/05/04 11/06/04 11/07/04', |
| 303 | '11/08/04 11/09/04 11/10/04 11/11/04 11/12/04 11/13/04 11/14/04', |
| 304 | '11/15/04 11/16/04 11/17/04 11/18/04 11/19/04 11/20/04 11/21/04', |
| 305 | '11/22/04 11/23/04 11/24/04 11/25/04 11/26/04 11/27/04 11/28/04', |
| 306 | '11/29/04 11/30/04 12/01/04 12/02/04 12/03/04 12/04/04 12/05/04'], |
| 307 | ['11/29/04 11/30/04 12/01/04 12/02/04 12/03/04 12/04/04 12/05/04', |
| 308 | '12/06/04 12/07/04 12/08/04 12/09/04 12/10/04 12/11/04 12/12/04', |
| 309 | '12/13/04 12/14/04 12/15/04 12/16/04 12/17/04 12/18/04 12/19/04', |
| 310 | '12/20/04 12/21/04 12/22/04 12/23/04 12/24/04 12/25/04 12/26/04', |
| 311 | '12/27/04 12/28/04 12/29/04 12/30/04 12/31/04 01/01/05 01/02/05']]] |
| 312 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 313 | |
| 314 | class OutputTestCase(unittest.TestCase): |
| 315 | def normalize_calendar(self, s): |
Mark Dickinson | 934896d | 2009-02-21 20:59:32 +0000 | [diff] [blame] | 316 | # Filters out locale dependent strings |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 317 | def neitherspacenordigit(c): |
| 318 | return not c.isspace() and not c.isdigit() |
| 319 | |
| 320 | lines = [] |
Ezio Melotti | d8b509b | 2011-09-28 17:37:55 +0300 | [diff] [blame] | 321 | for line in s.splitlines(keepends=False): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 322 | # Drop texts, as they are locale dependent |
| 323 | if line and not filter(neitherspacenordigit, line): |
| 324 | lines.append(line) |
| 325 | return lines |
| 326 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 327 | def check_htmlcalendar_encoding(self, req, res): |
| 328 | cal = calendar.HTMLCalendar() |
| 329 | self.assertEqual( |
| 330 | cal.formatyearpage(2004, encoding=req).strip(b' \t\n'), |
| 331 | (result_2004_html % {'e': res}).strip(' \t\n').encode(res) |
| 332 | ) |
| 333 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 334 | def test_output(self): |
| 335 | self.assertEqual( |
| 336 | self.normalize_calendar(calendar.calendar(2004)), |
| 337 | self.normalize_calendar(result_2004_text) |
| 338 | ) |
| 339 | |
| 340 | def test_output_textcalendar(self): |
| 341 | self.assertEqual( |
| 342 | calendar.TextCalendar().formatyear(2004).strip(), |
| 343 | result_2004_text.strip() |
| 344 | ) |
| 345 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 346 | def test_output_htmlcalendar_encoding_ascii(self): |
| 347 | self.check_htmlcalendar_encoding('ascii', 'ascii') |
| 348 | |
| 349 | def test_output_htmlcalendar_encoding_utf8(self): |
| 350 | self.check_htmlcalendar_encoding('utf-8', 'utf-8') |
| 351 | |
| 352 | def test_output_htmlcalendar_encoding_default(self): |
| 353 | self.check_htmlcalendar_encoding(None, sys.getdefaultencoding()) |
| 354 | |
| 355 | def test_yeardatescalendar(self): |
| 356 | def shrink(cal): |
R David Murray | bb75678 | 2012-05-30 08:10:54 -0400 | [diff] [blame] | 357 | return [[[' '.join('{:02d}/{:02d}/{}'.format( |
| 358 | d.month, d.day, str(d.year)[-2:]) for d in z) |
| 359 | for z in y] for y in x] for x in cal] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 360 | self.assertEqual( |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 361 | shrink(calendar.Calendar().yeardatescalendar(2004)), |
| 362 | result_2004_dates |
| 363 | ) |
| 364 | |
| 365 | def test_yeardayscalendar(self): |
| 366 | self.assertEqual( |
| 367 | calendar.Calendar().yeardayscalendar(2004), |
| 368 | result_2004_days |
| 369 | ) |
| 370 | |
| 371 | def test_formatweekheader_short(self): |
| 372 | self.assertEqual( |
| 373 | calendar.TextCalendar().formatweekheader(2), |
| 374 | 'Mo Tu We Th Fr Sa Su' |
| 375 | ) |
| 376 | |
| 377 | def test_formatweekheader_long(self): |
| 378 | self.assertEqual( |
| 379 | calendar.TextCalendar().formatweekheader(9), |
| 380 | ' Monday Tuesday Wednesday Thursday ' |
| 381 | ' Friday Saturday Sunday ' |
| 382 | ) |
| 383 | |
| 384 | def test_formatmonth(self): |
| 385 | self.assertEqual( |
| 386 | calendar.TextCalendar().formatmonth(2004, 1).strip(), |
| 387 | result_2004_01_text.strip() |
| 388 | ) |
| 389 | |
| 390 | def test_formatmonthname_with_year(self): |
| 391 | self.assertEqual( |
| 392 | calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=True), |
| 393 | '<tr><th colspan="7" class="month">January 2004</th></tr>' |
| 394 | ) |
| 395 | |
| 396 | def test_formatmonthname_without_year(self): |
| 397 | self.assertEqual( |
| 398 | calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=False), |
| 399 | '<tr><th colspan="7" class="month">January</th></tr>' |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 400 | ) |
| 401 | |
Ezio Melotti | 87f0937 | 2013-09-14 04:55:53 +0300 | [diff] [blame] | 402 | def test_prweek(self): |
| 403 | with support.captured_stdout() as out: |
| 404 | week = [(1,0), (2,1), (3,2), (4,3), (5,4), (6,5), (7,6)] |
| 405 | calendar.TextCalendar().prweek(week, 1) |
| 406 | self.assertEqual(out.getvalue().strip(), "1 2 3 4 5 6 7") |
| 407 | |
| 408 | def test_prmonth(self): |
| 409 | with support.captured_stdout() as out: |
| 410 | calendar.TextCalendar().prmonth(2004, 1) |
| 411 | output = out.getvalue().strip() |
| 412 | self.assertEqual(output, result_2004_01_text.strip()) |
| 413 | |
| 414 | def test_pryear(self): |
| 415 | with support.captured_stdout() as out: |
| 416 | calendar.TextCalendar().pryear(2004) |
| 417 | self.assertEqual(out.getvalue().strip(), result_2004_text.strip()) |
| 418 | |
| 419 | def test_format(self): |
| 420 | with support.captured_stdout() as out: |
| 421 | calendar.format(["1", "2", "3"], colwidth=3, spacing=1) |
| 422 | self.assertEqual(out.getvalue().strip(), "1 2 3") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 423 | |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 424 | class CalendarTestCase(unittest.TestCase): |
| 425 | def test_isleap(self): |
| 426 | # Make sure that the return is right for a few years, and |
| 427 | # ensure that the return values are 1 or 0, not just true or |
| 428 | # false (see SF bug #485794). Specific additional tests may |
| 429 | # be appropriate; this tests a single "cycle". |
| 430 | self.assertEqual(calendar.isleap(2000), 1) |
| 431 | self.assertEqual(calendar.isleap(2001), 0) |
| 432 | self.assertEqual(calendar.isleap(2002), 0) |
| 433 | self.assertEqual(calendar.isleap(2003), 0) |
| 434 | |
| 435 | def test_setfirstweekday(self): |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 436 | self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber') |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 437 | self.assertRaises(ValueError, calendar.setfirstweekday, -1) |
| 438 | self.assertRaises(ValueError, calendar.setfirstweekday, 200) |
| 439 | orig = calendar.firstweekday() |
| 440 | calendar.setfirstweekday(calendar.SUNDAY) |
| 441 | self.assertEqual(calendar.firstweekday(), calendar.SUNDAY) |
| 442 | calendar.setfirstweekday(calendar.MONDAY) |
| 443 | self.assertEqual(calendar.firstweekday(), calendar.MONDAY) |
| 444 | calendar.setfirstweekday(orig) |
| 445 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 446 | def test_illegal_weekday_reported(self): |
| 447 | with self.assertRaisesRegex(calendar.IllegalWeekdayError, '123'): |
| 448 | calendar.setfirstweekday(123) |
| 449 | |
| 450 | def test_enumerate_weekdays(self): |
Skip Montanaro | 693c6c4 | 2002-03-15 03:57:04 +0000 | [diff] [blame] | 451 | self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10) |
| 452 | self.assertRaises(IndexError, calendar.day_name.__getitem__, 10) |
| 453 | self.assertEqual(len([d for d in calendar.day_abbr]), 7) |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 454 | |
Tim Peters | 0c2c8e7 | 2002-03-23 03:26:53 +0000 | [diff] [blame] | 455 | def test_days(self): |
| 456 | for attr in "day_name", "day_abbr": |
| 457 | value = getattr(calendar, attr) |
| 458 | self.assertEqual(len(value), 7) |
| 459 | self.assertEqual(len(value[:]), 7) |
| 460 | # ensure they're all unique |
Tim Peters | bbc0d44 | 2004-11-13 16:18:32 +0000 | [diff] [blame] | 461 | self.assertEqual(len(set(value)), 7) |
| 462 | # verify it "acts like a sequence" in two forms of iteration |
| 463 | self.assertEqual(value[::-1], list(reversed(value))) |
Tim Peters | 0c2c8e7 | 2002-03-23 03:26:53 +0000 | [diff] [blame] | 464 | |
| 465 | def test_months(self): |
| 466 | for attr in "month_name", "month_abbr": |
| 467 | value = getattr(calendar, attr) |
| 468 | self.assertEqual(len(value), 13) |
| 469 | self.assertEqual(len(value[:]), 13) |
| 470 | self.assertEqual(value[0], "") |
| 471 | # ensure they're all unique |
Tim Peters | bbc0d44 | 2004-11-13 16:18:32 +0000 | [diff] [blame] | 472 | self.assertEqual(len(set(value)), 13) |
| 473 | # verify it "acts like a sequence" in two forms of iteration |
| 474 | self.assertEqual(value[::-1], list(reversed(value))) |
Tim Peters | 0c2c8e7 | 2002-03-23 03:26:53 +0000 | [diff] [blame] | 475 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 476 | def test_locale_calendars(self): |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 477 | # ensure that Locale{Text,HTML}Calendar resets the locale properly |
| 478 | # (it is still not thread-safe though) |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 479 | old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) |
Georg Brandl | 9450cc0 | 2010-10-20 06:50:19 +0000 | [diff] [blame] | 480 | try: |
Serhiy Storchaka | f9fcdb7 | 2013-01-31 16:00:42 +0200 | [diff] [blame] | 481 | cal = calendar.LocaleTextCalendar(locale='') |
| 482 | local_weekday = cal.formatweekday(1, 10) |
| 483 | local_month = cal.formatmonthname(2010, 10, 10) |
Georg Brandl | 9450cc0 | 2010-10-20 06:50:19 +0000 | [diff] [blame] | 484 | except locale.Error: |
| 485 | # cannot set the system default locale -- skip rest of test |
Serhiy Storchaka | f9fcdb7 | 2013-01-31 16:00:42 +0200 | [diff] [blame] | 486 | raise unittest.SkipTest('cannot set the system default locale') |
| 487 | self.assertIsInstance(local_weekday, str) |
| 488 | self.assertIsInstance(local_month, str) |
| 489 | self.assertEqual(len(local_weekday), 10) |
| 490 | self.assertGreaterEqual(len(local_month), 10) |
| 491 | cal = calendar.LocaleHTMLCalendar(locale='') |
| 492 | local_weekday = cal.formatweekday(1) |
| 493 | local_month = cal.formatmonthname(2010, 10) |
| 494 | self.assertIsInstance(local_weekday, str) |
| 495 | self.assertIsInstance(local_month, str) |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 496 | new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 497 | self.assertEqual(old_october, new_october) |
Georg Brandl | 7004bd1 | 2010-10-19 18:54:25 +0000 | [diff] [blame] | 498 | |
Ezio Melotti | 85710a4 | 2012-09-21 17:26:35 +0300 | [diff] [blame] | 499 | def test_itermonthdates(self): |
| 500 | # ensure itermonthdates doesn't overflow after datetime.MAXYEAR |
| 501 | # see #15421 |
| 502 | list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) |
| 503 | |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 504 | |
| 505 | class MonthCalendarTestCase(unittest.TestCase): |
| 506 | def setUp(self): |
| 507 | self.oldfirstweekday = calendar.firstweekday() |
| 508 | calendar.setfirstweekday(self.firstweekday) |
| 509 | |
| 510 | def tearDown(self): |
| 511 | calendar.setfirstweekday(self.oldfirstweekday) |
| 512 | |
| 513 | def check_weeks(self, year, month, weeks): |
| 514 | cal = calendar.monthcalendar(year, month) |
| 515 | self.assertEqual(len(cal), len(weeks)) |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 516 | for i in range(len(weeks)): |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 517 | self.assertEqual(weeks[i], sum(day != 0 for day in cal[i])) |
| 518 | |
| 519 | |
| 520 | class MondayTestCase(MonthCalendarTestCase): |
| 521 | firstweekday = calendar.MONDAY |
| 522 | |
| 523 | def test_february(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 524 | # A 28-day february starting on monday (7+7+7+7 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 525 | self.check_weeks(1999, 2, (7, 7, 7, 7)) |
| 526 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 527 | # A 28-day february starting on tuesday (6+7+7+7+1 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 528 | self.check_weeks(2005, 2, (6, 7, 7, 7, 1)) |
| 529 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 530 | # A 28-day february starting on sunday (1+7+7+7+6 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 531 | self.check_weeks(1987, 2, (1, 7, 7, 7, 6)) |
| 532 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 533 | # A 29-day february starting on monday (7+7+7+7+1 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 534 | self.check_weeks(1988, 2, (7, 7, 7, 7, 1)) |
| 535 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 536 | # A 29-day february starting on tuesday (6+7+7+7+2 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 537 | self.check_weeks(1972, 2, (6, 7, 7, 7, 2)) |
| 538 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 539 | # A 29-day february starting on sunday (1+7+7+7+7 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 540 | self.check_weeks(2004, 2, (1, 7, 7, 7, 7)) |
| 541 | |
| 542 | def test_april(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 543 | # A 30-day april starting on monday (7+7+7+7+2 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 544 | self.check_weeks(1935, 4, (7, 7, 7, 7, 2)) |
| 545 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 546 | # A 30-day april starting on tuesday (6+7+7+7+3 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 547 | self.check_weeks(1975, 4, (6, 7, 7, 7, 3)) |
| 548 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 549 | # A 30-day april starting on sunday (1+7+7+7+7+1 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 550 | self.check_weeks(1945, 4, (1, 7, 7, 7, 7, 1)) |
| 551 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 552 | # A 30-day april starting on saturday (2+7+7+7+7 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 553 | self.check_weeks(1995, 4, (2, 7, 7, 7, 7)) |
| 554 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 555 | # A 30-day april starting on friday (3+7+7+7+6 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 556 | self.check_weeks(1994, 4, (3, 7, 7, 7, 6)) |
| 557 | |
| 558 | def test_december(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 559 | # A 31-day december starting on monday (7+7+7+7+3 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 560 | self.check_weeks(1980, 12, (7, 7, 7, 7, 3)) |
| 561 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 562 | # A 31-day december starting on tuesday (6+7+7+7+4 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 563 | self.check_weeks(1987, 12, (6, 7, 7, 7, 4)) |
| 564 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 565 | # A 31-day december starting on sunday (1+7+7+7+7+2 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 566 | self.check_weeks(1968, 12, (1, 7, 7, 7, 7, 2)) |
| 567 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 568 | # A 31-day december starting on thursday (4+7+7+7+6 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 569 | self.check_weeks(1988, 12, (4, 7, 7, 7, 6)) |
| 570 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 571 | # A 31-day december starting on friday (3+7+7+7+7 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 572 | self.check_weeks(2017, 12, (3, 7, 7, 7, 7)) |
| 573 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 574 | # A 31-day december starting on saturday (2+7+7+7+7+1 days) |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 575 | self.check_weeks(2068, 12, (2, 7, 7, 7, 7, 1)) |
| 576 | |
| 577 | |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 578 | class SundayTestCase(MonthCalendarTestCase): |
| 579 | firstweekday = calendar.SUNDAY |
| 580 | |
| 581 | def test_february(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 582 | # A 28-day february starting on sunday (7+7+7+7 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 583 | self.check_weeks(2009, 2, (7, 7, 7, 7)) |
| 584 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 585 | # A 28-day february starting on monday (6+7+7+7+1 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 586 | self.check_weeks(1999, 2, (6, 7, 7, 7, 1)) |
| 587 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 588 | # A 28-day february starting on saturday (1+7+7+7+6 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 589 | self.check_weeks(1997, 2, (1, 7, 7, 7, 6)) |
| 590 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 591 | # A 29-day february starting on sunday (7+7+7+7+1 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 592 | self.check_weeks(2004, 2, (7, 7, 7, 7, 1)) |
| 593 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 594 | # A 29-day february starting on monday (6+7+7+7+2 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 595 | self.check_weeks(1960, 2, (6, 7, 7, 7, 2)) |
| 596 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 597 | # A 29-day february starting on saturday (1+7+7+7+7 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 598 | self.check_weeks(1964, 2, (1, 7, 7, 7, 7)) |
| 599 | |
| 600 | def test_april(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 601 | # A 30-day april starting on sunday (7+7+7+7+2 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 602 | self.check_weeks(1923, 4, (7, 7, 7, 7, 2)) |
| 603 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 604 | # A 30-day april starting on monday (6+7+7+7+3 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 605 | self.check_weeks(1918, 4, (6, 7, 7, 7, 3)) |
| 606 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 607 | # A 30-day april starting on saturday (1+7+7+7+7+1 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 608 | self.check_weeks(1950, 4, (1, 7, 7, 7, 7, 1)) |
| 609 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 610 | # A 30-day april starting on friday (2+7+7+7+7 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 611 | self.check_weeks(1960, 4, (2, 7, 7, 7, 7)) |
| 612 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 613 | # A 30-day april starting on thursday (3+7+7+7+6 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 614 | self.check_weeks(1909, 4, (3, 7, 7, 7, 6)) |
| 615 | |
| 616 | def test_december(self): |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 617 | # A 31-day december starting on sunday (7+7+7+7+3 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 618 | self.check_weeks(2080, 12, (7, 7, 7, 7, 3)) |
| 619 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 620 | # A 31-day december starting on monday (6+7+7+7+4 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 621 | self.check_weeks(1941, 12, (6, 7, 7, 7, 4)) |
| 622 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 623 | # A 31-day december starting on saturday (1+7+7+7+7+2 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 624 | self.check_weeks(1923, 12, (1, 7, 7, 7, 7, 2)) |
| 625 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 626 | # A 31-day december starting on wednesday (4+7+7+7+6 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 627 | self.check_weeks(1948, 12, (4, 7, 7, 7, 6)) |
| 628 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 629 | # A 31-day december starting on thursday (3+7+7+7+7 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 630 | self.check_weeks(1927, 12, (3, 7, 7, 7, 7)) |
| 631 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 632 | # A 31-day december starting on friday (2+7+7+7+7+1 days) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 633 | self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1)) |
| 634 | |
Alexander Belopolsky | 43ca710 | 2010-06-14 17:32:03 +0000 | [diff] [blame] | 635 | class TimegmTestCase(unittest.TestCase): |
| 636 | TIMESTAMPS = [0, 10, 100, 1000, 10000, 100000, 1000000, |
| 637 | 1234567890, 1262304000, 1275785153,] |
| 638 | def test_timegm(self): |
| 639 | for secs in self.TIMESTAMPS: |
| 640 | tuple = time.gmtime(secs) |
| 641 | self.assertEqual(secs, calendar.timegm(tuple)) |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 642 | |
Brett Cannon | cfae36f | 2010-07-23 13:54:14 +0000 | [diff] [blame] | 643 | class MonthRangeTestCase(unittest.TestCase): |
| 644 | def test_january(self): |
| 645 | # Tests valid lower boundary case. |
| 646 | self.assertEqual(calendar.monthrange(2004,1), (3,31)) |
| 647 | |
| 648 | def test_february_leap(self): |
| 649 | # Tests February during leap year. |
| 650 | self.assertEqual(calendar.monthrange(2004,2), (6,29)) |
| 651 | |
| 652 | def test_february_nonleap(self): |
| 653 | # Tests February in non-leap year. |
| 654 | self.assertEqual(calendar.monthrange(2010,2), (0,28)) |
| 655 | |
| 656 | def test_december(self): |
| 657 | # Tests valid upper boundary case. |
| 658 | self.assertEqual(calendar.monthrange(2004,12), (2,31)) |
| 659 | |
| 660 | def test_zeroth_month(self): |
| 661 | # Tests low invalid boundary case. |
| 662 | with self.assertRaises(calendar.IllegalMonthError): |
| 663 | calendar.monthrange(2004, 0) |
| 664 | |
| 665 | def test_thirteenth_month(self): |
| 666 | # Tests high invalid boundary case. |
| 667 | with self.assertRaises(calendar.IllegalMonthError): |
| 668 | calendar.monthrange(2004, 13) |
| 669 | |
R David Murray | d0c8695 | 2012-05-29 12:55:05 -0400 | [diff] [blame] | 670 | def test_illegal_month_reported(self): |
| 671 | with self.assertRaisesRegex(calendar.IllegalMonthError, '65'): |
| 672 | calendar.monthrange(2004, 65) |
| 673 | |
R. David Murray | 1daaf9e | 2010-12-31 19:21:14 +0000 | [diff] [blame] | 674 | class LeapdaysTestCase(unittest.TestCase): |
| 675 | def test_no_range(self): |
| 676 | # test when no range i.e. two identical years as args |
| 677 | self.assertEqual(calendar.leapdays(2010,2010), 0) |
| 678 | |
| 679 | def test_no_leapdays(self): |
| 680 | # test when no leap years in range |
| 681 | self.assertEqual(calendar.leapdays(2010,2011), 0) |
| 682 | |
| 683 | def test_no_leapdays_upper_boundary(self): |
| 684 | # test no leap years in range, when upper boundary is a leap year |
| 685 | self.assertEqual(calendar.leapdays(2010,2012), 0) |
| 686 | |
| 687 | def test_one_leapday_lower_boundary(self): |
| 688 | # test when one leap year in range, lower boundary is leap year |
| 689 | self.assertEqual(calendar.leapdays(2012,2013), 1) |
| 690 | |
| 691 | def test_several_leapyears_in_range(self): |
| 692 | self.assertEqual(calendar.leapdays(1997,2020), 5) |
| 693 | |
Brett Cannon | cfae36f | 2010-07-23 13:54:14 +0000 | [diff] [blame] | 694 | |
Senthil Kumaran | 962fed9 | 2011-08-11 09:22:52 +0800 | [diff] [blame] | 695 | class ConsoleOutputTestCase(unittest.TestCase): |
| 696 | def test_outputs_bytes(self): |
| 697 | (return_code, stdout, stderr) = assert_python_ok('-m', 'calendar', '--type=html', '2010') |
| 698 | self.assertEqual(stdout[:6], b'<?xml ') |
| 699 | |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 700 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 701 | support.run_unittest( |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 702 | OutputTestCase, |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 703 | CalendarTestCase, |
Walter Dörwald | 302fa6d | 2004-07-08 17:14:17 +0000 | [diff] [blame] | 704 | MondayTestCase, |
Alexander Belopolsky | 43ca710 | 2010-06-14 17:32:03 +0000 | [diff] [blame] | 705 | SundayTestCase, |
| 706 | TimegmTestCase, |
Brett Cannon | cfae36f | 2010-07-23 13:54:14 +0000 | [diff] [blame] | 707 | MonthRangeTestCase, |
R. David Murray | 1daaf9e | 2010-12-31 19:21:14 +0000 | [diff] [blame] | 708 | LeapdaysTestCase, |
Senthil Kumaran | 962fed9 | 2011-08-11 09:22:52 +0800 | [diff] [blame] | 709 | ConsoleOutputTestCase |
Walter Dörwald | 59ad456 | 2004-07-02 19:00:09 +0000 | [diff] [blame] | 710 | ) |
| 711 | |
Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 712 | |
| 713 | if __name__ == "__main__": |
| 714 | test_main() |