Repository navigation
Expand file tree
/
Copy pathtest_basic.py
More file actions
405 lines (330 loc) · 11.3 KB
/
Copy pathtest_basic.py
File metadata and controls
405 lines (330 loc) · 11.3 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import datetime
import hypothesis.strategies as st
import pytest
import pytz
from dateutil.tz import tzlocal
from freezegun import freeze_time
from hypothesis import given
from todoman.cli import cli
from todoman.model import Database, FileTodo
def test_basic(tmpdir, runner, create):
result = runner.invoke(cli, ['list'], catch_exceptions=False)
assert not result.exception
assert result.output == ''
create(
'test.ics',
'SUMMARY:harhar\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'harhar' in result.output
def test_percent(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:harhar\n'
'PERCENT-COMPLETE:78\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert '78%' in result.output
def test_list_inexistant(tmpdir, runner, create):
result = runner.invoke(cli, ['list', 'nonexistant'])
assert result.exception
assert 'Error: Invalid value for "lists":' in result.output
def test_show_existing(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:harhar\n'
'DESCRIPTION:Lots of text. Yum!\n'
)
result = runner.invoke(cli, ['list'])
result = runner.invoke(cli, ['show', '1'])
assert not result.exception
assert 'harhar' in result.output
assert 'Lots of text. Yum!' in result.output
def test_show_inexistant(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:harhar\n'
)
result = runner.invoke(cli, ['list'])
result = runner.invoke(cli, ['show', '2'])
assert result.exit_code == -2
assert result.output == 'No todo with id 2.\n'
def test_human(runner):
result = runner.invoke(cli, [
'new', '-l', 'default', '-d', 'tomorrow', 'hail belzebub'
])
assert not result.exception
assert 'belzebub' in result.output
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'belzebub' in result.output
@pytest.mark.xfail(reason='issue#9')
def test_two_events(tmpdir, runner):
tmpdir.join('default/test.ics').write(
'BEGIN:VCALENDAR\n'
'BEGIN:VTODO\n'
'SUMMARY:task one\n'
'END:VTODO\n'
'BEGIN:VTODO\n'
'SUMMARY:task two\n'
'END:VTODO\n'
'END:VCALENDAR'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert len(result.output.splitlines()) == 2
assert 'task one' in result.output
assert 'task two' in result.output
def test_default_command(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:harhar\n'
)
result = runner.invoke(cli)
assert not result.exception
assert 'harhar' in result.output
def test_delete(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:harhar\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
result = runner.invoke(cli, ['delete', '1', '--yes'])
assert not result.exception
result = runner.invoke(cli, ['list'])
assert not result.exception
assert len(result.output.splitlines()) == 0
def test_copy(tmpdir, runner, create):
tmpdir.mkdir('other_list')
create(
'test.ics',
'SUMMARY:test_copy\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'test_copy' in result.output
assert 'default' in result.output
assert 'other_list' not in result.output
result = runner.invoke(cli, ['copy', '-l', 'other_list', '1'])
assert not result.exception
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'test_copy' in result.output
assert 'default' in result.output
assert 'other_list' in result.output
def test_move(tmpdir, runner, create):
tmpdir.mkdir('other_list')
create(
'test.ics',
'SUMMARY:test_move\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'test_move' in result.output
assert 'default' in result.output
assert 'other_list' not in result.output
result = runner.invoke(cli, ['move', '-l', 'other_list', '1'])
assert not result.exception
result = runner.invoke(cli, ['list'])
assert not result.exception
assert 'test_move' in result.output
assert 'default' not in result.output
assert 'other_list' in result.output
def test_dtstamp(tmpdir, runner, create):
"""
Test that we add the DTSTAMP to new entries as per RFC5545.
"""
result = runner.invoke(cli, ['new', '-l', 'default', 'test event'])
assert not result.exception
db = Database([tmpdir.join('default')],
tmpdir.join('/dtstamp_cache'))
todo = list(db.todos())[0]
assert todo.dtstamp is not None
assert todo.dtstamp.tzinfo is pytz.utc
def test_default_list(tmpdir, runner, create):
"""Test the default_list config parameter"""
result = runner.invoke(cli, ['new', 'test default list'])
assert result.exception
path = tmpdir.join('config')
path.write('default_list = default\n', 'a')
result = runner.invoke(cli, ['new', 'test default list'])
assert not result.exception
db = Database([tmpdir.join('default')],
tmpdir.join('/default_list'))
todo = list(db.todos())[0]
assert todo.summary == 'test default list'
@pytest.mark.parametrize(
'default_due, expected_due_hours', [(None, 24), (1, 1), (0, None)],
ids=['not specified', 'greater than 0', '0']
)
def test_default_due(
tmpdir, runner, create, default_due, expected_due_hours
):
"""Test setting the due date using the default_due config parameter"""
if default_due is not None:
path = tmpdir.join('config')
path.write('default_due = {}\n'.format(default_due), 'a')
runner.invoke(cli, ['new', '-l', 'default', 'aaa'])
db = Database([tmpdir.join('default')], tmpdir.join('/default_list'))
todo = list(db.todos())[0]
if expected_due_hours is None:
assert todo.due is None
else:
assert (todo.due - todo.created_at) == datetime.timedelta(
hours=expected_due_hours
)
@freeze_time(datetime.datetime.now())
def test_default_due2(tmpdir, runner, create, default_database):
cfg = tmpdir.join('config')
cfg.write('default_due = 24\n', 'a')
r = runner.invoke(cli, ['new', '-ldefault', '-dtomorrow', 'aaa'])
assert not r.exception
r = runner.invoke(cli, ['new', '-ldefault', 'bbb'])
assert not r.exception
r = runner.invoke(cli, ['new', '-ldefault', '-d', 'one hour', 'ccc'])
assert not r.exception
default_database.update_cache()
todos = {t.summary: t for t in default_database.todos(all=True)}
assert todos['aaa'].due.date() == todos['bbb'].due.date()
assert todos['ccc'].due == todos['bbb'].due - datetime.timedelta(hours=23)
def test_sorting_fields(tmpdir, runner, default_database):
tasks = []
for i in range(1, 10):
days = datetime.timedelta(days=i)
todo = FileTodo(new=True)
todo.list = next(default_database.lists())
todo.due = datetime.datetime.now() + days
todo.created_at = datetime.datetime.now() - days
todo.summary = 'harhar{}'.format(i)
tasks.append(todo)
todo.save()
fields = (
'id',
'uid',
'summary',
'due',
'priority',
'created_at',
'completed_at',
'dtstamp',
'status',
'description',
'location',
'categories',
)
@given(sort_key=st.lists(
st.sampled_from(fields + tuple('-' + x for x in fields)),
unique=True
))
def run_test(sort_key):
sort_key = ','.join(sort_key)
result = runner.invoke(cli, ['list', '--sort', sort_key])
assert not result.exception
assert result.exit_code == 0
assert len(result.output.strip().splitlines()) == len(tasks)
run_test()
def test_sorting_output(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:aaa\n'
'DUE;VALUE=DATE-TIME;TZID=ART:20160102T000000\n'
)
create(
'test2.ics',
'SUMMARY:bbb\n'
'DUE;VALUE=DATE-TIME;TZID=ART:20160101T000000\n'
)
examples = [
('-summary', ['aaa', 'bbb']),
('due', ['aaa', 'bbb'])
]
# Normal sorting, reversed by default
all_examples = [(['--sort', key], order) for key, order in examples]
# Testing --reverse, same exact output
all_examples.extend((['--reverse', '--sort', key], order)
for key, order in examples)
# Testing --no-reverse
all_examples.extend((['--no-reverse', '--sort', key], reversed(order))
for key, order in examples)
for args, order in all_examples:
result = runner.invoke(cli, ['list'] + args)
assert not result.exception
lines = result.output.splitlines()
for i, task in enumerate(order):
assert task in lines[i]
def test_sorting_null_values(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:aaa\n'
'PRIORITY:9\n'
)
create(
'test2.ics',
'SUMMARY:bbb\n'
'DUE;VALUE=DATE-TIME;TZID=ART:20160101T000000\n'
)
result = runner.invoke(cli)
assert not result.exception
assert 'bbb' in result.output.splitlines()[0]
assert 'aaa' in result.output.splitlines()[1]
@pytest.
74BA
mark.parametrize('hours', [1, -1])
def test_color_due_dates(tmpdir, runner, create, hours):
due = datetime.datetime.now() + datetime.timedelta(hours=hours)
create(
'test.ics',
'SUMMARY:aaa\n'
'STATUS:IN-PROGRESS\n'
'DUE;VALUE=DATE-TIME;TZID=ART:{}\n'
.format(due.strftime('%Y%m%dT%H%M%S'))
)
result = runner.invoke(cli, ['--color', 'always'])
assert not result.exception
due_str = due.strftime('%Y-%m-%d')
if hours == 1:
assert result.output == \
' 1 [ ] {} aaa @default\x1b[0m\n'.format(due_str)
else:
assert result.output == \
' 1 [ ] \x1b[31m{}\x1b[0m aaa @default\x1b[0m\n'.format(due_str)
def test_flush(tmpdir, runner, create):
create(
'test.ics',
'SUMMARY:aaa\n'
'STATUS:COMPLETED\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
create(
'test2.ics',
'SUMMARY:bbb\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert ' 2 [ ] bbb @default' in result.output
result = runner.invoke(cli, ['flush'], input='y\n', catch_exceptions=False)
assert not result.exception
create(
'test2.ics',
'SUMMARY:bbb\n'
)
result = runner.invoke(cli, ['list'])
assert not result.exception
assert ' 1 [ ] bbb @default' in result.output
def test_edit(runner, default_database):
todo = FileTodo()
todo.list = next(default_database.lists())
todo.summary = 'Eat paint'
todo.due = datetime.datetime(2016, 10, 3)
todo.save()
result = runner.invoke(cli, ['edit', '1', '--due', '2017-02-01'])
assert not result.exception
assert '2017-02-01' in result.output
default_database.update_cache()
todo = next(default_database.todos(all=True))
assert todo.due == datetime.datetime(2017, 2, 1, tzinfo=tzlocal())
assert todo.summary == 'Eat paint'
# TODO: test aware/naive datetime sorting
# TODO: test --grep