-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-34903: For datetime.datetime.strptime(), the leading zero for some two-digit formats is optional #9747
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
Sorry for being so lame at creating this pull request. The title should be: class TestStrptime(unittest.TestCase):
def show(): if name == 'main': |
@mikegleen You should be able to edit the title on the PR by clicking the Edit button to the right of the title. Please submit the CLA if you haven't yet done so. Thanks. |
Thanks, the title is updated now – I'm a little embarrassed not to have
noticed the Edit button.
The CLA is in process but there was some confusion as my bugs.python.org
userid is not the same as my github userid. I'm told it should may take a
couple of days.
…On Mon, Oct 8, 2018 at 10:58 PM Carol Willing ***@***.***> wrote:
@mikegleen <https://github.com/mikegleen> You should be able to edit the
title on the PR by clicking the Edit button to the right of the title.
Please submit the CLA if you haven't yet done so. Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9747 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABy9pn2ZZsXM6Hvo14UXJ4VhGnDRmOTfks5ui8qVgaJpZM4XLsQm>
.
|
Thanks for the update @mikegleen. No worries on the button (IMHO the edit button is a bit to far to the right in the GitHub UI). 🍪 |
@mikegleen It would be interesting to have the tests you commented out on this thread added to your PR. Reach me out If you have any questions about that. Thanks! |
Gus,
Here's the simple test code. Please let me know if you receive this as I am
not familiar with the email address style for replies.
Regards,
Mike
…On Tue, Oct 9, 2018 at 12:27 AM Gus Goulart ***@***.***> wrote:
@mikegleenIt would be interesting to have the tests you commented out on
this thread added to your PR. Reach me out If you have any questions about
that. Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9747 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABy9phljSvkS20-DT-E0fVnZE0NnAwUPks5ui994gaJpZM4XLsQm>
.
|
@mikegleen to make sure your tests are effective, they must be included in the Python test suite. Take a look at |
Gus,
I had a look at the existing test code for datetime.strptime and found that
it already tests the case of single digit days and months. So it looks like
it's just the doc that needs updating. Thanks for pointing me at that.
Regards,
Mike
…On Tue, Oct 9, 2018 at 1:35 PM Gus Goulart ***@***.***> wrote:
@mikegleen <https://github.com/mikegleen> to make sure your tests are
effective, they must be included in the Python test suite. Take a look at
/Lib/test and see where you can fit them.
To accomplish that, add your tests to the test file you found, commit the
changes and push the new commit to your pull request.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9747 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABy9pvivkWxz6FlV7mw2DIPntTL73x25ks5ujHvngaJpZM4XLsQm>
.
|
Hi @mikegleen, Have you filled out the CLA?
|
@mikegleen could you add the test code to the PR? |
merge updates
When Gus Goulart initially mentioned including the test code, I checked datetimetester.py and saw that single digit dates were already tested. I replied about this and did not proceed any further. But now, looking again, I see that the testing is somewhat incidental and it would be better to have a well-defined test of this issue. So I suggest that I create a separate PR for datetimetester.py, as so much time has passed since the original PR. Are you ok with this? Mike Gleen |
@mikegleen Up to you. No one will take issue if you add it to this one or create a separate PR. If you do a separate PR then please reference it here so people know where to look for the tests. And I'll leave a Changes Requests review so no one loses track of needing the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
by strptime. This test pairs with PR 9747 which updates the datetime doc. The corresponding bug report is bpo-34903.
I've updated datetimetester.py but the pull request failed because (I think) the existing PR (9747) also included the changes to the doc file. So I think I should close 9747 and then again create a PR which will now correctly include changes to both files. But I thought I should check first. Does this sound right? |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
Lib/test/datetimetester.py
Outdated
@@ -2425,6 +2425,22 @@ def test_strptime(self): | |||
self.assertEqual(expected, got) | |||
|
|||
strptime = self.theclass.strptime | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's actually a https://github.com/python/cpython/blob/master/Lib/test/test_strptime.py file for tests relating to strptime
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a huge fan of the test_strptime
thing, which tests _strptime
directly rather than testing the public API function(s) datetime.strptime
and time.strptime
.
The reasoning for this is that the tests in datetimetester.py
run against the C and datetime
implementations per PEP 399, and they are parametrized to be run against subclasses of datetime
.
In this case, I think it's unlikely that these tests will be affected by either of these things, but I also don't think the cost is particularly high, so I lean in favor of testing in datetimetester.py
rather than test_strptime.py
unless there's a compelling reason to do otherwise.
Lib/test/datetimetester.py
Outdated
|
||
# bpo-34903: Check that single digit dates and times are allowed. | ||
with self.assertRaises(ValueError): | ||
# %y does require two digits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# %y does require two digits | |
# %y does require two digits. |
Lib/test/datetimetester.py
Outdated
with self.assertRaises(ValueError): | ||
# %y does require two digits | ||
newdate = strptime('1/2/3 4:5:6', '%d/%m/%y %H:%M:%S') | ||
inputs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide comments specifying which format option you're specifically testing? Or better yet, provide explicit tests for each format you're testing? (You can keep these real-world examples as well).
Lib/test/datetimetester.py
Outdated
('6/4/2003', '%u/%V/%G', '2003-01-25T00:00:00') | ||
] | ||
for string, format, target in inputs: | ||
newdate = strptime(string, format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use unittest.subTest()
?
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
update to latest.
update latest
Replaced by #14149. |
https://bugs.python.org/issue34903