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_compare_different_tasks(self):
198 # Negative: compare two different tasks
199 t1 = Task(self.tw, description="test task")
200 t2 = Task(self.tw, description="test task")
205 self.assertEqual(t1 == t2, False)
207 def test_compare_same_task_object(self):
208 # Compare Task object wit itself
209 t = Task(self.tw, description="test task")
212 self.assertEqual(t == t, True)
214 def test_compare_same_task(self):
215 # Compare the same task using two different objects
216 t1 = Task(self.tw, description="test task")
219 t2 = self.tw.tasks.get(uuid=t1['uuid'])
220 self.assertEqual(t1 == t2, True)
222 def test_compare_unsaved_tasks(self):
223 # t1 and t2 are unsaved tasks, considered to be unequal
224 # despite the content of data
225 t1 = Task(self.tw, description="test task")
226 t2 = Task(self.tw, description="test task")
228 self.assertEqual(t1 == t2, False)
230 def test_hash_unsaved_tasks(self):
231 # Considered equal, it's the same object
232 t1 = Task(self.tw, description="test task")
234 self.assertEqual(hash(t1) == hash(t2), True)
236 def test_hash_same_task(self):
237 # Compare the hash of the 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.__hash__(), t2.__hash__())
244 def test_adding_task_with_priority(self):
245 t = Task(self.tw, description="test task", priority="M")
248 def test_removing_priority_with_none(self):
249 t = Task(self.tw, description="test task", priority="L")
252 # Remove the priority mark
256 # Assert that priority is not there after saving
257 self.assertEqual(t['priority'], None)
259 def test_adding_task_with_due_time(self):
260 t = Task(self.tw, description="test task", due=datetime.datetime.now())
263 def test_removing_due_time_with_none(self):
264 t = Task(self.tw, description="test task", due=datetime.datetime.now())
267 # Remove the due timestamp
271 # Assert that due timestamp is no longer there
272 self.assertEqual(t['due'], None)
275 class AnnotationTest(TasklibTest):
278 super(AnnotationTest, self).setUp()
279 Task(self.tw, description="test task").save()
281 def test_adding_annotation(self):
282 task = self.tw.tasks.get()
283 task.add_annotation('test annotation')
284 self.assertEqual(len(task['annotations']), 1)
285 ann = task['annotations'][0]
286 self.assertEqual(ann['description'], 'test annotation')
288 def test_removing_annotation(self):
289 task = self.tw.tasks.get()
290 task.add_annotation('test annotation')
291 ann = task['annotations'][0]
293 self.assertEqual(len(task['annotations']), 0)
295 def test_removing_annotation_by_description(self):
296 task = self.tw.tasks.get()
297 task.add_annotation('test annotation')
298 task.remove_annotation('test annotation')
299 self.assertEqual(len(task['annotations']), 0)
301 def test_removing_annotation_by_obj(self):
302 task = self.tw.tasks.get()
303 task.add_annotation('test annotation')
304 ann = task['annotations'][0]
305 task.remove_annotation(ann)
306 self.assertEqual(len(task['annotations']), 0)
309 class UnicodeTest(TasklibTest):
311 def test_unicode_task(self):
312 Task(self.tw, description="†åßk").save()
315 def test_non_unicode_task(self):
316 Task(self.tw, description="test task").save()