Browse Source

Make sorting more predictable.

Always first sort by name then by any attributes you want. Otherwise,
tests may fail.
main
Vincent Bernat 13 years ago
parent
commit
cc09d99a4e
2 changed files with 6 additions and 5 deletions
  1. +2
    -1
      hyde/ext/plugins/sorter.py
  2. +4
    -4
      hyde/tests/ext/test_sorter.py

+ 2
- 1
hyde/ext/plugins/sorter.py View File

@@ -44,7 +44,8 @@ def sort_method(node, settings=None):
if settings and hasattr(settings, 'attr') and settings.attr:
attr = settings.attr
filter_ = partial(filter_method, settings=settings)
resources = ifilter(filter_, node.walk_resources())
resources = sorted(ifilter(filter_, node.walk_resources()),
key=lambda f: f.name)
reverse = False
if settings and hasattr(settings, 'reverse'):
reverse = settings.reverse


+ 4
- 4
hyde/tests/ext/test_sorter.py View File

@@ -49,7 +49,7 @@ class TestSorter(object):
pages = [page.name for page in
s.content.walk_resources_sorted_by_kind()]

assert pages == sorted(expected, key=lambda f: File(f).kind)
assert pages == sorted(sorted(expected), key=lambda f: File(f).kind)

def test_walk_resources_sorted_reverse(self):
s = Site(TEST_SITE)
@@ -74,7 +74,7 @@ class TestSorter(object):
s.content.walk_resources_sorted_by_kind()]


assert pages == sorted(expected, key=lambda f: File(f).kind, reverse=True)
assert pages == sorted(sorted(expected), key=lambda f: File(f).kind, reverse=True)

def test_walk_resources_sorted_with_filters(self):
s = Site(TEST_SITE)
@@ -131,7 +131,7 @@ class TestSorter(object):

expected_sorted = [File(page).name
for page in
sorted(expected,
sorted(sorted(expected),
key=lambda p: tuple(
[File(p).kind,
File(p).parent.name]))]
@@ -269,4 +269,4 @@ class TestSorter(object):
text = target.read_all()
q = PyQuery(text)

assert q('span.latest').text() == 'YayYayYay'
assert q('span.latest').text() == 'YayYayYay'

Loading…
Cancel
Save