def test_sort_children(self): hc = HierarchyCount() hc.add("cooking/indian") hc.add("cooking/italian") hc.add("reading/history") hc.add("") hc.sort(reverse=True) self.assertEquals("reading", hc.children[0].category) self.assertEquals("cooking", hc.children[1].category)
class ArchiveProcessor(SummaryProcessor): """Subclass of SummaryProcessor which counts archives under a root""" def __init__(self, root=''): super(ArchiveProcessor, self).__init__(root, '', cfg('YAWT_ARCHIVE_COUNT_FILE')) def _init_summary(self): self.summary = HierarchyCount() def on_visit_article(self, article): datefield = current_app.config['YAWT_ARCHIVE_DATEFIELD'] date = getattr(article.info, datefield) datestring = _date_hierarchy(date) self.summary.add(datestring) def unvisit(self, name): create_time = _fetch_date_for_name(name) if create_time: datestring = _date_hierarchy(create_time) self.summary.remove(datestring) def on_post_walk(self): self.summary.sort(reverse=True) super(ArchiveProcessor, self).on_post_walk()