All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
8 from .task import TaskWarrior, Task
11 class TasklibTest(unittest.TestCase):
14 self.tmp = tempfile.mkdtemp(dir='.')
15 self.tw = TaskWarrior(data_location=self.tmp)
18 shutil.rmtree(self.tmp)
21 class TaskFilterTest(TasklibTest):
23 def test_all_empty(self):
24 self.assertEqual(len(self.tw.tasks.all()), 0)
26 def test_all_non_empty(self):
27 Task(self.tw, description="test task").save()
28 self.assertEqual(len(self.tw.tasks.all()), 1)
29 self.assertEqual(self.tw.tasks.all()[0]['description'], 'test task')
30 self.assertEqual(self.tw.tasks.all()[0]['status'], 'pending')
32 def test_pending_non_empty(self):
33 Task(self.tw, description="test task").save()
34 self.assertEqual(len(self.tw.tasks.pending()), 1)
35 self.assertEqual(self.tw.tasks.pending()[0]['description'],
37 self.assertEqual(self.tw.tasks.pending()[0]['status'], 'pending')
39 def test_completed_empty(self):
40 Task(self.tw, description="test task").save()
41 self.assertEqual(len(self.tw.tasks.completed()), 0)
43 def test_completed_non_empty(self):
44 Task(self.tw, description="test task").save()
45 self.assertEqual(len(self.tw.tasks.completed()), 0)
46 self.tw.tasks.all()[0].done()
47 self.assertEqual(len(self.tw.tasks.completed()), 1)
49 def test_filtering_by_attribute(self):
50 Task(self.tw, description="no priority task").save()
51 Task(self.tw, priority="H", description="high priority task").save()
52 self.assertEqual(len(self.tw.tasks.all()), 2)
54 # Assert that the correct number of tasks is returned
55 self.assertEqual(len(self.tw.tasks.filter(priority="H")), 1)
57 # Assert that the correct tasks are returned
58 high_priority_task = self.tw.tasks.get(priority="H")
59 self.assertEqual(high_priority_task['description'], "high priority task")
61 def test_filtering_by_empty_attribute(self):
62 Task(self.tw, description="no priority task").save()
63 Task(self.tw, priority="H", description="high priority task").save()
64 self.assertEqual(len(self.tw.tasks.all()), 2)
66 # Assert that the correct number of tasks is returned
67 self.assertEqual(len(self.tw.tasks.filter(priority=None)), 1)
69 # Assert that the correct tasks are returned
70 no_priority_task = self.tw.tasks.get(priority=None)
71 self.assertEqual(no_priority_task['description'], "no priority task")
74 class TaskTest(TasklibTest):
76 def test_create_unsaved_task(self):
77 # Make sure a new task is not saved unless explicitly called for
78 t = Task(self.tw, description="test task")
79 self.assertEqual(len(self.tw.tasks.all()), 0)
81 # TODO: once python 2.6 compatiblity is over, use context managers here
82 # and in all subsequent tests for assertRaises
84 def test_delete_unsaved_task(self):
85 t = Task(self.tw, description="test task")
86 self.assertRaises(Task.NotSaved, t.delete)
88 def test_complete_unsaved_task(self):
89 t = Task(self.tw, description="test task")
90 self.assertRaises(Task.NotSaved, t.done)
92 def test_refresh_unsaved_task(self):
93 t = Task(self.tw, description="test task")
94 self.assertRaises(Task.NotSaved, t.refresh)
96 def test_delete_deleted_task(self):
97 t = Task(self.tw, description="test task")
101 self.assertRaises(Task.DeletedTask, t.delete)
103 def test_complete_completed_task(self):
104 t = Task(self.tw, description="test task")
108 self.assertRaises(Task.CompletedTask, t.done)
110 def test_complete_deleted_task(self):
111 t = Task(self.tw, description="test task")
115 self.assertRaises(Task.DeletedTask, t.done)
117 def test_modify_simple_attribute_without_space(self):
118 t = Task(self.tw, description="test")
121 self.assertEquals(t['description'], "test")
123 t['description'] = "test-modified"
126 self.assertEquals(t['description'], "test-modified")
128 def test_modify_simple_attribute_with_space(self):
129 # Space can pose problems with parsing
130 t = Task(self.tw, description="test task")
133 self.assertEquals(t['description'], "test task")
135 t['description'] = "test task modified"
138 self.assertEquals(t['description'], "test task modified")
140 def test_empty_dependency_set_of_unsaved_task(self):
141 t = Task(self.tw, description="test task")
142 self.assertEqual(t['depends'], set())
144 def test_empty_dependency_set_of_saved_task(self):
145 t = Task(self.tw, description="test task")
147 self.assertEqual(t['depends'], set())
149 def test_set_unsaved_task_as_dependency(self):
150 # Adds only one dependency to task with no dependencies
151 t = Task(self.tw, description="test task")
152 dependency = Task(self.tw, description="needs to be done first")
154 # We only save the parent task, dependency task is unsaved
157 self.assertRaises(Task.NotSaved,
158 t.__setitem__, 'depends', set([dependency]))
160 def test_set_simple_dependency_set(self):
161 # Adds only one dependency to task with no dependencies
162 t = Task(self.tw, description="test task")
163 dependency = Task(self.tw, description="needs to be done first")
168 t['depends'] = set([dependency])
170 self.assertEqual(t['depends'], set([dependency]))
172 def test_set_complex_dependency_set(self):
173 # Adds two dependencies to task with no dependencies
174 t = Task(self.tw, description="test task")
175 dependency1 = Task(self.tw, description="needs to be done first")
176 dependency2 = Task(self.tw, description="needs to be done second")
182 t['depends'] = set([dependency1, dependency2])
184 self.assertEqual(t['depends'], set([dependency1, dependency2]))
186 def test_remove_from_dependency_set(self):
187 # Removes dependency from task with two dependencies
188 t = Task(self.tw, description="test task")
189 dependency1 = Task(self.tw, description="needs to be done first")
190 dependency2 = Task(self.tw, description="needs to be done second")
195 t['depends'] = set([dependency1, dependency2])
198 t['depends'] = t['depends'] - set([dependency2])
201 self.assertEqual(t['depends'], set([dependency1]))
203 def test_add_to_dependency_set(self):
204 # Adds dependency to task with one dependencies
205 t = Task(self.tw, description="test task")
206 dependency1 = Task(self.tw, description="needs to be done first")
207 dependency2 = Task(self.tw, description="needs to be done second")
212 t['depends'] = set([dependency1])
215 t['depends'] = t['depends'] | set([dependency2])
218 self.assertEqual(t['depends'], set([dependency1, dependency2]))
220 def test_simple_dependency_set_save_repeatedly(self):
221 # Adds only one dependency to task with no dependencies
222 t = Task(self.tw, description="test task")
223 dependency = Task(self.tw, description="needs to be done first")
226 t['depends'] = set([dependency])
229 # We taint the task, but keep depends intact
230 t['description'] = "test task modified"
233 self.assertEqual(t['depends'], set([dependency]))
235 # We taint the task, but assign the same set to the depends
236 t['depends'] = set([dependency])
237 t['description'] = "test task modified again"
240 self.assertEqual(t['depends'], set([dependency]))
242 def test_compare_different_tasks(self):
243 # Negative: compare two different tasks
244 t1 = Task(self.tw, description="test task")
245 t2 = Task(self.tw, description="test task")
250 self.assertEqual(t1 == t2, False)
252 def test_compare_same_task_object(self):
253 # Compare Task object wit itself
254 t = Task(self.tw, description="test task")
257 self.assertEqual(t == t, True)
259 def test_compare_same_task(self):
260 # Compare the same task using two different objects
261 t1 = Task(self.tw, description="test task")
264 t2 = self.tw.tasks.get(uuid=t1['uuid'])
265 self.assertEqual(t1 == t2, True)
267 def test_compare_unsaved_tasks(self):
268 # t1 and t2 are unsaved tasks, considered to be unequal
269 # despite the content of data
270 t1 = Task(self.tw, description="test task")
271 t2 = Task(self.tw, description="test task")
273 self.assertEqual(t1 == t2, False)
275 def test_hash_unsaved_tasks(self):
276 # Considered equal, it's the same object
277 t1 = Task(self.tw, description="test task")
279 self.assertEqual(hash(t1) == hash(t2), True)
281 def test_hash_same_task(self):
282 # Compare the hash of the task using two different objects
283 t1 = Task(self.tw, description="test task")
286 t2 = self.tw.tasks.get(uuid=t1['uuid'])
287 self.assertEqual(t1.__hash__(), t2.__hash__())
289 def test_adding_task_with_priority(self):
290 t = Task(self.tw, description="test task", priority="M")
293 def test_removing_priority_with_none(self):
294 t = Task(self.tw, description="test task", priority="L")
297 # Remove the priority mark
301 # Assert that priority is not there after saving
302 self.assertEqual(t['priority'], None)
304 def test_adding_task_with_due_time(self):
305 t = Task(self.tw, description="test task", due=datetime.datetime.now())
308 def test_removing_due_time_with_none(self):
309 t = Task(self.tw, description="test task", due=datetime.datetime.now())
312 # Remove the due timestamp
316 # Assert that due timestamp is no longer there
317 self.assertEqual(t['due'], None)
319 def test_modified_fields_new_task(self):
322 # This should be empty with new task
323 self.assertEqual(set(t._modified_fields), set())
326 t['description'] = "test task"
327 self.assertEqual(set(t._modified_fields), set(['description']))
329 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
330 self.assertEqual(set(t._modified_fields), set(['description', 'due']))
332 t['project'] = "test project"
333 self.assertEqual(set(t._modified_fields),
334 set(['description', 'due', 'project']))
336 # List of modified fields should clear out when saved
338 self.assertEqual(set(t._modified_fields), set())
340 # Reassigning the fields with the same values now should not produce
342 t['description'] = "test task"
343 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
344 t['project'] = "test project"
345 self.assertEqual(set(t._modified_fields), set())
347 def test_modified_fields_loaded_task(self):
351 t['description'] = "test task"
352 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
353 t['project'] = "test project"
355 dependency = Task(self.tw, description="dependency")
357 t['depends'] = set([dependency])
359 # List of modified fields should clear out when saved
361 self.assertEqual(set(t._modified_fields), set())
363 # Get the task by using a filter by UUID
364 t2 = self.tw.tasks.get(uuid=t['uuid'])
366 # Reassigning the fields with the same values now should not produce
368 t['description'] = "test task"
369 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
370 t['project'] = "test project"
371 t['depends'] = set([dependency])
372 self.assertEqual(set(t._modified_fields), set())
374 class AnnotationTest(TasklibTest):
377 super(AnnotationTest, self).setUp()
378 Task(self.tw, description="test task").save()
380 def test_adding_annotation(self):
381 task = self.tw.tasks.get()
382 task.add_annotation('test annotation')
383 self.assertEqual(len(task['annotations']), 1)
384 ann = task['annotations'][0]
385 self.assertEqual(ann['description'], 'test annotation')
387 def test_removing_annotation(self):
388 task = self.tw.tasks.get()
389 task.add_annotation('test annotation')
390 ann = task['annotations'][0]
392 self.assertEqual(len(task['annotations']), 0)
394 def test_removing_annotation_by_description(self):
395 task = self.tw.tasks.get()
396 task.add_annotation('test annotation')
397 task.remove_annotation('test annotation')
398 self.assertEqual(len(task['annotations']), 0)
400 def test_removing_annotation_by_obj(self):
401 task = self.tw.tasks.get()
402 task.add_annotation('test annotation')
403 ann = task['annotations'][0]
404 task.remove_annotation(ann)
405 self.assertEqual(len(task['annotations']), 0)
408 class UnicodeTest(TasklibTest):
410 def test_unicode_task(self):
411 Task(self.tw, description="†åßk").save()
414 def test_non_unicode_task(self):
415 Task(self.tw, description="test task").save()