Commit ce119824 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix strict recurrence and its tests.

parent 42ddf3ef
...@@ -36,6 +36,7 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -36,6 +36,7 @@ class DoCommandTest(CommandTest.CommandTest):
"x 2014-10-18 Already complete", "x 2014-10-18 Already complete",
"Inactive t:2030-12-31 id:2", "Inactive t:2030-12-31 id:2",
"Subtodo of inactive p:2", "Subtodo of inactive p:2",
"Strict due:2014-01-01 rec:1d",
] ]
self.todolist = TodoList.TodoList(todos) self.todolist = TodoList.TodoList(todos)
...@@ -108,30 +109,35 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -108,30 +109,35 @@ class DoCommandTest(CommandTest.CommandTest):
def _recurrence_helper(self, p_flags): def _recurrence_helper(self, p_flags):
command = DoCommand.DoCommand(p_flags, self.todolist, self.out, self.error) command = DoCommand.DoCommand(p_flags, self.todolist, self.out, self.error)
self.assertFalse(self.todolist.todo(4).has_tag('due'))
command.execute() command.execute()
todo = self.todolist.todo(8)
result = " 8 %s Recurring! rec:1d due:%s\nCompleted: x %s Recurring! rec:1d\n" % (self.today, self.tomorrow, self.today)
self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, result)
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
self.assertEquals(self.todolist.count(), 8) self.assertEquals(self.todolist.count(), 9)
self.assertTrue(self.todolist.todo(4).is_completed())
self.assertFalse(todo.is_completed())
self.assertTrue(todo.has_tag('due'))
def test_recurrence(self): def test_recurrence(self):
self.assertFalse(self.todolist.todo(4).has_tag('due'))
self._recurrence_helper(["4"]) self._recurrence_helper(["4"])
self.assertTrue(self.todolist.todo(4).is_completed())
result = " 9 %s Recurring! rec:1d due:%s\nCompleted: x %s Recurring! rec:1d\n" % (self.today, self.tomorrow, self.today)
self.assertEquals(self.output, result)
todo = self.todolist.todo(8)
self.assertFalse(todo.is_completed())
self.assertTrue(todo.has_tag('due'))
def test_strict_recurrence1(self): def test_strict_recurrence1(self):
self._recurrence_helper(["-s", "4"]) self._recurrence_helper(["-s", "8"])
result = " 9 2014-11-19 Strict due:2014-01-02 rec:1d\nCompleted: x 2014-11-19 Strict due:2014-01-01 rec:1d\n"
self.assertEquals(self.output, result)
def test_strict_recurrence2(self): def test_strict_recurrence2(self):
self._recurrence_helper(["--strict", "4"]) self._recurrence_helper(["--strict", "8"])
result = " 9 2014-11-19 Strict due:2014-01-02 rec:1d\nCompleted: x 2014-11-19 Strict due:2014-01-01 rec:1d\n"
self.assertEquals(self.output, result)
def test_invalid1(self): def test_invalid1(self):
command = DoCommand.DoCommand(["99"], self.todolist, self.out, self.error) command = DoCommand.DoCommand(["99"], self.todolist, self.out, self.error)
......
...@@ -18,23 +18,24 @@ import re ...@@ -18,23 +18,24 @@ import re
from DCommand import DCommand from DCommand import DCommand
from PrettyPrinter import pretty_print from PrettyPrinter import pretty_print
from Recurrence import advance_recurring_todo from Recurrence import advance_recurring_todo, strict_advance_recurring_todo
class DoCommand(DCommand): class DoCommand(DCommand):
def __init__(self, p_args, p_todolist, def __init__(self, p_args, p_todolist,
p_out=lambda a: None, p_out=lambda a: None,
p_err=lambda a: None, p_err=lambda a: None,
p_prompt=lambda a: None): p_prompt=lambda a: None):
super(DoCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
self.strict_recurrence = False self.strict_recurrence = False
super(DoCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
def get_flags(self): def get_flags(self):
""" Additional flags. """ """ Additional flags. """
return ("s", ["strict"]) return ("s", ["strict"])
def process_flag(self, p_opt, p_value): def process_flag(self, p_opt, p_value):
if p_opt == "s" or p_opt == "--strict": if p_opt == "-s" or p_opt == "--strict":
self.strict_recurrence = True self.strict_recurrence = True
def _handle_recurrence(self): def _handle_recurrence(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment