def __init__(self, entry): self.header = entry.split('\n')[0] self.contents = entry.replace(self.header + '\n', '') #parsedate accepts YYYY MM without DD, avoid errors try: self.date = date(*parse_date(self.header)) except ValueError as e: logging.warning('Skipping ValueError for date: %s', e)
def _parse_task(self, text, open=True): level = self._depth if level > 0: level -= 1 # first list level should be same as level of line items in para parent_level, parent, parent_children = self._stack[-1] # Get prio prio = text.count('!') if prio == 0: prio = parent[2] # default to parent prio # Get due date due = _NO_DATE datematch = _date_re.search(text) # first match if datematch: date = parse_date(datematch.group(0)) if date: due = '%04i-%02i-%02i' % date # (y, m, d) if due == _NO_DATE: due = parent[3] # default to parent date (or default for root) # Find tags tags = set(_tag_re.findall(text)) if self._intasklist and self._tasklist_tags: tags |= self._tasklist_tags tags |= parent[4] # add parent tags # Check actionable if not parent[1]: # default parent not actionable actionable = False elif any(t.lower() in self.nonactionable_tags for t in tags): actionable = False elif self._matches_next_label(text) and parent_children: previous = parent_children[-1] actionable = not previous[0] # previous task not open else: actionable = True # Parents are not closed if it has open child items if self._depth > 0 and open: for l, t, c in self._stack[1:]: t[0] = True # And finally add to stack task = [open, actionable, prio, due, tags, text] children = [] parent_children.append((task, children)) if self._depth > 0: # (don't add paragraph level items to the stack) self._stack.append((level, task, children))
def _parse_task(self, text, open=True): level = self._depth if level > 0: level -= 1 # first list level should be same as level of line items in para parent_level, parent, parent_children = self._stack[-1] # Get prio prio = text.count('!') if prio == 0: prio = parent[2] # default to parent prio # Get due date due = _NO_DATE datematch = _date_re.search(text) # first match if datematch: date = parse_date(datematch.group(0)) if date: due = '%04i-%02i-%02i' % date # (y, m, d) if due == _NO_DATE: due = parent[3] # default to parent date (or default for root) # Find tags tags = set(_tag_re.findall(text)) if self._intasklist and self._tasklist_tags: tags |= self._tasklist_tags tags |= parent[4] # add parent tags # Check actionable if not parent[1]: # default parent not actionable actionable = False elif any(t.lower() in self.nonactionable_tags for t in tags): actionable = False elif self._matches_next_label(text) and parent_children: previous = parent_children[-1][0] actionable = not previous[0] # previous task not open else: actionable = True # Parents are not closed if it has open child items if self._depth > 0 and open: for l, t, c in self._stack[1:]: t[0] = True # And finally add to stack task = [open, actionable, prio, due, tags, text] children = [] parent_children.append((task, children)) if self._depth > 0: # (don't add paragraph level items to the stack) self._stack.append((level, task, children))
def testLabelledCheckboxes(self): mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('TODO: test heading with label'), []), (t('A'), []), (t('B'), []), (t('C'), []), (t('FIXME: dus'), []), # this time does not inherit due-date from non-task: (t('TODO: BAR !!!', prio=3), []), (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('A', tags='someday'), []), (t('B', tags='someday'), [ (t('B-1', tags='someday'), []), ]), (t('C', tags='someday'), []), (t('main task', tags='home'), [ (t('do this', open=False, tags='home'), []), (t('Next: do that', tags='home'), []), (t('Next: do something else', tags='home'), []), ]), ] tree = WikiParser().parse(WIKI_TEXT) tb = TokenBuilder() tree.visit(tb) tokens = tb.tokens testTokenStream(tokens) parser = TaskParser(all_checkboxes=False) with tests.LoggingFilter('zim.plugins.tasklist', 'Invalid date format'): tasks = parser.parse(tokens) #~ import pprint; pprint.pprint(tasks) self.assertEqual(tasks, wanted)
def _parse_task(self, text, open=True, tags=None, actionable=True, defaultdate=None, defaultprio=None, tasks=None): # # Note: do not modify text here, keep it as is, any cleanup is done by the widget prio = text.count('!') if defaultprio and prio == 0: prio = defaultprio if not tags: tags = [] else: # ensure we don't mutate the parent's tags list tags = list(tags) tags += _tag_re.findall(text) datematch = _date_re.search(text) # first match if datematch: mydate = parse_date(datematch.group(0)) if mydate: date = '%04i-%02i-%02i' % mydate # (y, m, d) else: date = _NO_DATE else: date = _NO_DATE if defaultdate and date == _NO_DATE: date = defaultdate if actionable: if any(t.lower().strip('@') in self.nonactionble_tags for t in tags): actionable = False elif self.next_label_re.match(text): if tasks and tasks[-1][0][0]: # previous task still open actionable = False # else parent was non-actionable already, so stay non-actionable tags = ','.join(t.strip('@') for t in tags) return [open, actionable, prio, date, tags, text]
def testParsing(self): klass = PluginManager.get_plugin_class('tasklist') plugin = klass() notebook = tests.new_notebook() plugin.extend(notebook.index) index_ext = plugin.get_extension(IndexExtension) self.assertIsNotNone(index_ext) # Test correctnest of parsing NO_DATE = '9999' def extract_tasks(text): # Returns a nested list of tuples, where each node is # like "(TASK, [CHILD, ...]) where each task (and child) # is a tuple like (open, actionable, prio, due, description) parser = zim.formats.get_format('wiki').Parser() tree = parser.parse(text) origtree = tree.tostring() #~ print 'TREE', origtree tasks = index_ext._extract_tasks(tree) self.assertEqual(tree.tostring(), origtree) # extract should not modify the tree return tasks def t(label, open=True, due=NO_DATE, prio=0, tags='', actionable=True): # Generate a task tuple # (open, actionable, prio, due, tags, description) if tags: tags = set(unicode(tags).split(',')) else: tags = set() return [open, actionable, prio, due, tags, unicode(label)] # Note that this same text is in the test notebook # so it gets run through the index as well - keep in sync text = '''\ Try all kind of combos - see if the parser trips TODO: [ ] A [ ] B [ ] C [ ] D [ ] E FIXME: dus ~~FIXME:~~ foo [ ] Simple [ ] List [ ] List with [ ] Nested items [*] Some are done [*] Done but with open child [x] Others not [ ] FOOOOO [ ] Bar [ ] And then there are @tags [ ] Next: And due dates [ ] Date [d: 11/12] [ ] Date [d: 11/12/2012] [ ] TODO: BAR !!! TODO @home: [ ] Some more tasks !!! [ ] Foo ! * some sub item * some other item [ ] Bar TODO: dus FIXME: jaja - TODO !! @FIXME ~~TODO~~: Ignore this one - it is strike out * TODO: dus - list item * FIXME: jaja - TODO !! @FIXME - list item * ~~TODO~~: Ignore this one - it is strike out - list item * Bullet list * With tasks as sub items [ ] Sub item bullets * dus 1. Numbered list 2. With tasks as sub items [ ] Sub item numbered 3. dus Test task inheritance: [ ] Main @tag1 @tag2 ! [*] Sub1 [ ] Sub2 @tag3 !!!! [*] Sub2-1 [*] Sub2-2 @tag4 [ ] Sub2-3 [ ] Sub3 TODO: @someday [ ] A [ ] B [ ] B-1 [ ] C TODO @home [ ] main task [x] do this [ ] Next: do that [ ] Next: do something else ''' mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('D'), []), (t('E'), []), (t('FIXME: dus'), []), (t('Simple'), []), (t('List'), []), (t('List with'), [ (t('Nested items'), []), (t('Some are done', open=False), []), (t('Done but with open child', open=True), [ (t('Others not', open=False), []), (t('FOOOOO'), []), ]), ]), (t('Bar'), []), (t('And then there are @tags', tags='tags'), []), (t('Next: And due dates', actionable=False), []), (t('Date [d: 11/12]', due=mydate), []), (t('Date [d: 11/12/2012]', due='2012-12-11'), [ (t('TODO: BAR !!!', prio=3, due='2012-12-11'), []), # due date is inherited ]), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('Sub item bullets'), []), (t('Sub item numbered'), []), (t('Main @tag1 @tag2 !', prio=1, tags='tag1,tag2'), [ (t('Sub1', prio=1, open=False, tags='tag1,tag2'), []), (t('Sub2 @tag3 !!!!', prio=4, tags='tag1,tag2,tag3'), [ (t('Sub2-1', prio=4, open=False, tags='tag1,tag2,tag3'), []), (t('Sub2-2 @tag4', prio=4, open=False, tags='tag1,tag2,tag3,tag4'), []), (t('Sub2-3', prio=4, tags='tag1,tag2,tag3'), []), ]), (t('Sub3', prio=1, tags='tag1,tag2'), []), ]), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), (t('main task', tags='home'), [ (t('do this', open=False, tags='home'), []), (t('Next: do that', tags='home'), []), (t('Next: do something else', tags='home', actionable=False), []), ]) ] plugin.preferences['nonactionable_tags'] = '@someday, @maybe' index_ext._set_preferences() tasks = extract_tasks(text) self.assertEqual(tasks, wanted) plugin.preferences['all_checkboxes'] = False wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('FIXME: dus'), []), (t('Next: And due dates', actionable=False), []), (t('TODO: BAR !!!', prio=3), []), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), (t('main task', tags='home'), [ (t('do this', open=False, tags='home'), []), (t('Next: do that', tags='home'), []), (t('Next: do something else', tags='home', actionable=False), []), ]) ] tasks = extract_tasks(text) self.assertEqual(tasks, wanted)
def testLabelledCheckboxes(self): from zim.plugins.tasklist.indexer import TaskParser from zim.parsing import parse_date NO_DATE = '9999' def t(desc, open=True, start=0, due=NO_DATE, prio=0, tags=''): # Generate a task tuple # 0:open, 1:prio, 2:start, 3:due, 4:tags, 5:desc if tags: tags = set(str(tags).split(',')) else: tags = set() return [open, prio, start, due, tags, str(desc)] mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('TODO: test heading with label'), []), (t('A'), []), (t('B'), []), (t('C'), []), (t('FIXME: dus'), []), # this time does not inherit due-date from non-task: (t('TODO: BAR !!!', prio=3), []), (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('A', tags='someday'), []), (t('B', tags='someday'), [ (t('B-1', tags='someday'), []), ]), (t('C', tags='someday'), []), (t('main task', tags='home'), [ (t('do this', open=False, tags='home'), []), (t('Next: do that', tags='home'), []), (t('Next: do something else', tags='home'), []), ]), ] tree = WikiParser().parse(WIKI_TEXT) tb = TokenBuilder() tree.visit(tb) tokens = tb.tokens testTokenStream(tokens) parser = TaskParser(all_checkboxes=False) with tests.LoggingFilter('zim.plugins.tasklist', 'Invalid date format'): tasks = parser.parse(tokens) #~ import pprint; pprint.pprint(tasks) self.assertEqual(tasks, wanted)
def testAllCheckboxes(self): from zim.plugins.tasklist.indexer import TaskParser from zim.parsing import parse_date NO_DATE = '9999' def t(desc, open=True, start=0, due=NO_DATE, prio=0, tags=''): # Generate a task tuple # 0:open, 1:prio, 2:start, 3:due, 4:tags, 5:desc if tags: tags = set(str(tags).split(',')) else: tags = set() return [open, prio, start, due, tags, str(desc)] mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('TODO: test heading with label'), []), (t('A'), []), (t('B'), []), (t('C'), []), (t('D'), []), (t('E'), []), (t('FIXME: dus'), []), (t('Simple'), []), (t('List'), []), (t('List with'), [ (t('Nested items'), []), (t('Some are done', open=False), []), (t('Done but with open child', open=True), [ (t('Others not', open=False), []), (t('FOOOOO'), []), ]), ]), (t('Bar'), []), (t('And then there are @tags', tags='tags'), []), (t('Next: And due dates'), []), (t('Date [d: 11/12]', due=mydate), []), ( t('Date [d: 11/12/2012]', due='2012-12-11'), [ (t('TODO: BAR !!!', prio=3, due='2012-12-11'), []), # due date is inherited ]), (t('Date <2012-03-27 >2012-03-01', due='2012-03-27', start='2012-03-01'), []), (t('Date < wk1213.3', due='2012-03-28'), []), (t('Date < wk1213.3! with punctuation', due='2012-03-28', prio=1), []), (t('Not a date < wk1213.8'), []), (t('Not a date < wk1213foooooo'), []), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('Sub item bullets'), []), (t('Sub item numbered'), []), (t('Main @tag1 @tag2 !', prio=1, tags='tag1,tag2'), [ (t('Sub1', prio=1, open=False, tags='tag1,tag2'), []), (t('Sub2 @tag3 !!!!', prio=4, tags='tag1,tag2,tag3'), [ (t('Sub2-1', prio=4, open=False, tags='tag1,tag2,tag3'), []), (t('Sub2-2 @tag4', prio=4, open=False, tags='tag1,tag2,tag3,tag4'), []), (t('Sub2-3', prio=4, tags='tag1,tag2,tag3'), []), ]), (t('Sub3', prio=1, tags='tag1,tag2'), []), ]), (t('A', tags='someday'), []), (t('B', tags='someday'), [ (t('B-1', tags='someday'), []), ]), (t('C', tags='someday'), []), (t('main task', tags='home'), [ (t('do this', open=False, tags='home'), []), (t('Next: do that', tags='home'), []), (t('Next: do something else', tags='home'), []), ]), (t('Closed parent task', open=True), [ (t('With open child'), []), (t('Must be open as well to show up in list'), []), ]), (t('Closed parent task', open=False), [ (t('With closed children', open=False), []), (t('Should not', open=False), []), ]), ] tree = WikiParser().parse(WIKI_TEXT) tb = TokenBuilder() tree.visit(tb) tokens = tb.tokens testTokenStream(tokens) parser = TaskParser() with tests.LoggingFilter('zim.plugins.tasklist', 'Invalid date format'): tasks = parser.parse(tokens) #~ import pprint; pprint.pprint(tasks) self.assertEqual(tasks, wanted)
def testParsing(self): klass = zim.plugins.get_plugin_class('tasklist') plugin = klass() notebook = tests.new_notebook() plugin.extend(notebook.index) index_ext = plugin.get_extension(IndexExtension) self.assertIsNotNone(index_ext) # Test correctnest of parsing NO_DATE = '9999' def extract_tasks(text): # Returns a nested list of tuples, where each node is # like "(TASK, [CHILD, ...]) where each task (and child) # is a tuple like (open, actionable, prio, due, description) parser = zim.formats.get_format('wiki').Parser() tree = parser.parse(text) origtree = tree.tostring() #~ print 'TREE', origtree tasks = index_ext._extract_tasks(tree) self.assertEqual(tree.tostring(), origtree) # extract should not modify the tree return tasks def t(label, open=True, due=NO_DATE, prio=0, tags='', actionable=True): # Generate a task tuple # (open, actionable, prio, due, tags, description) if tags: tags = set(unicode(tags).split(',')) else: tags = set() return [open, actionable, prio, due, tags, unicode(label)] # Note that this same text is in the test notebook # so it gets run through the index as well - keep in sync text = '''\ Try all kind of combos - see if the parser trips TODO: [ ] A [ ] B [ ] C [ ] D [ ] E FIXME: dus ~~FIXME:~~ foo [ ] Simple [ ] List [ ] List with [ ] Nested items [*] Some are done [*] Done but with open child [x] Others not [ ] FOOOOO [ ] Bar [ ] And then there are @tags [ ] And due dates [ ] Date [d: 11/12] [ ] Date [d: 11/12/2012] [ ] TODO: BAR !!! TODO @home: [ ] Some more tasks !!! [ ] Foo ! * some sub item * some other item [ ] Bar TODO: dus FIXME: jaja - TODO !! @FIXME ~~TODO~~: Ignore this one - it is strike out * TODO: dus - list item * FIXME: jaja - TODO !! @FIXME - list item * ~~TODO~~: Ignore this one - it is strike out - list item * Bullet list * With tasks as sub items [ ] Sub item bullets * dus 1. Numbered list 2. With tasks as sub items [ ] Sub item numbered 3. dus Test task inheritance: [ ] Main @tag1 @tag2 ! [*] Sub1 [ ] Sub2 @tag3 !!!! [*] Sub2-1 [*] Sub2-2 @tag4 [ ] Sub2-3 [ ] Sub3 TODO: @someday [ ] A [ ] B [ ] B-1 [ ] C ''' mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('D'), []), (t('E'), []), (t('FIXME: dus'), []), (t('Simple'), []), (t('List'), []), (t('List with'), [ (t('Nested items'), []), (t('Some are done', open=False), []), (t('Done but with open child', open=True), [ (t('Others not', open=False), []), (t('FOOOOO'), []), ]), ]), (t('Bar'), []), (t('And then there are @tags', tags='tags'), []), (t('And due dates'), []), (t('Date [d: 11/12]', due=mydate), []), ( t('Date [d: 11/12/2012]', due='2012-12-11'), [ (t('TODO: BAR !!!', prio=3, due='2012-12-11'), []), # due date is inherited ]), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('Sub item bullets'), []), (t('Sub item numbered'), []), (t('Main @tag1 @tag2 !', prio=1, tags='tag1,tag2'), [ (t('Sub1', prio=1, open=False, tags='tag1,tag2'), []), (t('Sub2 @tag3 !!!!', prio=4, tags='tag1,tag2,tag3'), [ (t('Sub2-1', prio=4, open=False, tags='tag1,tag2,tag3'), []), (t('Sub2-2 @tag4', prio=4, open=False, tags='tag1,tag2,tag3,tag4'), []), (t('Sub2-3', prio=4, tags='tag1,tag2,tag3'), []), ]), (t('Sub3', prio=1, tags='tag1,tag2'), []), ]), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), ] plugin.preferences['nonactionable_tags'] = '@someday, @maybe' index_ext._set_preferences() tasks = extract_tasks(text) self.assertEqual(tasks, wanted) plugin.preferences['all_checkboxes'] = False wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('FIXME: dus'), []), (t('TODO: BAR !!!', prio=3), []), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), ] tasks = extract_tasks(text) self.assertEqual(tasks, wanted)
def testIndexing(self): '''Check indexing of tasklist plugin''' klass = zim.plugins.get_plugin('tasklist') ui = MockUI() plugin = klass(ui) # Test indexing based on index signals ui.notebook.index.flush() ui.notebook.index.update() self.assertTrue(plugin.db_initialized) tasks = list(plugin.list_tasks()) self.assertTrue(len(tasks) > 5) for task in tasks: path = plugin.get_path(task) self.assertTrue(not path is None) # Test correctnest of parsing NO_DATE = '9999' def extract_tasks(text): # Returns a nested list of tuples, where each node is # like "(TASK, [CHILD, ...]) where each task (and child) # is a tuple like (open, actionable, prio, due, description) parser = zim.formats.get_format('wiki').Parser() tree = parser.parse(text) origtree = tree.tostring() tasks = plugin._extract_tasks(tree) self.assertEqual(tree.tostring(), origtree) # extract should not modify the tree return tasks def t(label, open=True, due=NO_DATE, prio=0, tags='', actionable=True): # Generate a task tuple # (open, actionable, prio, due, tags, description) return [open, actionable, prio, due, tags, label] # Note that this same text is in the test notebook # so it gets run through the index as well - keep in sync text = '''\ Try all kind of combos - see if the parser trips TODO: [ ] A [ ] B [ ] C [ ] D [ ] E FIXME: dus ~~FIXME:~~ foo [ ] Simple [ ] List [ ] List with [ ] Nested items [*] Some are done [*] Done but with open child [x] Others not [ ] FOOOOO [ ] Bar [ ] And then there are @tags [ ] And due dates [ ] Date [d: 11/12] [ ] Date [d: 11/12/2012] [ ] TODO: BAR !!! TODO @home: [ ] Some more tasks !!! [ ] Foo ! * some sub item * some other item [ ] Bar TODO: dus FIXME: jaja - TODO !! @FIXME ~~TODO~~: Ignore this one - it is strike out * TODO: dus - list item * FIXME: jaja - TODO !! @FIXME - list item * ~~TODO~~: Ignore this one - it is strike out - list item * Bullet list * With tasks as sub items [ ] Sub item bullets * dus 1. Numbered list 2. With tasks as sub items [ ] Sub item numbered 3. dus Test task inheritance: [ ] Main @tag1 @tag2 ! [*] Sub1 [ ] Sub2 @tag3 !!!! [*] Sub2-1 [*] Sub2-2 @tag4 [ ] Sub2-3 [ ] Sub3 TODO: @someday [ ] A [ ] B [ ] B-1 [ ] C ''' mydate = '%04i-%02i-%02i' % parse_date('11/12') wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('D'), []), (t('E'), []), (t('FIXME: dus'), []), (t('Simple'), []), (t('List'), []), (t('List with'), [ (t('Nested items'), []), (t('Some are done', open=False), []), (t('Done but with open child', open=True), [ (t('Others not', open=False), []), (t('FOOOOO'), []), ]), ]), (t('Bar'), []), (t('And then there are @tags', tags='tags'), []), (t('And due dates'), []), (t('Date [d: 11/12]', due=mydate), []), (t('Date [d: 11/12/2012]', due='2012-12-11'), [ (t('TODO: BAR !!!', prio=3, due='2012-12-11'), []), # due date is inherited ]), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('Sub item bullets'), []), (t('Sub item numbered'), []), (t('Main @tag1 @tag2 !', prio=1, tags='tag1,tag2'), [ (t('Sub1', prio=1, open=False, tags='tag1,tag2'), []), (t('Sub2 @tag3 !!!!', prio=4, tags='tag1,tag2,tag3'), [ (t('Sub2-1', prio=4, open=False, tags='tag1,tag2,tag3'), []), (t('Sub2-2 @tag4', prio=4, open=False, tags='tag1,tag2,tag3,tag4'), []), (t('Sub2-3', prio=4, tags='tag1,tag2,tag3'), []), ]), (t('Sub3', prio=1, tags='tag1,tag2'), []), ]), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), ] plugin.preferences['nonactionable_tags'] = '@someday, @maybe' plugin.do_preferences_changed() tasks = extract_tasks(text) self.assertEqual(tasks, wanted) plugin.preferences['all_checkboxes'] = False wanted = [ (t('A'), []), (t('B'), []), (t('C'), []), (t('FIXME: dus'), []), (t('TODO: BAR !!!', prio=3), []), # this list inherits the @home tag - and inherits prio (t('Some more tasks !!!', prio=3, tags='home'), [ (t('Foo !', prio=1, tags='home'), []), (t('Bar', prio=3, tags='home'), []), ]), (t('TODO: dus'), []), (t('FIXME: jaja - TODO !! @FIXME', prio=2, tags='FIXME'), []), (t('TODO: dus - list item'), []), (t('FIXME: jaja - TODO !! @FIXME - list item', prio=2, tags='FIXME'), []), (t('A', tags='someday', actionable=False), []), (t('B', tags='someday', actionable=False), [ (t('B-1', tags='someday', actionable=False), []), ]), (t('C', tags='someday', actionable=False), []), ] tasks = extract_tasks(text) self.assertEqual(tasks, wanted)
def testIndexing(self): """Check indexing of tasklist plugin""" klass = zim.plugins.get_plugin("tasklist") ui = MockUI() plugin = klass(ui) # Test indexing based on index signals ui.notebook.index.flush() ui.notebook.index.update() self.assertTrue(plugin.db_initialized) tasks = list(plugin.list_tasks()) self.assertTrue(len(tasks) > 5) for task in tasks: path = plugin.get_path(task) self.assertTrue(not path is None) # Test correctnest of parsing NO_DATE = "9999" def extract_tasks(text): # Returns a nested list of tuples, where each node is # like "(TASK, [CHILD, ...]) where each task (and child) # is a tuple like (open, actionable, prio, due, description) parser = zim.formats.get_format("wiki").Parser() tree = parser.parse(text) origtree = tree.tostring() tasks = plugin._extract_tasks(tree) self.assertEqual(tree.tostring(), origtree) # extract should not modify the tree return tasks def t(label, open=True, due=NO_DATE, prio=0, tags="", actionable=True): # Generate a task tuple # (open, actionable, prio, due, tags, description) return [open, actionable, prio, due, tags, label] # Note that this same text is in the test notebook # so it gets run through the index as well - keep in sync text = """\ Try all kind of combos - see if the parser trips TODO: this is a test FIXME: now ~~FIXME:~~ Ignore this one - it is strike out **FIXME**: now **FIXME:** now __FIXME:__ now TODO @home: TODO: dus FIXME: jaja ~~TODO~~: Ignore this one - it is strike out * TODO: dus - list item * FIXME: jaja - TODO !! @FIXME - list item * ~~TODO~~: Ignore this one - it is strike out - list item """ mydate = "%04i-%02i-%02i" % parse_date("11/12") wanted = [ (t("A"), []), (t("B"), []), (t("C"), []), (t("D"), []), (t("E"), []), (t("FIXME: dus"), []), (t("Simple"), []), (t("List"), []), ( t("List with"), [ (t("Nested items"), []), (t("Some are done", open=False), []), (t("Done but with open child", open=True), [(t("Others not", open=False), []), (t("FOOOOO"), [])]), ], ), (t("Bar"), []), (t("And then there are @tags", tags="tags"), []), (t("And due dates"), []), (t("Date [d: 11/12]", due=mydate), []), ( t("Date [d: 11/12/2012]", due="2012-12-11"), [ (t("TODO: BAR !!!", prio=3, due="2012-12-11"), []), # due date is inherited ], ), # this list inherits the @home tag - and inherits prio ( t("Some more tasks !!!", prio=3, tags="home"), [(t("Foo !", prio=1, tags="home"), []), (t("Bar", prio=3, tags="home"), [])], ), (t("TODO: dus"), []), (t("FIXME: jaja - TODO !! @FIXME", prio=2, tags="FIXME"), []), (t("TODO: dus - list item"), []), (t("FIXME: jaja - TODO !! @FIXME - list item", prio=2, tags="FIXME"), []), (t("Sub item bullets"), []), (t("Sub item numbered"), []), ( t("Main @tag1 @tag2 !", prio=1, tags="tag1,tag2"), [ (t("Sub1", prio=1, open=False, tags="tag1,tag2"), []), ( t("Sub2 @tag3 !!!!", prio=4, tags="tag1,tag2,tag3"), [ (t("Sub2-1", prio=4, open=False, tags="tag1,tag2,tag3"), []), (t("Sub2-2 @tag4", prio=4, open=False, tags="tag1,tag2,tag3,tag4"), []), (t("Sub2-3", prio=4, tags="tag1,tag2,tag3"), []), ], ), (t("Sub3", prio=1, tags="tag1,tag2"), []), ], ), (t("A", tags="someday", actionable=False), []), (t("B", tags="someday", actionable=False), [(t("B-1", tags="someday", actionable=False), [])]), (t("C", tags="someday", actionable=False), []), ] plugin.preferences["nonactionable_tags"] = "@someday, @maybe" plugin.do_preferences_changed() tasks = extract_tasks(text) self.assertEqual(tasks, wanted) plugin.preferences["all_checkboxes"] = False wanted = [ (t("A"), []), (t("B"), []), (t("C"), []), (t("FIXME: dus"), []), (t("TODO: BAR !!!", prio=3), []), # this list inherits the @home tag - and inherits prio ( t("Some more tasks !!!", prio=3, tags="home"), [(t("Foo !", prio=1, tags="home"), []), (t("Bar", prio=3, tags="home"), [])], ), (t("TODO: dus"), []), (t("FIXME: jaja - TODO !! @FIXME", prio=2, tags="FIXME"), []), (t("TODO: dus - list item"), []), (t("FIXME: jaja - TODO !! @FIXME - list item", prio=2, tags="FIXME"), []), (t("A", tags="someday", actionable=False), []), (t("B", tags="someday", actionable=False), [(t("B-1", tags="someday", actionable=False), [])]), (t("C", tags="someday", actionable=False), []), ] tasks = extract_tasks(text) self.assertEqual(tasks, wanted)