This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Calendar module test coverage improved
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Oleg.Plakhotnyuk, ezio.melotti, giampaolo.rodola, ncoghlan, python-dev, r.david.murray, rhettinger, vstinner
Priority: normal Keywords: patch

Created on 2012-05-13 16:06 by Oleg.Plakhotnyuk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_calendar.patch Oleg.Plakhotnyuk, 2012-05-25 15:36 review
Messages (9)
msg160519 - (view) Author: Oleg Plakhotnyuk (Oleg.Plakhotnyuk) * Date: 2012-05-13 16:06
I've improved calendar.py test coverage a bit.

Before:
  410    71%   calendar   (.../Lib/calendar.py)
After:
  410    77%   calendar   (.../Lib/calendar.py)
msg160527 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-05-13 17:13
Thanks for the patch.

There are a couple of things I'd change, which I or someone could do while committing if you prefer, but if you'd like to tune up the patch yourself that would be great.

The first is that I'd break up the tests that run more than one test into separate test methods (test_formatweekheader, test_formatmonthname, test_output_htmlcalendar).  The second is that the exception tests can be written more compactly (and IMO more legibly) like this:

    def test_illegal_month_reported(self):
        with self.assertRaisesRegex(calendar.IllegalMonthError, '65'):
            calendar.monthrange(2004, 65)
msg160540 - (view) Author: Oleg Plakhotnyuk (Oleg.Plakhotnyuk) * Date: 2012-05-13 18:08
Thanks for the review.

I'll happily tune the patch myself. Just when I have some spare time again.
msg161061 - (view) Author: Oleg Plakhotnyuk (Oleg.Plakhotnyuk) * Date: 2012-05-18 16:26
I didn't event know that there is such a handy assertRaisesRegex context.

Many thanks for pointing this out!
msg161901 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-29 16:55
New changeset 98bc9e357f74 by R David Murray in branch 'default':
#14796: improve calendar test coverage.
http://hg.python.org/cpython/rev/98bc9e357f74
msg161902 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-05-29 16:56
Thanks, Oleg.
msg161934 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-05-30 08:21
> New changeset 98bc9e357f74 by R David Murray in branch 'default':
> #14796: improve calendar test coverage.
> http://hg.python.org/cpython/rev/98bc9e357f74

The following added test fails on Windows:

...
+    def test_yeardatescalendar(self):
+        def shrink(cal):
+            return [[[' '.join((d.strftime('%D')
+                    for d in z)) for z in y] for y in x] for x in cal]
         self.assertEqual(
-            cal.formatyearpage(2004, encoding=encoding).strip(b' \t\n'),
-            result_2004_html.strip(' \t\n').encode(encoding)
+            shrink(calendar.Calendar().yeardatescalendar(2004)),
+            result_2004_dates
+        )
...

The "%D" format is not supported by strftime(). Extract of timemodule.c:

#if defined(MS_WINDOWS) && !defined(HAVE_WCSFTIME)
    /* check that the format string contains only valid directives */
    for(outbuf = strchr(fmt, '%');
        outbuf != NULL;
        outbuf = strchr(outbuf+2, '%'))
    {
        if (outbuf[1]=='#')
            ++outbuf; /* not documented by python, */
        if (outbuf[1]=='\0' ||
            !strchr("aAbBcdHIjmMpSUwWxXyYzZ%", outbuf[1]))
        {
            PyErr_SetString(PyExc_ValueError, "Invalid format string");
            Py_DECREF(format);
            return NULL;
        }
    }
#endif
msg161947 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-30 12:11
New changeset d3321c010af5 by R David Murray in branch 'default':
#14796: fix failure of new calendar test on windows.
http://hg.python.org/cpython/rev/d3321c010af5
msg161949 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-05-30 13:44
The buildbots seem happy.
History
Date User Action Args
2022-04-11 14:57:30adminsetgithub: 59001
2012-05-30 13:44:18r.david.murraysetstatus: open -> closed

messages: + msg161949
2012-05-30 12:11:02python-devsetmessages: + msg161947
2012-05-30 08:21:07vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg161934

resolution: fixed ->
2012-05-29 16:56:12r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg161902

stage: patch review -> resolved
2012-05-29 16:55:30python-devsetnosy: + python-dev
messages: + msg161901
2012-05-25 15:36:24Oleg.Plakhotnyuksetfiles: + test_calendar.patch
2012-05-25 15:36:10Oleg.Plakhotnyuksetfiles: - test_calendar.patch
2012-05-18 16:26:14Oleg.Plakhotnyuksetfiles: + test_calendar.patch

messages: + msg161061
2012-05-18 16:23:42Oleg.Plakhotnyuksetfiles: - test_calendar.patch
2012-05-13 18:08:22Oleg.Plakhotnyuksetmessages: + msg160540
2012-05-13 17:13:39r.david.murraysetnosy: + r.david.murray
messages: + msg160527
2012-05-13 16:35:45ezio.melottisetnosy: + ezio.melotti
type: enhancement
2012-05-13 16:28:53brett.cannonsetstage: patch review
2012-05-13 16:06:10Oleg.Plakhotnyukcreate