Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

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

Copy link
Member

@vstinner vstinner left a 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
Copy link
Member

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

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

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

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

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

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

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

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!

Copy link
Member

@vstinner vstinner left a 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
Copy link
Member

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

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
@serhiy-storchaka serhiy-storchaka deleted the test_platform-test__comparable_version branch September 4, 2018 12:04
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants