-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Handle .x in version sorting #6012
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
Merged
davidfischer
merged 3 commits into
master
from
davidfischer/handle-x-in-version-sorting
Jul 31, 2019
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
readthedocs/rtd_tests/tests/projects/test_version_sorting.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.test import TestCase | ||
from django_dynamic_fixture import get | ||
|
||
from readthedocs.builds.constants import BRANCH | ||
from readthedocs.builds.models import Version | ||
from readthedocs.projects.models import Project | ||
from readthedocs.projects.templatetags.projects_tags import sort_version_aware | ||
|
||
|
||
class SortVersionsTest(TestCase): | ||
|
||
def setUp(self): | ||
self.project = get(Project) | ||
|
||
def test_basic_sort(self): | ||
identifiers = ['1.0', '2.0', '1.1', '1.9', '1.10'] | ||
for identifier in identifiers: | ||
get( | ||
Version, | ||
project=self.project, | ||
type=BRANCH, | ||
identifier=identifier, | ||
verbose_name=identifier, | ||
slug=identifier, | ||
) | ||
|
||
versions = list(Version.objects.filter(project=self.project)) | ||
self.assertEqual( | ||
['latest', '2.0', '1.10', '1.9', '1.1', '1.0'], | ||
[v.slug for v in sort_version_aware(versions)], | ||
) | ||
|
||
def test_sort_wildcard(self): | ||
identifiers = ['1.0.x', '2.0.x', '1.1.x', '1.9.x', '1.10.x'] | ||
for identifier in identifiers: | ||
get( | ||
Version, | ||
project=self.project, | ||
type=BRANCH, | ||
identifier=identifier, | ||
verbose_name=identifier, | ||
slug=identifier, | ||
) | ||
|
||
versions = list(Version.objects.filter(project=self.project)) | ||
self.assertEqual( | ||
['latest', '2.0.x', '1.10.x', '1.9.x', '1.1.x', '1.0.x'], | ||
[v.slug for v in sort_version_aware(versions)], | ||
) | ||
|
||
def test_sort_alpha(self): | ||
identifiers = ['banana', 'apple', 'carrot'] | ||
for identifier in identifiers: | ||
get( | ||
Version, | ||
project=self.project, | ||
type=BRANCH, | ||
identifier=identifier, | ||
verbose_name=identifier, | ||
slug=identifier, | ||
) | ||
|
||
versions = list(Version.objects.filter(project=self.project)) | ||
self.assertEqual( | ||
['latest', 'carrot', 'banana', 'apple'], | ||
[v.slug for v in sort_version_aware(versions)], | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know that this is not a behavior that you changed, but I'd like to sort alphanumeric versions from A to Z instead at some point. Feels more human-readable when you have a many of these.
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.
Do we have any examples of projects that use something like this? I can think of Ubuntu off the top of my head, but that's about it.
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.
test-builds, which may not apply as a real project but shows the sorting problem when building alphanumeric branch names