diff options
author | Brett Cannon <bcannon@gmail.com> | 2005-11-02 23:04:26 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2005-11-02 23:04:26 (GMT) |
commit | 5d0bf9446b1684b8d2832600ceb49d8c5c4b812d (patch) | |
tree | 41a415bc4f611d69f99432d3ab1afa1323c6a1e4 /Lib/test | |
parent | 076b7325a88f7f779fd4f900a1b8d0214c7e062d (diff) | |
download | cpython-5d0bf9446b1684b8d2832600ceb49d8c5c4b812d.zip cpython-5d0bf9446b1684b8d2832600ceb49d8c5c4b812d.tar.gz cpython-5d0bf9446b1684b8d2832600ceb49d8c5c4b812d.tar.bz2 |
Change time.strptime() to raise ValueError whenever there is an error in the
format string. Before exceptions generated by the internal code propagated up
to the user and were not helpful.
Closes bug #1340337.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_strptime.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index f9763aa..ba65649 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -197,10 +197,20 @@ class StrptimeTests(unittest.TestCase): """Create testing time tuple.""" self.time_tuple = time.gmtime() - def test_TypeError(self): - # Make sure ValueError is raised when match fails + def test_ValueError(self): + # Make sure ValueError is raised when match fails or format is bad self.assertRaises(ValueError, _strptime.strptime, data_string="%d", format="%A") + for bad_format in ("%", "% ", "%e"): + try: + _strptime.strptime("2005", bad_format) + except ValueError: + continue + except Exception, err: + self.fail("'%s' raised %s, not ValueError" % + (bad_format, err.__class__.__name__)) + else: + self.fail("'%s' did not raise ValueError" % bad_format) def test_unconverteddata(self): # Check ValueError is raised when there is unconverted data |