Browse Source

Made sorting tests predictable without changing the behavior of sorter plugin

main
Lakshmi Vyasarajan 13 years ago
parent
commit
9a7da0e8fa
3 changed files with 15 additions and 10 deletions
  1. +1
    -2
      hyde/ext/plugins/sorter.py
  2. +13
    -7
      hyde/tests/ext/test_sorter.py
  3. +1
    -1
      hyde/tests/templates/jinja2/index.html

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

@@ -44,8 +44,7 @@ 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 = sorted(ifilter(filter_, node.walk_resources()),
key=lambda f: f.name)
resources = ifilter(filter_, node.walk_resources())
reverse = False
if settings and hasattr(settings, 'reverse'):
reverse = settings.reverse


+ 13
- 7
hyde/tests/ext/test_sorter.py View File

@@ -31,7 +31,7 @@ class TestSorter(object):
s = Site(TEST_SITE)
s.load()
s.config.plugins = ['hyde.ext.sorter.SorterPlugin']
s.config.sorter = Expando(dict(kind=dict(attr='source_file.kind')))
s.config.sorter = Expando(dict(kind=dict(attr=['source_file.kind', 'name'])))

SorterPlugin(s).begin_site()

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

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

def test_walk_resources_sorted_reverse(self):
s = Site(TEST_SITE)
s.load()
s.config.plugins = ['hyde.ext.sorter.SorterPlugin']
s.config.sorter = Expando(dict(kind=dict(attr='source_file.kind', reverse=True)))
s.config.sorter = Expando(dict(kind=dict(attr=['source_file.kind', 'name'], reverse=True)))

SorterPlugin(s).begin_site()

@@ -74,7 +74,7 @@ class TestSorter(object):
s.content.walk_resources_sorted_by_kind()]


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

def test_walk_resources_sorted_with_filters(self):
s = Site(TEST_SITE)
@@ -110,6 +110,7 @@ class TestSorter(object):
attr:
- source_file.kind
- node.name
- name

"""
s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
@@ -131,10 +132,10 @@ class TestSorter(object):

expected_sorted = [File(page).name
for page in
sorted(sorted(expected),
sorted(expected,
key=lambda p: tuple(
[File(p).kind,
File(p).parent.name]))]
File(p).parent.name, p]))]
assert pages == expected_sorted

def test_walk_resources_sorted_no_default_is_processable(self):
@@ -146,6 +147,8 @@ class TestSorter(object):
kind2:
filters:
source_file.kind: html
attr:
- name
"""
s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
s.load()
@@ -169,6 +172,8 @@ class TestSorter(object):
kind2:
filters:
source_file.kind: html
attr:
- name
"""
s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
s.load()
@@ -201,7 +206,8 @@ class TestSorter(object):
- hyde.ext.sorter.SorterPlugin
sorter:
folder_name:
attr: node.name
attr:
- node.name
reverse: True
filters:
source_file.kind: html


+ 1
- 1
hyde/tests/templates/jinja2/index.html View File

@@ -6,7 +6,7 @@
<div class="article">
<h2><a href="{{ article.href|e }}">{{ article.title|e }}</a></h2>
<p class="meta">written by <a href="{{ article.user.href|e
}}">{{ article.user.username|e }}</a> on {{ article.pub_date.strftime('%Y-%m-%d') }}</p>
}}">{{ article.user.username|e }}</a> on {{ article.pub_date|dateformat }}</p>
<div class="text">{{ article.body }}</div>
</div>
{%- endfor %}


Loading…
Cancel
Save