1
0
Fork 0
mirror of https://github.com/topydo/topydo.git synced 2024-05-20 13:58:33 +00:00

Compare commits

...

5 commits

Author SHA1 Message Date
Daniel J. Perry c054766f85
Merge 55ffa1cd24 into f3dc108d58 2023-09-02 05:59:39 -07:00
David Steele f3dc108d58 Fix tests for test completion test change 2023-08-14 10:25:40 -04:00
David Steele 5d7a742095 Use todo.txt spec for id-ing completed tasks
Topydo was only identifying a task as completed if it included a
completion date (which topydo automatically adds). This affects
compatibility with other todo.txt apps, making archiving unreliable.
2023-08-14 10:14:31 -04:00
Daniel J. Perry 55ffa1cd24 Color relative start date 2022-09-15 11:46:54 -04:00
Daniel J. Perry 46ed36af84 Color relative due date based on remaining time 2022-09-08 18:25:36 -04:00
8 changed files with 98 additions and 12 deletions

View file

@ -1,4 +1,3 @@
x 2014-10-19 Complete
x 2014-10-20 Another one complete
x Not complete
(C) Active

View file

@ -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__':

68
test/test_parse.py Normal file
View 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()

View file

@ -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")

View file

@ -17,9 +17,11 @@
""" Utilities for formatting output with "list_format" option."""
import re
from datetime import date, timedelta
import arrow
from topydo.lib.Color import Color
from topydo.lib.Config import config
from topydo.lib.ProgressColor import progress_color
from topydo.lib.Utils import escape_ansi, get_terminal_size, humanize_date
@ -278,12 +280,28 @@ class ListFormatParser(object):
repl_trunc = None
for substr, placeholder, getter in self.format_list:
color = Color()
repl = getter(p_todo) if getter else ''
pattern = MAIN_PATTERN.format(ph=placeholder)
if placeholder == 'S':
repl_trunc = repl
# Alternative output formats may have to remove color codes
match placeholder:
case 'D' if p_todo.due_date():
td = p_todo.due_date() - date.today()
if td > timedelta(days=3):
color.color = 'green'
elif timedelta(days=1) < td <= timedelta(days=3):
color.color = 'yellow'
else:
color.color = 'red'
repl = color.as_ansi() + repl + '\033[0m'
case 'S':
repl_trunc = repl
case 'T' if p_todo.start_date():
color.color = 'green'
repl = color.as_ansi() + repl + '\033[0m'
# The rest of this code should break on color codes or destroy them
try:
if repl == '':
substr = re.sub(pattern, '', substr)

View file

@ -51,7 +51,7 @@ class Todo(TodoBase):
""" Returns a date object of the todo's start date. """
return self.get_date(config().tag_start())
def due_date(self):
def due_date(self) -> date:
""" Returns a date object of the todo's due date. """
return self.get_date(config().tag_due())

View file

@ -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(

View file

@ -48,6 +48,13 @@ class PrettyPrinterColorFilter(PrettyPrinterFilter):
# color by priority
p_todo_str.set_color(0, priority_color)
# Here the "default" color is really the priority color, so any
# special highlighting done by parsing is still kept, but will be
# set back to priority afterwards.
for i,match in enumerate(re.finditer('\033\\[0m', p_todo_str.data)):
p_todo_str.set_color(match.end()-(i+1)*4, priority_color)
re.sub('\033\\[0m', '', p_todo_str.data)
for pattern, color in colors:
for match in re.finditer(pattern, p_todo_str.data):
p_todo_str.set_color(match.start(), color)