diff options
author | Brett Cannon <bcannon@gmail.com> | 2004-10-18 01:37:57 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2004-10-18 01:37:57 (GMT) |
commit | 8abcc5d5339d8d8e056138d1217fa07fdcc342c9 (patch) | |
tree | 15928368ac3057ce2aa850987525ec24c5d62c06 /Lib/test/test_strptime.py | |
parent | be8370dc9cd3a9c951d8869088502f84e6892a6e (diff) | |
download | cpython-8abcc5d5339d8d8e056138d1217fa07fdcc342c9.zip cpython-8abcc5d5339d8d8e056138d1217fa07fdcc342c9.tar.gz cpython-8abcc5d5339d8d8e056138d1217fa07fdcc342c9.tar.bz2 |
Add support for %U and %W to contribute to calculating the date when the year
and day of the week are specified.
Closes bug #1045381.
Diffstat (limited to 'Lib/test/test_strptime.py')
-rw-r--r-- | Lib/test/test_strptime.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index 17f339b..bc68851 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -6,6 +6,7 @@ import locale import re import sys from test import test_support +from datetime import date as datetime_date import _strptime @@ -417,6 +418,27 @@ class CalculationTests(unittest.TestCase): "Calculation of day of the week failed;" "%s != %s" % (result.tm_wday, self.time_tuple.tm_wday)) + def test_week_of_year_and_day_of_week_calculation(self): + # Should be able to infer date if given year, week of year (%U or %W) + # and day of the week + def test_helper(ymd_tuple, test_reason): + for directive in ('W', 'U'): + format_string = "%%Y %%%s %%w" % directive + strp_input = datetime_date(*ymd_tuple).strftime(format_string) + strp_output = _strptime.strptime(strp_input, format_string) + self.failUnless(strp_output[:3] == ymd_tuple, + "%s(%s) test failed w/ '%s': %s != %s" % + (test_reason, directive, strp_input, + strp_output[:3], ymd_tuple[:3])) + test_helper((1901, 1, 3), "week 0") + test_helper((1901, 1, 8), "common case") + test_helper((1901, 1, 13), "day on Sunday") + test_helper((1901, 1, 14), "day on Monday") + test_helper((1905, 1, 1), "Jan 1 on Sunday") + test_helper((1906, 1, 1), "Jan 1 on Monday") + test_helper((1905, 12, 31), "Dec 31 on Sunday") + test_helper((1906, 12, 31), "Dec 31 on Monday") + class CacheTests(unittest.TestCase): """Test that caching works properly.""" |