Skip to content
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

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Aug 28, 2018

Copy link
Member

@vstinner vstinner left a comment

See maybe Lib/distutils/tests/test_version.py for ideas of tests. There are tests for strange versions like "1.13++" :-)

@@ -275,6 +275,26 @@ def test_libc_ver(self):
self.assertEqual(platform.libc_ver(support.TESTFN),
('glibc', '1.23.4'))

@support.cpython_only
def test__comparable_version(self):
from platform import _comparable_version as V
Copy link
Member

@vstinner vstinner Aug 28, 2018

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.

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka Aug 28, 2018

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.

Copy link
Member

@vstinner vstinner Sep 4, 2018

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'))
Copy link
Member

@vstinner vstinner Aug 28, 2018

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?

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka Aug 28, 2018

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.

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka Aug 28, 2018

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).

Copy link
Member

@vstinner vstinner Sep 4, 2018

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 ;-)

Copy link
Member

@vstinner vstinner left a comment

LGTM, thanks for adding tests!

Copy link
Member

@vstinner vstinner left a comment

@serhiy-storchaka: can you merge this PR and then update/rewrite your backports to include these new tests?

@@ -275,6 +275,26 @@ def test_libc_ver(self):
self.assertEqual(platform.libc_ver(support.TESTFN),
('glibc', '1.23.4'))

@support.cpython_only
def test__comparable_version(self):
from platform import _comparable_version as V
Copy link
Member

@vstinner vstinner Sep 4, 2018

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'))
Copy link
Member

@vstinner vstinner Sep 4, 2018

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 ;-)

@serhiy-storchaka serhiy-storchaka merged commit 7917aad into python:master Sep 4, 2018
9 checks passed
@serhiy-storchaka serhiy-storchaka deleted the test_platform-test__comparable_version branch Sep 4, 2018
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA signed skip news tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants