-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_todo_item.py
executable file
·184 lines (159 loc) · 7 KB
/
test_todo_item.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
'''
Created on Dec 17, 2012
@author: mstave
'''
import unittest
from todo_item import TodoItem
class TestToDoItem(unittest.TestCase): # pylint: disable-msg=R0904
def test_parse_pri(self):
test_str = "(B) 2012-08-27 @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.priority)
self.assertEqual(test_item.priority, "B")
def test_parse_date(self):
test_str = "(B) 2012-08-27 @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.creation_date)
self.assertEqual(test_item.creation_date, '2012-08-27')
def test_parse_context(self):
test_str = "(B) 2012-08-27 @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.context)
self.assertEqual(test_item.context, "home")
def test_parse_no_pri(self):
test_str = "2012-08-27 @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.priority)
self.assertEqual(test_item.creation_date, '2012-08-27')
def test_parse_no_date(self):
test_str = "@home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.creation_date)
self.assertIsNotNone(test_item.context)
self.assertEqual(test_item.context, "home")
def test_parse_task_with_context(self):
test_str = "@foo task"
test_item = TodoItem(test_str)
self.assertEqual("task", test_item.task)
def test_parse_with_context_and_pri(self):
test_str = "(B) @foo task"
test_item = TodoItem(test_str)
self.assertEqual("task", test_item.task)
def test_parse_no_task(self):
test_str = "(B) 2012-08-27"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.task)
def test_parse_no_context(self):
test_str = "Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.priority)
self.assertIsNotNone(test_item.task)
self.assertEqual(test_item.task, test_str)
def test_set_context_existing(self):
test_str = "(B) 2012-08-27 Xbox repair @home"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.context)
self.assertEqual(test_item.context, "home")
test_item.context = "work"
self.assertIsNotNone(test_item.context)
self.assertEqual("work", test_item.context)
self.assertEqual(test_str.replace("home", "work"),
test_item.todo_txt_line)
def test_del_priority(self):
test_str = "(B) 2012-08-27 @home Xbox repair"
test_item = TodoItem(test_str)
test_item.priority = None
self.assertIsNone(test_item.priority)
self.assertEqual("2012-08-27 Xbox repair @home",
test_item.todo_txt_line)
def test_done(self):
test_str = "(B) 2012-08-27 Xbox repair @home"
done_str = "x 2012-09-23 2012-02-12 XBox repair @home"
done_item = TodoItem(done_str)
not_done_item = TodoItem(test_str)
self.assertFalse(not_done_item.done)
self.assertTrue(done_item.done)
self.assertEqual("home", done_item.context)
self.assertEqual("2012-02-12", done_item.creation_date)
self.assertEqual(str(done_item), done_str)
print done_str, str(done_item)
def test_done_2(self):
test_str = "x 2012-09-27 approve 8194"
test_item = TodoItem(test_str)
self.assertEqual("approve 8194", test_item.task)
def test_mark_done(self):
test_str = "(B) 2012-08-27 @home Xbox repair"
done_item = TodoItem("x " + TodoItem.curr_date_str() +
" 2012-08-27 @home Xbox repair")
test_item = TodoItem(test_str)
test_item.done = True
test_item.priority = None
self.assertEqual(test_item.__dict__, done_item.__dict__)
def test_set_context_from_scratch(self):
test_str = "(B) 2012-08-27 Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.context)
test_item.context = "work"
self.assertIsNotNone(test_item.context)
self.assertEqual("work", test_item.context)
self.assertEqual("Xbox repair", test_item.task)
self.assertEqual("(B) 2012-08-27 Xbox repair @work",
test_item.todo_txt_line)
def test_set_task_existing(self):
test_str = "(B) 2012-08-27 Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.task)
test_item.task = "ps3 polish"
self.assertEqual("ps3 polish", test_item.task)
self.assertEqual("(B) 2012-08-27 ps3 polish", test_item.todo_txt_line)
def test_set_date_from_scratch(self):
test_str = "(B) @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.creation_date)
test_item.creation_date = "2012-01-04"
self.assertIsNotNone(test_item.creation_date)
self.assertEquals("2012-01-04", test_item.creation_date)
self.assertEquals("(B) 2012-01-04 Xbox repair @home",
test_item.todo_txt_line)
def test_set_date_existing_date(self):
test_str = "(B) 2012-02-05 @home Xbox repair"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.creation_date)
test_item.creation_date = "2012-01-04"
self.assertIsNotNone(test_item.creation_date)
self.assertEquals("(B) 2012-01-04 Xbox repair @home",
test_item.todo_txt_line)
def test_set_task_from_scratch(self):
test_str = "(B) 2012-08-27"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.task)
test_item.task = "foo bar"
self.assertIsNotNone(test_item.task)
self.assertEquals("foo bar", test_item.task)
self.assertEquals(test_str + " " + "foo bar", test_item.todo_txt_line)
test_str = "(B)"
test_item = TodoItem(test_str)
test_item.task = "foo bar"
self.assertIsNotNone(test_item.task)
self.assertEquals("foo bar", test_item.task)
self.assertEquals(test_str + " " + "foo bar", test_item.todo_txt_line)
def test_set_priority_from_scratch(self):
test_str = "2012-09-15 bar baz @home"
test_item = TodoItem(test_str)
self.assertIsNone(test_item.priority)
test_item.priority = "D"
self.assertIsNotNone(test_item.priority)
self.assertEquals("(D) " + test_str, test_item.todo_txt_line)
def test_set_priority_exists(self):
test_str = "(A) 2012-09-15 bar baz @home"
test_item = TodoItem(test_str)
self.assertIsNotNone(test_item.priority)
test_item.priority = "D"
self.assertIsNotNone(test_item.priority)
self.assertEquals("D", test_item.priority)
self.assertEquals("(D) 2012-09-15 bar baz @home",
test_item.todo_txt_line)
if __name__ == "__main__":
print "This module is not generally intended to run stand-alone"
print "Running unit tests."
unittest.main()