mirror of
https://github.com/topydo/topydo.git
synced 2024-05-20 13:58:33 +00:00
Compare commits
4 commits
24f1137329
...
33ec48ecac
Author | SHA1 | Date | |
---|---|---|---|
33ec48ecac | |||
f3dc108d58 | |||
5d7a742095 | |||
f007b1b5fd |
|
@ -1,4 +1,3 @@
|
|||
x 2014-10-19 Complete
|
||||
x 2014-10-20 Another one complete
|
||||
x Not complete
|
||||
(C) Active
|
||||
|
|
11
test/data/TodoListBiggerTest.txt
Normal file
11
test/data/TodoListBiggerTest.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
(C) Foo @Context2 Not@Context +Project1 Not+Project
|
||||
(D) Bar @Context1 +Project2
|
||||
(C) Baz @Context1 +Project1 key:value
|
||||
(C) Drink beer @ home
|
||||
|
||||
(C) 13 + 29 = 42
|
||||
Another Bar @Context3
|
||||
Different Foo +Project3
|
||||
Another Different Bar @Context3
|
||||
Different Another Bar Foo @Context3 +Project3
|
||||
Foo Bar @Context3 +Project3
|
|
@ -33,7 +33,7 @@ class ArchiveCommandTest(CommandTest):
|
|||
|
||||
self.assertTrue(todolist.dirty)
|
||||
self.assertTrue(archive.dirty)
|
||||
self.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active")
|
||||
self.assertEqual(todolist.print_todos(), "(C) Active")
|
||||
self.assertEqual(archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -39,6 +39,30 @@ class ListContextCommandTest(CommandTest):
|
|||
self.assertEqual(self.output, "Context1\nContext2\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_contexts_with_counts(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListContextCommand(["-c"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
|
||||
self.assertEqual(self.output, "2\tContext1\n1\tContext2\n4\tContext3\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_contexts_with_counts_sorted(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListContextCommand(["-c", "-s"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
|
||||
self.assertEqual(self.output, "1\tContext2\n2\tContext1\n4\tContext3\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_contexts_with_counts_sorted_inversely(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListContextCommand(["-c", "-S"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
|
||||
self.assertEqual(self.output, "4\tContext3\n2\tContext1\n1\tContext2\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_listcontext_name(self):
|
||||
name = ListContextCommand.name()
|
||||
|
||||
|
|
|
@ -41,6 +41,33 @@ class ListProjectCommandTest(CommandTest):
|
|||
self.assertEqual(self.output, "Project1\nProject2\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_projects_with_counts(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListProjectCommand(["-c"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
command.execute_post_archive_actions()
|
||||
|
||||
self.assertEqual(self.output, "2\tProject1\n1\tProject2\n3\tProject3\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_projects_with_counts_sorted(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListProjectCommand(["-c", "-s"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
command.execute_post_archive_actions()
|
||||
|
||||
self.assertEqual(self.output, "1\tProject2\n2\tProject1\n3\tProject3\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_projects_with_counts_sorted_inversely(self):
|
||||
todolist = load_file_to_todolist("test/data/TodoListBiggerTest.txt")
|
||||
command = ListProjectCommand(["-c", "-S"], todolist, self.out, self.error)
|
||||
command.execute()
|
||||
command.execute_post_archive_actions()
|
||||
|
||||
self.assertEqual(self.output, "3\tProject3\n2\tProject1\n1\tProject2\n")
|
||||
self.assertFalse(self.errors)
|
||||
|
||||
def test_listproject_name(self):
|
||||
name = ListProjectCommand.name()
|
||||
|
||||
|
|
68
test/test_parse.py
Normal file
68
test/test_parse.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Topydo - A todo.txt client written in Python.
|
||||
# Copyright (C) 2023 David Steele <dsteele@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import unittest
|
||||
|
||||
from topydo.lib.TodoParser import parse_line
|
||||
|
||||
complete_tasks = [
|
||||
"x 2023-08-12",
|
||||
"x 2023-08-12 ",
|
||||
"x 2023-08-12 2023-08-12",
|
||||
"x 2023-08-12 2023-08-12 ",
|
||||
"x 2023-08-12 2023-08-12 task text",
|
||||
"x 2023-08-12 2023-08-12 task text",
|
||||
"x 2023-08-12 task text",
|
||||
"x task text",
|
||||
"x ",
|
||||
]
|
||||
|
||||
incomplete_tasks = [
|
||||
"",
|
||||
" ",
|
||||
" x",
|
||||
" x ",
|
||||
"x",
|
||||
"incomplete task",
|
||||
]
|
||||
|
||||
|
||||
def gen_test(task, result):
|
||||
def test_fn(self):
|
||||
task_dict = parse_line(task)
|
||||
|
||||
self.assertEqual(task_dict["completed"], result, f'Failed "{task}"')
|
||||
|
||||
return test_fn
|
||||
|
||||
|
||||
def populate_tasks(cls):
|
||||
for i, task in enumerate(complete_tasks):
|
||||
setattr(cls, f"test_complete_{i}", gen_test(task, True))
|
||||
|
||||
for i, task in enumerate(incomplete_tasks):
|
||||
setattr(cls, f"test_incomplete_{i}", gen_test(task, False))
|
||||
|
||||
return cls
|
||||
|
||||
|
||||
@populate_tasks
|
||||
class ParseTodoTest(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
|
@ -229,12 +229,6 @@ class TodoBaseTester(TopydoTest):
|
|||
|
||||
self.assertFalse(todo.is_completed())
|
||||
|
||||
def test_completion3(self):
|
||||
""" A completed todo must start with an x followed by a date. """
|
||||
todo = TodoBase("x Not complete")
|
||||
|
||||
self.assertFalse(todo.is_completed())
|
||||
|
||||
def test_completion4(self):
|
||||
""" A completed todo must start with an x followed by a date. """
|
||||
todo = TodoBase("X 2014-06-14 Not complete")
|
||||
|
|
|
@ -25,12 +25,39 @@ class ListContextCommand(Command):
|
|||
super().__init__(
|
||||
p_args, p_todolist, p_out, p_err, p_prompt)
|
||||
|
||||
self.counts = False
|
||||
self.sort_by = 'name'
|
||||
|
||||
def _process_flags(self):
|
||||
flags, args = self.getopt("csS")
|
||||
for flag, _ in flags:
|
||||
if flag == "-c":
|
||||
self.counts = True
|
||||
elif flag == "-s":
|
||||
self.sort_by = 'counts'
|
||||
elif flag == "-S":
|
||||
self.sort_by = 'counts_inv'
|
||||
|
||||
def execute(self):
|
||||
if not super().execute():
|
||||
return False
|
||||
|
||||
for context in sorted(self.todolist.contexts(), key=lambda s: s.lower()):
|
||||
self.out(context)
|
||||
self._process_flags()
|
||||
|
||||
if self.counts:
|
||||
sorting_fns = {
|
||||
'name': lambda s: s[0].lower(),
|
||||
'counts': lambda s: s[1],
|
||||
'counts_inv': lambda s: -s[1]
|
||||
}
|
||||
|
||||
for context, c in sorted(self.todolist.contexts_counts().items(),
|
||||
key=sorting_fns[self.sort_by]):
|
||||
self.out("{}\t{}".format(c, context))
|
||||
else:
|
||||
for context in sorted(self.todolist.contexts(),
|
||||
key=lambda s: s.lower()):
|
||||
self.out(context)
|
||||
|
||||
def usage(self):
|
||||
return """Synopsis: lscon"""
|
||||
|
|
|
@ -25,12 +25,39 @@ class ListProjectCommand(Command):
|
|||
super().__init__(
|
||||
p_args, p_todolist, p_out, p_err, p_prompt)
|
||||
|
||||
self.counts = False
|
||||
self.sort_by = 'name'
|
||||
|
||||
def _process_flags(self):
|
||||
flags, args = self.getopt("csS")
|
||||
for flag, _ in flags:
|
||||
if flag == "-c":
|
||||
self.counts = True
|
||||
elif flag == "-s":
|
||||
self.sort_by = 'counts'
|
||||
elif flag == "-S":
|
||||
self.sort_by = 'counts_inv'
|
||||
|
||||
def execute(self):
|
||||
if not super().execute():
|
||||
return False
|
||||
|
||||
for project in sorted(self.todolist.projects(), key=lambda s: s.lower()):
|
||||
self.out(project)
|
||||
self._process_flags()
|
||||
|
||||
if self.counts:
|
||||
sorting_fns = {
|
||||
'name': lambda s: s[0].lower(),
|
||||
'counts': lambda s: s[1],
|
||||
'counts_inv': lambda s: -s[1]
|
||||
}
|
||||
|
||||
for project, c in sorted(self.todolist.projects_counts().items(),
|
||||
key=sorting_fns[self.sort_by]):
|
||||
self.out("{}\t{}".format(c, project))
|
||||
else:
|
||||
for project in sorted(self.todolist.projects(),
|
||||
key=lambda s: s.lower()):
|
||||
self.out(project)
|
||||
|
||||
def usage(self):
|
||||
return """Synopsis: lsprj"""
|
||||
|
|
|
@ -20,6 +20,7 @@ A list of todo items.
|
|||
|
||||
import math
|
||||
import re
|
||||
from collections import Counter
|
||||
from datetime import date
|
||||
|
||||
from topydo.lib import Filter
|
||||
|
@ -218,6 +219,18 @@ class TodoListBase(object):
|
|||
|
||||
return result
|
||||
|
||||
def projects_counts(self):
|
||||
""" Returns a dict of all projects in this list with their respective
|
||||
couts. """
|
||||
|
||||
result = Counter()
|
||||
for todo in self._todos:
|
||||
projects = todo.projects()
|
||||
for project in projects:
|
||||
result[project] += 1
|
||||
|
||||
return dict(result)
|
||||
|
||||
def contexts(self):
|
||||
""" Returns a set of all contexts in this list. """
|
||||
result = set()
|
||||
|
@ -227,6 +240,18 @@ class TodoListBase(object):
|
|||
|
||||
return result
|
||||
|
||||
def contexts_counts(self):
|
||||
""" Returns a dict of all contexts in this list with their respective
|
||||
counts. """
|
||||
result = Counter()
|
||||
for todo in self._todos:
|
||||
contexts = todo.contexts()
|
||||
for context in contexts:
|
||||
result[context] += 1
|
||||
|
||||
return dict(result)
|
||||
|
||||
|
||||
def view(self, p_sorter, p_filters):
|
||||
"""
|
||||
Constructs a view of the todo list.
|
||||
|
|
|
@ -26,7 +26,7 @@ from topydo.lib.Utils import date_string_to_date
|
|||
_DATE_MATCH = r'\d{4}-\d{2}-\d{2}'
|
||||
|
||||
_COMPLETED_HEAD_MATCH = re.compile(
|
||||
r'x ((?P<completionDate>' + _DATE_MATCH + ') )' + '((?P<creationDate>' +
|
||||
r'x ((?P<completionDate>' + _DATE_MATCH + ') )?' + '((?P<creationDate>' +
|
||||
_DATE_MATCH + ') )?(?P<rest>.*)')
|
||||
|
||||
_NORMAL_HEAD_MATCH = re.compile(
|
||||
|
|
Loading…
Reference in a new issue