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_empty_dependency_set_of_unsaved_task(self):
118 t = Task(self.tw, description="test task")
119 self.assertEqual(t['depends'], set())
121 def test_empty_dependency_set_of_saved_task(self):
122 t = Task(self.tw, description="test task")
124 self.assertEqual(t['depends'], set())
126 def test_set_unsaved_task_as_dependency(self):
127 # Adds only one dependency to task with no dependencies
128 t = Task(self.tw, description="test task")
129 dependency = Task(self.tw, description="needs to be done first")
131 # We only save the parent task, dependency task is unsaved
134 self.assertRaises(Task.NotSaved,
135 t.__setitem__, 'depends', set([dependency]))
137 def test_set_simple_dependency_set(self):
138 # Adds only one dependency to task with no dependencies
139 t = Task(self.tw, description="test task")
140 dependency = Task(self.tw, description="needs to be done first")
145 t['depends'] = set([dependency])
147 self.assertEqual(t['depends'], set([dependency]))
149 def test_set_complex_dependency_set(self):
150 # Adds two dependencies to task with no dependencies
151 t = Task(self.tw, description="test task")
152 dependency1 = Task(self.tw, description="needs to be done first")
153 dependency2 = Task(self.tw, description="needs to be done second")
159 t['depends'] = set([dependency1, dependency2])
161 self.assertEqual(t['depends'], set([dependency1, dependency2]))
163 def test_remove_from_dependency_set(self):
164 # Removes dependency from task with two dependencies
165 t = Task(self.tw, description="test task")
166 dependency1 = Task(self.tw, description="needs to be done first")
167 dependency2 = Task(self.tw, description="needs to be done second")
172 t['depends'] = set([dependency1, dependency2])
175 t['depends'] = t['depends'] - set([dependency2])
178 self.assertEqual(t['depends'], set([dependency1]))
180 def test_add_to_dependency_set(self):
181 # Adds dependency to task with one dependencies
182 t = Task(self.tw, description="test task")
183 dependency1 = Task(self.tw, description="needs to be done first")
184 dependency2 = Task(self.tw, description="needs to be done second")
189 t['depends'] = set([dependency1])
192 t['depends'] = t['depends'] | set([dependency2])
195 self.assertEqual(t['depends'], set([dependency1, dependency2]))
197 def test_simple_dependency_set_save_repeatedly(self):
198 # Adds only one dependency to task with no dependencies
199 t = Task(self.tw, description="test task")
200 dependency = Task(self.tw, description="needs to be done first")
203 t['depends'] = set([dependency])
206 # We taint the task, but keep depends intact
207 t['description'] = "test task modified"
210 self.assertEqual(t['depends'], set([dependency]))
212 # We taint the task, but assign the same set to the depends
213 t['depends'] = set([dependency])
214 t['description'] = "test task modified again"
217 self.assertEqual(t['depends'], set([dependency]))
219 def test_compare_different_tasks(self):
220 # Negative: compare two different tasks
221 t1 = Task(self.tw, description="test task")
222 t2 = Task(self.tw, description="test task")
227 self.assertEqual(t1 == t2, False)
229 def test_compare_same_task_object(self):
230 # Compare Task object wit itself
231 t = Task(self.tw, description="test task")
234 self.assertEqual(t == t, True)
236 def test_compare_same_task(self):
237 # Compare the same task using two different objects
238 t1 = Task(self.tw, description="test task")
241 t2 = self.tw.tasks.get(uuid=t1['uuid'])
242 self.assertEqual(t1 == t2, True)
244 def test_compare_unsaved_tasks(self):
245 # t1 and t2 are unsaved tasks, considered to be unequal
246 # despite the content of data
247 t1 = Task(self.tw, description="test task")
248 t2 = Task(self.tw, description="test task")
250 self.assertEqual(t1 == t2, False)
252 def test_hash_unsaved_tasks(self):
253 # Considered equal, it's the same object
254 t1 = Task(self.tw, description="test task")
256 self.assertEqual(hash(t1) == hash(t2), True)
258 def test_hash_same_task(self):
259 # Compare the hash of the task using two different objects
260 t1 = Task(self.tw, description="test task")
263 t2 = self.tw.tasks.get(uuid=t1['uuid'])
264 self.assertEqual(t1.__hash__(), t2.__hash__())
266 def test_adding_task_with_priority(self):
267 t = Task(self.tw, description="test task", priority="M")
270 def test_removing_priority_with_none(self):
271 t = Task(self.tw, description="test task", priority="L")
274 # Remove the priority mark
278 # Assert that priority is not there after saving
279 self.assertEqual(t['priority'], None)
281 def test_adding_task_with_due_time(self):
282 t = Task(self.tw, description="test task", due=datetime.datetime.now())
285 def test_removing_due_time_with_none(self):
286 t = Task(self.tw, description="test task", due=datetime.datetime.now())
289 # Remove the due timestamp
293 # Assert that due timestamp is no longer there
294 self.assertEqual(t['due'], None)
296 def test_modified_fields_new_task(self):
299 # This should be empty with new task
300 self.assertEqual(set(t._modified_fields), set())
303 t['description'] = "test task"
304 self.assertEqual(set(t._modified_fields), set(['description']))
306 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
307 self.assertEqual(set(t._modified_fields), set(['description', 'due']))
309 t['project'] = "test project"
310 self.assertEqual(set(t._modified_fields),
311 set(['description', 'due', 'project']))
313 # List of modified fields should clear out when saved
315 self.assertEqual(set(t._modified_fields), set())
317 # Reassigning the fields with the same values now should not produce
319 t['description'] = "test task"
320 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
321 t['project'] = "test project"
322 self.assertEqual(set(t._modified_fields), set())
324 def test_modified_fields_loaded_task(self):
328 t['description'] = "test task"
329 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
330 t['project'] = "test project"
332 dependency = Task(self.tw, description="dependency")
334 t['depends'] = set([dependency])
336 # List of modified fields should clear out when saved
338 self.assertEqual(set(t._modified_fields), set())
340 # Get the task by using a filter by UUID
341 t2 = self.tw.tasks.get(uuid=t['uuid'])
343 # Reassigning the fields with the same values now should not produce
345 t['description'] = "test task"
346 t['due'] = datetime.datetime(2014, 2, 14, 14, 14, 14) # <3
347 t['project'] = "test project"
348 t['depends'] = set([dependency])
349 self.assertEqual(set(t._modified_fields), set())
351 class AnnotationTest(TasklibTest):
354 super(AnnotationTest, self).setUp()
355 Task(self.tw, description="test task").save()
357 def test_adding_annotation(self):
358 task = self.tw.tasks.get()
359 task.add_annotation('test annotation')
360 self.assertEqual(len(task['annotations']), 1)
361 ann = task['annotations'][0]
362 self.assertEqual(ann['description'], 'test annotation')
364 def test_removing_annotation(self):
365 task = self.tw.tasks.get()
366 task.add_annotation('test annotation')
367 ann = task['annotations'][0]
369 self.assertEqual(len(task['annotations']), 0)
371 def test_removing_annotation_by_description(self):
372 task = self.tw.tasks.get()
373 task.add_annotation('test annotation')
374 task.remove_annotation('test annotation')
375 self.assertEqual(len(task['annotations']), 0)
377 def test_removing_annotation_by_obj(self):
378 task = self.tw.tasks.get()
379 task.add_annotation('test annotation')
380 ann = task['annotations'][0]
381 task.remove_annotation(ann)
382 self.assertEqual(len(task['annotations']), 0)
385 class UnicodeTest(TasklibTest):
387 def test_unicode_task(self):
388 Task(self.tw, description="†åßk").save()
391 def test_non_unicode_task(self):
392 Task(self.tw, description="test task").save()