From cc09d99a4e617ea83bb8a2a3b882831447081273 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 7 May 2011 10:04:33 +0200 Subject: [PATCH] Make sorting more predictable. Always first sort by name then by any attributes you want. Otherwise, tests may fail. --- hyde/ext/plugins/sorter.py | 3 ++- hyde/tests/ext/test_sorter.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hyde/ext/plugins/sorter.py b/hyde/ext/plugins/sorter.py index c923283..229e565 100644 --- a/hyde/ext/plugins/sorter.py +++ b/hyde/ext/plugins/sorter.py @@ -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 diff --git a/hyde/tests/ext/test_sorter.py b/hyde/tests/ext/test_sorter.py index 21770dd..29aff42 100644 --- a/hyde/tests/ext/test_sorter.py +++ b/hyde/tests/ext/test_sorter.py @@ -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' \ No newline at end of file + assert q('span.latest').text() == 'YayYayYay'