diff --git a/hyde/ext/plugins/grouper.py b/hyde/ext/plugins/grouper.py index efe27a6..42af543 100644 --- a/hyde/ext/plugins/grouper.py +++ b/hyde/ext/plugins/grouper.py @@ -58,7 +58,7 @@ class Group(Expando): that belong to this group. """ for group in group.walk_groups(): - for resource in group.list_resources(node): + for resource in group.walk_resources_in_node(node): yield resource @staticmethod @@ -69,7 +69,7 @@ class Group(Expando): """ walker = group.walk_groups() for g in walker: - lister = g.list_resources(node) + lister = g.walk_resources_in_node(node) for r in lister: yield g break; @@ -84,9 +84,9 @@ class Group(Expando): for child in group.walk_groups(): yield child - def list_resources(self, node): + def walk_resources_in_node(self, node): """ - Lists the resources in the given node + Walks the resources in the given node sorted based on sorter configuration in this group. """ diff --git a/hyde/tests/ext/test_grouper.py b/hyde/tests/ext/test_grouper.py index 49931c5..916f39b 100644 --- a/hyde/tests/ext/test_grouper.py +++ b/hyde/tests/ext/test_grouper.py @@ -16,98 +16,114 @@ import yaml TEST_SITE = File(__file__).parent.parent.child_folder('_test') -class TestGrouper(object): +class TestGrouperSingleLevel(object): def setUp(self): TEST_SITE.make() TEST_SITE.parent.child_folder( 'sites/test_grouper').copy_contents_to(TEST_SITE) - def tearDown(self): - TEST_SITE.delete() - - def test_walk_resources_sorted_with_grouping_one_level(self): - s = Site(TEST_SITE) + self.s = Site(TEST_SITE) cfg = """ nodemeta: meta.yaml plugins: - - hyde.ext.meta.MetaPlugin - - hyde.ext.sorter.SorterPlugin - - hyde.ext.grouper.GrouperPlugin + - hyde.ext.meta.MetaPlugin + - hyde.ext.sorter.SorterPlugin + - hyde.ext.grouper.GrouperPlugin sorter: - kind: - attr: - - source_file.kind - filters: - is_processable: True + kind: + attr: + - source_file.kind + filters: + is_processable: True grouper: - section: - description: Sections in the site - sorter: kind - groups: - - - name: start - description: Getting Started - - - name: plugins - description: Plugins + section: + description: Sections in the site + sorter: kind + groups: + - + name: start + description: Getting Started + - + name: plugins + description: Plugins """ - s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) - s.load() - MetaPlugin(s).begin_site() - SorterPlugin(s).begin_site() - GrouperPlugin(s).begin_site() - - print [resource.name for resource in s.content.walk_resources_sorted_by_kind()] - groups = dict([(g.name, g) for g in s.grouper['section'].groups]) + self.s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) + self.s.load() + MetaPlugin(self.s).begin_site() + SorterPlugin(self.s).begin_site() + GrouperPlugin(self.s).begin_site() + + def tearDown(self): + TEST_SITE.delete() + + def test_site_grouper_groups(self): + + groups = dict([(g.name, g) for g in self.s.grouper['section'].groups]) assert len(groups) == 2 assert 'start' in groups assert 'plugins' in groups - - groups = dict([(g.name, g) for g in s.grouper['section'].walk_groups()]) + + def test_site_grouper_walk_groups(self): + + groups = dict([(g.name, g) for g in self.s.grouper['section'].walk_groups()]) assert len(groups) == 3 assert 'section' in groups assert 'start' in groups assert 'plugins' in groups - - assert hasattr(s.content, 'walk_section_groups') - groups = dict([(g.name, g) for g in s.content.walk_section_groups()]) + + def test_walk_section_groups(self): + + assert hasattr(self.s.content, 'walk_section_groups') + groups = dict([(g.name, g) for g in self.s.content.walk_section_groups()]) assert len(groups) == 2 assert 'start' in groups assert 'plugins' in groups - assert hasattr(s.content, 'walk_resources_grouped_by_section') - - resources = [resource.name for resource in s.content.walk_resources_grouped_by_section()] - + def test_walk_start_groups(self): + + assert hasattr(self.s.content, 'walk_start_groups') + groups = dict([(g.name, g) for g in self.s.content.walk_start_groups()]) + assert len(groups) == 1 + assert 'start' in groups + + def test_walk_plugins_groups(self): + + assert hasattr(self.s.content, 'walk_plugins_groups') + groups = dict([(g.name, g) for g in self.s.content.walk_plugins_groups()]) + assert len(groups) == 1 + assert 'plugins' in groups + + def test_walk_section_resources(self): + + assert hasattr(self.s.content, 'walk_resources_grouped_by_section') + + resources = [resource.name for resource in self.s.content.walk_resources_grouped_by_section()] assert len(resources) == 5 + assert 'installation.html' in resources + assert 'overview.html' in resources + assert 'templating.html' in resources + assert 'plugins.html' in resources + assert 'tags.html' in resources + + def test_walk_start_resources(self): + + assert hasattr(self.s.content, 'walk_resources_grouped_by_start') + + start_resources = [resource.name for resource in self.s.content.walk_resources_grouped_by_start()] + assert len(start_resources) == 3 + assert 'installation.html' in start_resources + assert 'overview.html' in start_resources + assert 'templating.html' in start_resources + + def test_walk_plugins_resources(self): + + assert hasattr(self.s.content, 'walk_resources_grouped_by_plugins') + + plugin_resources = [resource.name for resource in self.s.content.walk_resources_grouped_by_plugins()] + assert len(plugin_resources) == 2 + assert 'plugins.html' in plugin_resources + assert 'tags.html' in plugin_resources - # assert hasattr(s, 'sectional') - # assert hasattr(s.sectional, 'groups') - # assert len(s.sectional.groups) == 2 - # - # groups = dict([(g.name, g) for g in s.sectional.groups]) - # - # assert 'start' in groups - # assert 'plugins' in groups - # - # start = groups['start'] - # assert hasattr(start, 'resources') - # start_resources = [resource.name for resource in - # start.resources if resource.is_processable] - # assert len(start_resources) == 3 - # assert 'installation.html' in start_resources - # assert 'overview.html' in start_resources - # assert 'templating.html' in start_resources - # - # plugin = groups['plugins'] - # assert hasattr(plugin, 'resources') - # plugin_resources = [resource.name for resource in - # plugin.resources if resource.is_processable] - # assert len(plugin_resources) == 2 - # assert 'plugins.html' in plugin_resources - # assert 'tags.html' in plugin_resources - # - # \ No newline at end of file