Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add use case where we generate an exception
  • Loading branch information
matrixise committed Mar 22, 2019
commit cff74a9540940415fb43b9d40b7c323a4c53bd2a
4 changes: 1 addition & 3 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,6 @@ def test_strptime_valid_format(self):
def test_strptime_invalid_format(self):
tests = [
('2004-12-01 13:02:47.197', '%Y-%m-%d %H:%M:%S.%f'),
('2018-01-01 00:00', '%Y-%m-%d %H:%M'),
('2018-01-01', ''),
('01', '%M'),
('02', '%H'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs at least two more test cases:

    ('2018-01-01 00:00', '%Y-%m-%d %H:%M'),
    ('2018-01-01', ''),

Both should fail.

Expand Down Expand Up @@ -3134,8 +3133,7 @@ def test_strptime_invalid(self):
tests = [
('2004-12-01 13:02:47.197', '%Y-%m-%d %H:%M:%S.%f'),
('2004-12-01', '%Y-%m-%d'),
('1900-01-01 12:30', '%Y-%m-%d %H:%M'),
('12:30:15', '')
('12:30:15', ''),
]
for date_string, date_format in tests:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to use with self.subTest for these parametrized tests.

Also, per the other comment I guess you need to add something like ('12:30:15', '')` to get full coverage.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need two more test cases:

    ('1900-01-01 12:30', '%Y-%m-%d %H:%M'),
    ('12:30:15', ''),

date.strptime has similarly missing tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test with ('1900-01-01 12:30', '%Y-%m-%d %H:%M') does not raise an exception but returns datetime.time(12, 30)

For the other test, yep, there is an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that it doesn't raise an exception is an issue. I'm a bit surprised that it doesn't raise an exception on pure Python, that's a bug, because I'm pretty sure that:

datetime.time.strptime("1901-01-01 12:30", "%Y-%m-%d %H:%M") does raise an exception.

with self.subTest(date_string=date_string, date_format=date_format):
Expand Down