8000 WIP: bpo-1100942: Add datetime.time.strptime and datetime.date.strptime by matrixise · Pull Request #5578 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

WIP: bpo-1100942: Add datetime.time.strptime and datetime.date.strptime #5578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
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
Update
  • Loading branch information
matrixise committed Mar 22, 2019
commit 8353a65e702efb5e87efff23d5ec4b376849bb59
4 changes: 4 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ 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
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 @@ -3132,6 +3134,8 @@ 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', '')
]
for date_string, date_format in tests:
Copy link
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
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
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
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
0