mirror of
https://github.com/topydo/topydo.git
synced 2024-05-20 13:58:33 +00:00
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.
This commit is contained in:
parent
800f9aec36
commit
5d7a742095
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()
|
|
@ -26,7 +26,7 @@ from topydo.lib.Utils import date_string_to_date
|
||||||
_DATE_MATCH = r'\d{4}-\d{2}-\d{2}'
|
_DATE_MATCH = r'\d{4}-\d{2}-\d{2}'
|
||||||
|
|
||||||
_COMPLETED_HEAD_MATCH = re.compile(
|
_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>.*)')
|
_DATE_MATCH + ') )?(?P<rest>.*)')
|
||||||
|
|
||||||
_NORMAL_HEAD_MATCH = re.compile(
|
_NORMAL_HEAD_MATCH = re.compile(
|
||||||
|
|
Loading…
Reference in a new issue