-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-26544: Add test for platform._comparable_version(). #8973
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
bpo-26544: Add test for platform._comparable_version(). #8973
Conversation
vstinner
left a comment
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.
See maybe Lib/distutils/tests/test_version.py for ideas of tests. There are tests for strange versions like "1.13++" :-)
|
|
||
| @support.cpython_only | ||
| def test__comparable_version(self): | ||
| from platform import _comparable_version as V |
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.
What do you think of also adding tests checking directly the result of the function? Compare to a list.
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.
This would expose too much implementation details. For example the initial versions converted '1.2.3' to [(100, 1), (100, 2), (100, 3)], but now it converts to [100, 1, 100, 2, 100, 3]. I thought also for converting to [1, 2, 3] and using negative numbers for pre-release versions and float('inf') for "pl". If this function be public, I would return a tuple, but a list is enough in this case. Of course magic numbers like 100 are arbitrary.
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.
Ok, it's up to you.
| @support.cpython_only | ||
| def test__comparable_version(self): | ||
| from platform import _comparable_version as V | ||
| self.assertEqual(V('1.2.3'), V('1.2.3')) |
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.
If I understood correctly, the function has been added to compare correctly 2.7.9 to 2.7.10 (or a similar issue). Maybe add also a test for that?
Maybe also add a test comparing 2.0 and 2.0.0?
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.
If I understood correctly, the function has been added to compare correctly 2.7.9 to 2.7.10 (or a similar issue). Maybe add also a test for that?
Next line.
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.
Maybe also add a test comparing 2.0 and 2.0.0?
Done. Although this is a case for which the result is different from distutils.version.StrictVersion. I don't think this will add problems in practice (in addition to existing problems of using such guessing function).
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.
Next line.
Oops, I missed it, sorry ;-)
vstinner
left a comment
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.
LGTM, thanks for adding tests!
vstinner
left a comment
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.
@serhiy-storchaka: can you merge this PR and then update/rewrite your backports to include these new tests?
|
|
||
| @support.cpython_only | ||
| def test__comparable_version(self): | ||
| from platform import _comparable_version as V |
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.
Ok, it's up to you.
| @support.cpython_only | ||
| def test__comparable_version(self): | ||
| from platform import _comparable_version as V | ||
| self.assertEqual(V('1.2.3'), V('1.2.3')) |
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.
Next line.
Oops, I missed it, sorry ;-)
https://bugs.python.org/issue26544