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.
7 from .task import TaskWarrior, Task
10 class TasklibTest(unittest.TestCase):
13 self.tmp = tempfile.mkdtemp(dir='.')
14 self.tw = TaskWarrior(data_location=self.tmp)
17 shutil.rmtree(self.tmp)
20 class TaskFilterTest(TasklibTest):
22 def test_all_empty(self):
23 self.assertEqual(len(self.tw.tasks.all()), 0)
25 def test_all_non_empty(self):
26 Task(self.tw, description="test task").save()
27 self.assertEqual(len(self.tw.tasks.all()), 1)
28 self.assertEqual(self.tw.tasks.all()[0]['description'], 'test task')
29 self.assertEqual(self.tw.tasks.all()[0]['status'], 'pending')
31 def test_pending_non_empty(self):
32 Task(self.tw, description="test task").save()
33 self.assertEqual(len(self.tw.tasks.pending()), 1)
34 self.assertEqual(self.tw.tasks.pending()[0]['description'],
36 self.assertEqual(self.tw.tasks.pending()[0]['status'], 'pending')
38 def test_completed_empty(self):
39 Task(self.tw, description="test task").save()
40 self.assertEqual(len(self.tw.tasks.completed()), 0)
42 def test_completed_non_empty(self):
43 Task(self.tw, description="test task").save()
44 self.assertEqual(len(self.tw.tasks.completed()), 0)
45 self.tw.tasks.all()[0].done()
46 self.assertEqual(len(self.tw.tasks.completed()), 1)
48 def test_filtering_by_attribute(self):
49 Task(self.tw, description="no priority task").save()
50 Task(self.tw, priority="H", description="high priority task").save()
51 self.assertEqual(len(self.tw.tasks.all()), 2)
53 # Assert that the correct number of tasks is returned
54 self.assertEqual(len(self.tw.tasks.filter(priority="H")), 1)
56 # Assert that the correct tasks are returned
57 high_priority_task = self.tw.tasks.get(priority="H")
58 self.assertEqual(high_priority_task['description'], "high priority task")
60 def test_filtering_by_empty_attribute(self):
61 Task(self.tw, description="no priority task").save()
62 Task(self.tw, priority="H", description="high priority task").save()
63 self.assertEqual(len(self.tw.tasks.all()), 2)
65 # Assert that the correct number of tasks is returned
66 self.assertEqual(len(self.tw.tasks.filter(priority=None)), 1)
68 # Assert that the correct tasks are returned
69 no_priority_task = self.tw.tasks.get(priority=None)
70 self.assertEqual(no_priority_task['description'], "no priority task")
73 class TaskTest(TasklibTest):
75 def test_create_unsaved_task(self):
76 # Make sure a new task is not saved unless explicitly called for
77 t = Task(self.tw, description="test task")
78 self.assertEqual(len(self.tw.tasks.all()), 0)
80 # TODO: once python 2.6 compatiblity is over, use context managers here
81 # and in all subsequent tests for assertRaises
83 def test_delete_unsaved_task(self):
84 t = Task(self.tw, description="test task")
85 self.assertRaises(Task.NotSaved, t.delete)
87 def test_complete_unsaved_task(self):
88 t = Task(self.tw, description="test task")
89 self.assertRaises(Task.NotSaved, t.done)
91 def test_refresh_unsaved_task(self):
92 t = Task(self.tw, description="test task")
93 self.assertRaises(Task.NotSaved, t.refresh)
95 def test_delete_deleted_task(self):
96 t = Task(self.tw, description="test task")
100 self.assertRaises(Task.DeletedTask, t.delete)
102 def test_complete_completed_task(self):
103 t = Task(self.tw, description="test task")
107 self.assertRaises(Task.CompletedTask, t.done)
109 def test_complete_deleted_task(self):
110 t = Task(self.tw, description="test task")
114 self.assertRaises(Task.DeletedTask, t.done)
116 def test_empty_dependency_set_of_unsaved_task(self):
117 t = Task(self.tw, description="test task")
118 self.assertEqual(t['depends'], set())
120 def test_empty_dependency_set_of_saved_task(self):
121 t = Task(self.tw, description="test task")
123 self.assertEqual(t['depends'], set())
125 def test_set_unsaved_task_as_dependency(self):
126 # Adds only one dependency to task with no dependencies
127 t = Task(self.tw, description="test task")
128 dependency = Task(self.tw, description="needs to be done first")
130 # We only save the parent task, dependency task is unsaved
133 self.assertRaises(Task.NotSaved,
134 t.__setitem__, 'depends', set([dependency]))
136 def test_set_simple_dependency_set(self):
137 # Adds only one dependency to task with no dependencies
138 t = Task(self.tw, description="test task")
139 dependency = Task(self.tw, description="needs to be done first")
144 t['depends'] = set([dependency])
146 self.assertEqual(t['depends'], set([dependency]))
148 def test_set_complex_dependency_set(self):
149 # Adds two dependencies to task with no dependencies
150 t = Task(self.tw, description="test task")
151 dependency1 = Task(self.tw, description="needs to be done first")
152 dependency2 = Task(self.tw, description="needs to be done second")
158 t['depends'] = set([dependency1, dependency2])
160 self.assertEqual(t['depends'], set([dependency1, dependency2]))
162 def test_remove_from_dependency_set(self):
163 # Removes dependency from task with two dependencies
164 t = Task(self.tw, description="test task")
165 dependency1 = Task(self.tw, description="needs to be done first")
166 dependency2 = Task(self.tw, description="needs to be done second")
171 t['depends'] = set([dependency1, dependency2])
174 t['depends'] = t['depends'] - set([dependency2])
177 self.assertEqual(t['depends'], set([dependency1]))
179 def test_add_to_dependency_set(self):
180 # Adds dependency to task with one dependencies
181 t = Task(self.tw, description="test task")
182 dependency1 = Task(self.tw, description="needs to be done first")
183 dependency2 = Task(self.tw, description="needs to be done second")
188 t['depends'] = set([dependency1])
191 t['depends'] = t['depends'] | set([dependency2])
194 self.assertEqual(t['depends'], set([dependency1, dependency2]))
197 class AnnotationTest(TasklibTest):
200 super(AnnotationTest, self).setUp()
201 Task(self.tw, description="test task").save()
203 def test_adding_annotation(self):
204 task = self.tw.tasks.get()
205 task.add_annotation('test annotation')
206 self.assertEqual(len(task['annotations']), 1)
207 ann = task['annotations'][0]
208 self.assertEqual(ann['description'], 'test annotation')
210 def test_removing_annotation(self):
211 task = self.tw.tasks.get()
212 task.add_annotation('test annotation')
213 ann = task['annotations'][0]
215 self.assertEqual(len(task['annotations']), 0)
217 def test_removing_annotation_by_description(self):
218 task = self.tw.tasks.get()
219 task.add_annotation('test annotation')
220 task.remove_annotation('test annotation')
221 self.assertEqual(len(task['annotations']), 0)
223 def test_removing_annotation_by_obj(self):
224 task = self.tw.tasks.get()
225 task.add_annotation('test annotation')
226 ann = task['annotations'][0]
227 task.remove_annotation(ann)
228 self.assertEqual(len(task['annotations']), 0)
231 class UnicodeTest(TasklibTest):
233 def test_unicode_task(self):
234 Task(self.tw, description="†åßk").save()
237 def test_non_unicode_task(self):
238 Task(self.tw, description="test task").save()