Commit 7a32e218 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix test cases and assume 14 days when due < start or creation date

parent 561ba74f
...@@ -125,35 +125,35 @@ class ProgressColorTest(TopydoTest): ...@@ -125,35 +125,35 @@ class ProgressColorTest(TopydoTest):
def test_progress17(self): def test_progress17(self):
""" Due tomorrow (creation date + recurrence + start date) """ """ Due tomorrow (creation date + recurrence + start date) """
color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02')) color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02'))
self.assertEqual(color.color, 3) self.assertEqual(color.color, 2)
def test_progress18(self): def test_progress18(self):
""" Due tomorrow (creation date + recurrence + start date) """ """ Due tomorrow (creation date + recurrence + start date) """
set_256_colors() set_256_colors()
color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02')) color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02'))
self.assertEqual(color.color, 208) self.assertEqual(color.color, 22)
def test_progress19(self): def test_progress19(self):
""" Due tomorrow (creation date + strict recurrence + start date) """ """ Due tomorrow (creation date + strict recurrence + start date) """
color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02')) color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02'))
self.assertEqual(color.color, 3) self.assertEqual(color.color, 2)
def test_progress20(self): def test_progress20(self):
""" Due tomorrow (creation date + strict recurrence + start date) """ """ Due tomorrow (creation date + strict recurrence + start date) """
set_256_colors() set_256_colors()
color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02')) color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02'))
self.assertEqual(color.color, 208) self.assertEqual(color.color, 22)
def test_progress21(self): def test_progress21(self):
""" Due tomorrow (creation date + start date) """ """ Due tomorrow (creation date + start date) """
color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 t:2016-01-02')) color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 t:2016-01-02'))
self.assertEqual(color.color, 3) self.assertEqual(color.color, 2)
def test_progress22(self): def test_progress22(self):
""" Due tomorrow (creation date + start date) """ """ Due tomorrow (creation date + start date) """
set_256_colors() set_256_colors()
color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 t:2016-01-02')) color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 t:2016-01-02'))
self.assertEqual(color.color, 208) self.assertEqual(color.color, 22)
def test_progress23(self): def test_progress23(self):
""" Due tomorrow (creation date + start date) """ """ Due tomorrow (creation date + start date) """
...@@ -179,5 +179,12 @@ class ProgressColorTest(TopydoTest): ...@@ -179,5 +179,12 @@ class ProgressColorTest(TopydoTest):
# a length of 14 days is assumed # a length of 14 days is assumed
self.assertEqual(color.color, 208) self.assertEqual(color.color, 208)
def test_progress27(self):
""" Creation date after due date """
set_256_colors()
color = progress_color(Todo('2016-01-03 Foo due:2016-01-02'))
# a length of 14 days is assumed
self.assertEqual(color.color, 208)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -20,6 +20,11 @@ from topydo.lib.Color import Color ...@@ -20,6 +20,11 @@ from topydo.lib.Color import Color
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.Recurrence import relative_date_to_date from topydo.lib.Recurrence import relative_date_to_date
# when a todo item has not enough information to determine the length, assume
# this length
ASSUMED_TODO_LENGTH = 14 # days
def progress_color(p_todo): def progress_color(p_todo):
color16_range = [ color16_range = [
2, # green 2, # green
...@@ -48,18 +53,24 @@ def progress_color(p_todo): ...@@ -48,18 +53,24 @@ def progress_color(p_todo):
diff = p_end - p_start diff = p_end - p_start
return diff.days return diff.days
if p_todo.has_tag('rec') and p_todo.due_date() \ does_recur = p_todo.has_tag('rec')
and not p_todo.start_date(): start_date = p_todo.start_date()
due_date = p_todo.due_date()
creation_date = p_todo.creation_date()
if does_recur and due_date and not start_date:
# add negation, offset is based on due date # add negation, offset is based on due date
recurrence_pattern = p_todo.tag_value('rec') recurrence_pattern = p_todo.tag_value('rec')
neg_recurrence_pattern = re.sub('^\+?', '-', recurrence_pattern) neg_recurrence_pattern = re.sub('^\+?', '-', recurrence_pattern)
start = relative_date_to_date( start = relative_date_to_date(neg_recurrence_pattern, due_date)
neg_recurrence_pattern, p_todo.due_date()) result = diff_days(start, due_date)
due = p_todo.due_date() elif due_date and not start_date and not creation_date:
result = ASSUMED_TODO_LENGTH
result = diff_days(start, due) elif due_date and start_date and due_date < start_date:
result = ASSUMED_TODO_LENGTH
elif due_date and not start_date and creation_date and due_date < creation_date:
result = ASSUMED_TODO_LENGTH
else: else:
result = p_todo.length() result = p_todo.length()
......
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