def test_recursion(self): tasks = [ Task('a id:1 after:3'), Task('b id:2 after:1'), Task('c id:3 after:2') ] results = self.search('', tasks) self.assertEqual(len(results), 0)
def test_more_parents(self): tasks = [Task('a id:1'), Task('b id:2'), Task('c after:1,2')] results = self.search('', tasks) self.assertEqual(len(results), 2) results = self.search('after:1', tasks) self.assertEqual(len(results), 1) self.assertIn('c', str(results[0]))
def setUp(self): self.sources = [ Source(FakeSource([Task('task id:30'), Task('task id:prefixed22')])), Source(FakeSource([Task('task id:41')])) ] self.sources[0].update_contexts_and_projects() self.sources[1].update_contexts_and_projects()
def test_all_parents_completed2(self): tasks = [ Task('x a id:1'), Task('x b id:2'), Task('c id:3 after:1 after:2') ] results = self.search('done:n', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['3'])
def testDueSorting(self): tasks = [ Task(utils.dehumanize_dates("due in a week due:+1w id:1")), Task(utils.dehumanize_dates("due tomorrow due:1 id:2")), Task(utils.dehumanize_dates("due in a month due:+1m id:3")), Task(utils.dehumanize_dates("(A) no due date id:4")) ] sortorder = utils.build_sort_order(common.DEFAULT_SORT_ORDER) tasks.sort(key=lambda t: utils.sort_fnc(t, sortorder)) self.assertEqual(tasks[0].attr_id, ['2']) self.assertEqual(tasks[1].attr_id, ['1']) self.assertEqual(tasks[2].attr_id, ['3']) self.assertEqual(tasks[3].attr_id, ['4'])
def testOverdueSorting(self): tasks = [ Task(utils.dehumanize_dates("(A) Important id:1")), Task(utils.dehumanize_dates("due tomorrow due:1 id:2")), Task(utils.dehumanize_dates("due yesterday due:-1 id:3")), Task(utils.dehumanize_dates("Not relevant id:4")) ] sortorder = utils.build_sort_order(common.DEFAULT_SORT_ORDER) tasks.sort(key=lambda t: utils.sort_fnc(t, sortorder)) self.assertEqual(tasks[0].attr_id, ['3']) self.assertEqual(tasks[1].attr_id, ['2']) self.assertEqual(tasks[2].attr_id, ['1']) self.assertEqual(tasks[3].attr_id, ['4'])
def test_update_spent(self): then = (datetime.datetime.now() - datetime.timedelta(minutes=10)).strftime(utils.DATETIME_FMT) task = Task(f'Something spent:1h10m tracking:{then}') self.assertTrue(utils.update_spent(task)) self.assertEqual(task.attributes, {'spent': ['1h20m']})
def test_hide_after(self): tasks = [Task('a id:1'), Task('b id:2 after:1')] results = self.search('', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['1'])
def test_show_all(self): tasks = [Task('a id:1'), Task('b id:2 after:1')] results = self.search('after:', tasks) self.assertEqual(len(results), 2)
def test_no_match_not(self): tasks = [Task('a id:1')] results = self.search('not:file:nope', tasks) self.assertEqual(len(results), 1)
def test_match(self): tasks = [Task('a id:1')] results = self.search('file:test', tasks) self.assertEqual(len(results), 1)
def test_ids(self): tasks = [Task('a id:1'), Task('b id:2 ref:1')] results = self.search('id:1,2', tasks) self.assertEqual(len(results), 2)
def test_after_search(self): tasks = [Task('x a id:1'), Task('t id:2 after:1')] results = self.search('ref:1', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['2'])
def test_decimals(self): sources = [Source(FakeSource([Task('task id:9'), Task('task id:12')]))] sources[0].update_contexts_and_projects() nextid = utils.new_task_id(sources) self.assertEqual(nextid, '13')
def test_has_no_id(self): tasks = [Task('a id:1'), Task('b')] results = self.search('-id:', tasks) self.assertEqual(len(results), 1) self.assertEqual(str(results[0]), 'b')
def test_has_id(self): tasks = [Task('a id:1'), Task('b')] results = self.search('id:', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['1'])
def test_not_ids2(self): tasks = [Task('a id:1'), Task('b id:2 ref:1')] results = self.search('-id:1 -id:2', tasks) self.assertEqual(len(results), 0)
def test_not_id(self): tasks = [Task('a id:1'), Task('b id:2 ref:1')] results = self.search('-id:1', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['2'])
def test_parent_completed(self): tasks = [Task('x a id:1'), Task('b after:1 id:test')] results = self.search('done:n', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['test'])
def test_ref_not_there(self): tasks = [Task('a id:1'), Task('b id:2 ref:1')] results = self.search('ref:2', tasks) self.assertEqual(len(results), 0)
def test_ref_multiple2(self): tasks = [Task('a id:1'), Task('b id:2 ref:1 ref:4')] results = self.search('ref:4', tasks) self.assertEqual(len(results), 1) self.assertEqual(results[0].attr_id, ['2'])