]> git.madduck.net Git - etc/taskwarrior.git/blob - tasklib/tests.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

The next version will be 0.4.1
[etc/taskwarrior.git] / tasklib / tests.py
1 # coding=utf-8
2
3 import shutil
4 import tempfile
5 import unittest
6
7 from .task import TaskWarrior
8
9
10 class TasklibTest(unittest.TestCase):
11
12     def setUp(self):
13         self.tmp = tempfile.mkdtemp(dir='.')
14         self.tw = TaskWarrior(data_location=self.tmp)
15
16     def tearDown(self):
17         shutil.rmtree(self.tmp)
18
19
20 class TaskFilterTest(TasklibTest):
21
22     def test_all_empty(self):
23         self.assertEqual(len(self.tw.tasks.all()), 0)
24
25     def test_all_non_empty(self):
26         self.tw.execute_command(['add', 'test task'])
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')
30
31     def test_pending_non_empty(self):
32         self.tw.execute_command(['add', 'test task'])
33         self.assertEqual(len(self.tw.tasks.pending()), 1)
34         self.assertEqual(self.tw.tasks.pending()[0]['description'],
35                          'test task')
36         self.assertEqual(self.tw.tasks.pending()[0]['status'], 'pending')
37
38     def test_completed_empty(self):
39         self.tw.execute_command(['add', 'test task'])
40         self.assertEqual(len(self.tw.tasks.completed()), 0)
41
42     def test_completed_non_empty(self):
43         self.tw.execute_command(['add', 'test task'])
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)
47
48
49 class AnnotationTest(TasklibTest):
50
51     def setUp(self):
52         super(AnnotationTest, self).setUp()
53         self.tw.execute_command(['add', 'test task'])
54
55     def test_adding_annotation(self):
56         task = self.tw.tasks.get()
57         task.add_annotation('test annotation')
58         self.assertEqual(len(task['annotations']), 1)
59         ann = task['annotations'][0]
60         self.assertEqual(ann['description'], 'test annotation')
61
62     def test_removing_annotation(self):
63         task = self.tw.tasks.get()
64         task.add_annotation('test annotation')
65         ann = task['annotations'][0]
66         ann.remove()
67         self.assertEqual(len(task['annotations']), 0)
68
69     def test_removing_annotation_by_description(self):
70         task = self.tw.tasks.get()
71         task.add_annotation('test annotation')
72         task.remove_annotation('test annotation')
73         self.assertEqual(len(task['annotations']), 0)
74
75     def test_removing_annotation_by_obj(self):
76         task = self.tw.tasks.get()
77         task.add_annotation('test annotation')
78         ann = task['annotations'][0]
79         task.remove_annotation(ann)
80         self.assertEqual(len(task['annotations']), 0)
81
82
83 class UnicodeTest(TasklibTest):
84
85     def test_unicode_task(self):
86         self.tw.execute_command(['add', '†åßk'])
87         self.tw.tasks.get()
88
89     def test_non_unicode_task(self):
90         self.tw.execute_command(['add', 'task'])
91         self.tw.tasks.get()