-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-slice.py
executable file
·1050 lines (888 loc) · 28.5 KB
/
test-slice.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
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
from contextlib import contextmanager
from datetime import date
import imp
import logging
import os.path
import unittest
slice = imp.load_source("slice", "slice")
AbstractTodoEnv = slice.AbstractTodoEnv
Tag = slice.Tag
ContextTag = slice.ContextTag
ProjectTag = slice.ProjectTag
KeyValueTag = slice.KeyValueTag
@contextmanager
def capture(log, level):
records = []
class MemoryHandler(logging.Handler):
def emit(self, record):
records.append(record)
h = MemoryHandler()
h.setLevel(level)
log.addHandler(h)
yield records
log.removeHandler(h)
class VirtualTodoEnv(AbstractTodoEnv, unittest.TestCase):
__editor_path = "EDITOR"
__todo_file_name = "todo.txt"
__edit_dir_path = "EDIT"
__edit_file_path = os.path.join(__edit_dir_path, __todo_file_name)
__todo_dir_path = "TODO"
__todo_file_path = os.path.join(__todo_dir_path, __todo_file_name)
def __init__(self, expect_clean_exit, todo0, edit0, edit1, todo1, strip_edit0_comments, export, unset):
unittest.TestCase.__init__(self)
self.__expect_clean_exit = expect_clean_exit
self.__todo0 = todo0
self.__edit0 = edit0
self.__edit1 = edit1
self.__todo1 = todo1
self.__strip_edit0_comments = strip_edit0_comments
self.__edit_dir_deleted = False
self.__edit_file_path_written = False
self.__todo_file_path_written = False
os_environ = {
"TODO_DIR": self.__todo_dir_path,
"TODO_FILE": self.__todo_file_path,
"EDITOR": self.__editor_path,
"TODOTXT_DATE_ON_ADD": "0",
"TODOTXT_PRESERVE_LINE_NUMBERS": "1",
"TODOTXT_DISABLE_FILTER": "0",
}
os_environ.update(export)
for key in unset:
del os_environ[key]
AbstractTodoEnv.__init__(self, os_environ)
def today(self):
return date(2000, 1, 1)
def read_lines(self, path):
if path == self.__todo_file_path:
return self.__todo0
elif path == self.__edit_file_path:
return self.__edit1
else:
self.fail("attempt to read unknown path: %s" % path)
def write_lines(self, path, lines):
if path == self.__todo_file_path:
self.assertEqual(self.__todo1, lines, msg = "Todo file content does not match expected content")
self.__todo_file_path_written = True
elif path == self.__edit_file_path:
testable_lines = [line for line in lines if not line.startswith("#") and line != ""] if self.__strip_edit0_comments else lines
self.assertEqual(self.__edit0, testable_lines, msg = "Slice file content does not match expected content")
self.__edit_file_path_written = True
else:
self.fail("attempt to write unknown path: %s" % path)
@contextmanager
def create_temp_dir(self):
self.__edit_dir_deleted = False
yield self.__edit_dir_path
self.__edit_dir_deleted = True
def subprocess_check_call(self, path, args):
self.assertEqual(self.__editor_path, path)
self.assertEqual([self.__edit_file_path], args)
def print_diff(self, id, max_id_len, task_a, task_b):
self.assertLessEqual(len(str(id)), max_id_len, msg = "Expected id (%d) to have length <= %d" % (id, max_id_len))
self.assertNotEqual(task_a, task_b)
def assert_success(self):
if self.__expect_clean_exit:
self.assertTrue(self.__edit_dir_deleted, msg = "Expected edit directory to be used and cleaned up")
self.assertTrue(self.__edit_file_path_written, msg = "Expected edit file to be written")
changes = self.__todo0 != self.__todo1
if changes:
self.assertTrue(self.__todo_file_path_written, msg = "Expected todo file to be written")
else:
self.assertFalse(self.__todo_file_path_written, msg = "Expected todo file to be untouched as there were no changes")
else:
self.assertFalse(self.__todo_file_path_written, msg = "Expected todo file to be untouched")
class TagTest(unittest.TestCase):
def test_join_tokens(self):
a = ContextTag("a")
b = ContextTag("b")
# trivial cases
self.__test_join_tokens([], "")
self.__test_join_tokens([" "], "")
self.__test_join_tokens(["\t"], "")
self.__test_join_tokens(["x"], "x")
self.__test_join_tokens([a], "@a")
# one token supplies whitespace - simple join
self.__test_join_tokens(["x", "\ty"], "x\ty")
self.__test_join_tokens(["x\t", "y"], "x\ty")
self.__test_join_tokens([a, "\tx"], "@a\tx")
self.__test_join_tokens(["x\t", a], "x\t@a")
# no whitespace between tokens - space inserted
self.__test_join_tokens([a, "x"], "@a x")
self.__test_join_tokens(["x", a], "x @a")
self.__test_join_tokens(["x", "y"], "x y")
self.__test_join_tokens([a, b], "@a @b")
# both tokens supply whitespace - drop second
self.__test_join_tokens(["x ", "\ty"], "x y")
self.__test_join_tokens(["x\t", " y"], "x\ty")
# three tokens
self.__test_join_tokens(["x", "\t", "y"], "x\ty")
self.__test_join_tokens(["x\t", " ", " y"], "x\ty")
self.__test_join_tokens([a, "\t", b], "@a\t@b")
def __test_join_tokens(self, tokens, expected):
result = Tag.join_tokens(tokens)
self.assertEqual(expected, result, msg = "Expected Tag.join_tokens(%s) to equal '%s'" % (tokens, expected))
def test_sort_edge_tags(self):
c = ContextTag("c")
p = ProjectTag("p")
kv = KeyValueTag("k", "v")
# trivial cases
self.__test_sort_edge_tags([], [], trailing = True)
self.__test_sort_edge_tags([], [], trailing = False)
self.__test_sort_edge_tags(["x"], ["x"], trailing = True)
self.__test_sort_edge_tags(["x"], ["x"], trailing = False)
# no string tokens
self.__test_sort_edge_tags([c], [c], trailing = True)
self.__test_sort_edge_tags([c], [c], trailing = False)
# correct sort order
self.__test_sort_edge_tags([p, kv, c], [c, p, kv], trailing = True)
self.__test_sort_edge_tags([p, kv, c], [c, p, kv], trailing = False)
# sorts at correct end
self.__test_sort_edge_tags([p, c, "x", p, c], [c, p, "x", p, c], trailing = False)
self.__test_sort_edge_tags([p, c, "x", p, c], [p, c, "x", c, p], trailing = True)
# sorts to first non-whitespace token
self.__test_sort_edge_tags([p, " ", c, "x"], [c, p, "x"], trailing = False)
self.__test_sort_edge_tags(["x", p, " ", c], ["x", c, p], trailing = True)
def __test_sort_edge_tags(self, tokens, expected, trailing):
result = Tag.sort_edge_tags(tokens, trailing)
self.assertEqual(expected, result, msg = "Expected Tag.sort_edge_tags(%s) to equal '%s'" % (tokens, expected))
class AbstractSliceTest:
action_name = "slice"
def run_test(
self,
slice_args = [],
expect_clean_exit = True,
expect_warnings = False,
todo0 = None,
edit0 = None,
edit1 = None,
todo1 = None,
strip_edit0_comments = True,
export = {},
unset = set()
):
args = ["dummy.py"]
args.append(self.action_name)
args.append(self.slice_name)
args.extend(slice_args)
export_with_defaults = self.export.copy()
export_with_defaults.update(export),
env = VirtualTodoEnv(
expect_clean_exit = expect_clean_exit,
todo0 = todo0,
edit0 = edit0,
edit1 = edit1 if edit1 is not None else edit0,
todo1 = todo1 if todo1 is not None else todo0,
strip_edit0_comments = strip_edit0_comments,
export = export_with_defaults,
unset = unset
)
with capture(logging.getLogger("slice"), logging.WARN) as warnings:
if expect_clean_exit:
slice.main(env, args)
else:
with self.assertRaises(SystemExit):
slice.main(env, args)
have_warnings = len(warnings) > 0
if expect_warnings:
self.assertTrue(have_warnings, "Expected warnings")
else:
self.assertFalse(have_warnings, msg = "Expected no warnings: %s" % [w.getMessage() for w in warnings])
env.assert_success()
# the tests in this class should work with any slice as the todo file either starts empty, or causes a fatal error
def test_editor_required(self):
self.run_test(
todo0 = [],
edit0 = [],
unset = {"EDITOR"},
expect_warnings = True,
expect_clean_exit = False
)
def test_no_tasks(self):
self.run_test(
todo0 = [],
edit0 = []
)
def test_insert_task(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x"],
todo1 = ["x"],
)
# regression test
def test_insert_task_with_priority(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["(A) x"],
todo1 = ["(A) x"],
)
def test_insert_task_with_date(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x"],
todo1 = ["2000-01-01 x"],
export = {"TODOTXT_DATE_ON_ADD": "1"}
)
def test_refuse_to_edit_if_existing_task_looks_like_comment(self):
self.run_test(
todo0 = ["# x"],
expect_warnings = True,
expect_clean_exit = False
)
def test_ignore_comments_in_edit(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["# x"],
todo1 = [],
)
def test_leading_tag_order_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["k:v +p @c x"],
todo1 = ["@c +p k:v x"],
)
def test_trailing_tag_order_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x +p @c k:v"],
todo1 = ["x @c +p k:v"],
)
def test_intermediate_tag_order_not_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x +p @c k:v y"],
todo1 = ["x +p @c k:v y"],
)
def test_duplicate_contexts_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x @c @c"],
todo1 = ["x @c"],
expect_warnings = True
)
def test_duplicate_projects_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x +p +p"],
todo1 = ["x +p"],
expect_warnings = True
)
def test_duplicate_key_value_tags_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x k:v1 k:v1"],
todo1 = ["x k:v1"],
expect_warnings = True
)
# the spec is unclear on whether duplicates are permitted here
# let's err on the side of caution and assume they are permitted
def test_key_value_tags_with_same_key_and_different_values_not_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x k:v1 k:v2"],
todo1 = ["x k:v1 k:v2"],
expect_warnings = False
)
def test_redundant_start_date_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["past t:1999-12-31", "present t:2000-01-01", "future t:2000-01-02"],
todo1 = ["past", "present", "future t:2000-01-02"],
)
def test_completed_with_priority_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["x 2000-01-01 (A) complete"],
todo1 = ["x 2000-01-01 complete"]
)
# regression test
def test_explicit_no_level_normalized(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["(_) new"],
todo1 = ["new"]
)
def test_unknown_id_tag_ignored(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["i:42 x"],
todo1 = ["x"],
expect_warnings = True
)
# regression test
def test_invalid_id_tag_ignored(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["i:foo x"],
todo1 = ["x"],
expect_warnings = True
)
# regression test
def test_tags_not_matched_without_preceding_whitespace_or_start_of_string(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["word@x word@@x word+x word++x"],
todo1 = ["word@x word@@x word+x word++x"]
)
class AbstractSliceAllTest(AbstractSliceTest):
def test_comment_header(self):
self.run_test(
todo0 = [],
edit0 = ["# All tasks", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_single_task(self):
self.run_test(
todo0 = ["task"],
edit0 = ["i:1 task"]
)
def test_tasks_sorted(self):
self.run_test(
todo0 = ["(C) c", "(B) b", "(A) a"],
edit0 = ["(A) i:3 a", "(B) i:2 b", "(C) i:1 c"]
)
def test_completed_tasks_hidden(self):
self.run_test(
todo0 = ["x 2000-01-01 done"],
edit0 = []
)
def test_completed_tasks_not_hidden(self):
self.run_test(
todo0 = ["x 2000-01-01 done"],
edit0 = ["x 2000-01-01 i:1 done"],
export = {"TODOTXT_DISABLE_FILTER": "1"}
)
def test_future_tasks_hidden(self):
self.run_test(
todo0 = ["past t:1999-12-31", "present t:2000-01-01", "future t:2000-01-02"],
edit0 = ["i:1 past t:1999-12-31", "i:2 present t:2000-01-01"]
)
def test_future_tasks_not_hidden(self):
self.run_test(
todo0 = ["past t:1999-12-31", "present t:2000-01-01", "future t:2000-01-02"],
edit0 = ["i:1 past t:1999-12-31", "i:2 present t:2000-01-01", "i:3 future t:2000-01-02"],
export = {"TODOTXT_DISABLE_FILTER": "1"}
)
def test_remove_task(self):
self.run_test(
todo0 = ["x"],
edit0 = ["i:1 x"],
edit1 = [],
todo1 = [],
)
def test_edit_task(self):
self.run_test(
todo0 = ["a", "b"],
edit0 = ["i:1 a", "i:2 b"],
edit1 = ["i:1 x", "i:2 b"],
todo1 = ["x", "b"],
)
def test_empty_line_preserved(self):
self.run_test(
todo0 = ["", "orig"],
edit0 = ["i:2 orig"],
edit1 = ["i:2 orig"],
todo1 = ["", "orig"]
)
def test_empty_line_unchanged_if_no_other_edits(self):
self.run_test(
todo0 = ["", "orig"],
edit0 = ["i:2 orig"],
edit1 = ["i:2 orig"],
todo1 = ["", "orig"],
export = {"TODOTXT_PRESERVE_LINE_NUMBERS": "0"}
)
def test_empty_line_not_preserved_when_other_edits(self):
self.run_test(
todo0 = ["", "orig"],
edit0 = ["i:2 orig"],
edit1 = ["i:2 changed"],
todo1 = ["changed"],
export = {"TODOTXT_PRESERVE_LINE_NUMBERS": "0"}
)
# regression test
def test_insert_task_empty_line_preserved(self):
self.run_test(
todo0 = ["", "orig"],
edit0 = ["i:2 orig"],
edit1 = ["i:2 orig", "new"],
todo1 = ["", "orig", "new"]
)
# regression test
def test_insert_task_empty_line_not_preserved(self):
self.run_test(
todo0 = ["", "orig"],
edit0 = ["i:2 orig"],
edit1 = ["i:2 orig", "new"],
todo1 = ["orig", "new"],
export = {"TODOTXT_PRESERVE_LINE_NUMBERS": "0"}
)
def test_leading_tag_order_not_normalized_if_no_other_edits(self):
self.run_test(
todo0 = ["k:v +p @c x"],
edit0 = ["i:1 k:v +p @c x"],
)
def test_leading_tag_order_normalized_if_other_edits(self):
self.run_test(
todo0 = ["k:v +p @c x"],
edit0 = ["i:1 k:v +p @c x"],
edit1 = ["i:1 k:v +p @c y"],
todo1 = ["@c +p k:v y"],
)
def test_trailing_tag_order_not_normalized_if_no_other_edits(self):
self.run_test(
todo0 = ["x k:v +p @c"],
edit0 = ["i:1 x k:v +p @c"],
)
def test_trailing_tag_order_normalized_if_other_edits(self):
self.run_test(
todo0 = ["x k:v +p @c"],
edit0 = ["i:1 x k:v +p @c"],
edit1 = ["i:1 y k:v +p @c"],
todo1 = ["y @c +p k:v"],
)
# regression test
def test_can_manually_make_changes_equal_to_normalization_even_if_no_other_edits(self):
self.run_test(
todo0 = ["x t:2000-01-01"],
edit0 = ["i:1 x t:2000-01-01"],
edit1 = ["i:1 x"],
todo1 = ["x"],
)
# regression test
def test_url_is_not_considered_tag(self):
self.run_test(
todo0 = ["http://example.com @c"],
edit0 = ["i:1 http://example.com @c"]
)
def test_duplicate_id_tag_ignored(self):
self.run_test(
todo0 = ["a"],
edit0 = ["i:1 a"],
edit1 = ["i:1 i:1 x"],
todo1 = ["x"],
expect_warnings = True
)
def test_hides_but_preserves_date(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(A) i:1 a"]
)
class SliceAllTest(AbstractSliceAllTest, unittest.TestCase):
slice_name = "all"
export = {}
# Any tests for "all" should go in AbstractSliceAllTest instead,
# so the tests for the "terms" and "tags" slices can inherit them too.
# The "terms" and "tags" slices should behave identically when they have no arguments.
class SliceTermsTest(AbstractSliceAllTest, unittest.TestCase):
slice_name = "terms"
export = {}
def test_comment_header_included_terms(self):
self.run_test(
slice_args = ["x", "y"],
todo0 = [],
edit0 = ["# Tasks including terms: x y", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_comment_header_excluded_terms(self):
self.run_test(
slice_args = ["-x", "-y"],
todo0 = [],
edit0 = ["# Tasks excluding terms: x y", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_comment_header_included_and_excluded_terms(self):
self.run_test(
slice_args = ["x", "-y"],
todo0 = [],
edit0 = ["# Tasks including terms: x and excluding terms: y", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_match_task_with_term(self):
self.run_test(
slice_args = ["x"],
todo0 = ["x", "y"],
edit0 = ["i:1 x"]
)
# regression test
def test_match_task_with_term_case_insensitive(self):
self.run_test(
slice_args = ["X"],
todo0 = ["x", "y"],
edit0 = ["i:1 x"]
)
def test_match_task_without_excluded_term(self):
self.run_test(
slice_args = ["-x"],
todo0 = ["x", "y"],
edit0 = ["i:2 y"]
)
# regression test
def test_match_task_without_excluded_term_case_insensitive(self):
self.run_test(
slice_args = ["-X"],
todo0 = ["x", "y"],
edit0 = ["i:2 y"]
)
def test_match_task_with_multiple_terms(self):
self.run_test(
slice_args = ["x", "y1"],
todo0 = ["x y1", "y1 x", "x y2"],
edit0 = ["i:1 x y1", "i:2 y1 x"]
)
def test_match_task_with_included_and_without_excluded_terms(self):
self.run_test(
slice_args = ["x", "-y1"],
todo0 = ["x y1", "y1 x", "x y2"],
edit0 = ["i:3 x y2"]
)
def test_does_not_strip_tag(self):
self.run_test(
slice_args = ["@c"],
todo0 = ["x", "a @c"],
edit0 = ["i:2 a @c"]
)
class SliceTagsTest(AbstractSliceAllTest, unittest.TestCase):
slice_name = "tags"
export = {}
def test_comment_header_priority(self):
self.run_test(
slice_args = ["A"],
todo0 = [],
edit0 = ["# Tasks with priority (A)", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
# regression test
def test_comment_header_no_level_priority(self):
self.run_test(
slice_args = ["_"],
todo0 = [],
edit0 = ["# Tasks with priority (_)", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_comment_header_tags(self):
self.run_test(
slice_args = ["@c"],
todo0 = [],
edit0 = ["# Tasks with tags: @c", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_comment_header_priority_and_tags(self):
self.run_test(
slice_args = ["A", "@c"],
todo0 = [],
edit0 = ["# Tasks with priority (A) and tags: @c", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)
def test_match_task_with_priority(self):
self.run_test(
slice_args = ["A"],
todo0 = ["x", "(A) a"],
edit0 = ["i:2 a"]
)
def test_match_task_with_no_level_priority(self):
self.run_test(
slice_args = ["_"],
todo0 = ["x", "(A) a"],
edit0 = ["i:1 x"]
)
def test_match_task_with_context(self):
self.run_test(
slice_args = ["@c"],
todo0 = ["x", "a @c"],
edit0 = ["i:2 a"]
)
def test_match_task_with_project(self):
self.run_test(
slice_args = ["+p"],
todo0 = ["x", "a +p"],
edit0 = ["i:2 a"]
)
def test_match_task_with_kv(self):
self.run_test(
slice_args = ["k:v"],
todo0 = ["x", "a k:v"],
edit0 = ["i:2 a"]
)
# regression test
def test_unparseable_tag(self):
self.run_test(
slice_args = ["not_a_tag"],
todo0 = [],
edit0 = [],
expect_warnings = True,
expect_clean_exit = False
)
def test_forged_id_tag_ignored(self):
self.run_test(
slice_args = ["A"],
todo0 = ["(B) b"],
edit0 = [],
edit1 = ["i:1 a"],
todo1 = ["(B) b", "(A) a"],
expect_warnings = True
)
def test_insert_task_with_no_level_priority(self):
self.run_test(
slice_args = ["_"],
todo0 = [],
edit0 = [],
edit1 = ["y"],
todo1 = ["y"]
)
def test_insert_task_with_duplicate_tag(self):
self.run_test(
slice_args = ["@c"],
todo0 = [],
edit0 = [],
edit1 = ["y @c"],
todo1 = ["y @c"]
)
def test_insert_task_with_multiple_tags(self):
self.run_test(
slice_args = ["A", "@c", "+p", "k:v"],
todo0 = [],
edit0 = [],
edit1 = ["y"],
todo1 = ["(A) y @c +p k:v"]
)
def test_edit_task_with_multiple_tags(self):
self.run_test(
slice_args = ["A", "@c", "+p", "k:v"],
todo0 = ["x", "(A) a @c +p k:v", "(A) a +q"],
edit0 = ["i:2 a"],
edit1 = ["i:2 y"],
todo1 = ["x", "(A) y @c +p k:v", "(A) a +q"]
)
# regression test
def test_edit_task_explicitly_readding_hidden_tag(self):
self.run_test(
slice_args = ["@c"],
todo0 = ["a @c"],
edit0 = ["i:1 a"],
edit1 = ["i:1 a @c"],
todo1 = ["a @c"]
)
class SliceReviewTest(AbstractSliceTest, unittest.TestCase):
slice_name = "review"
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": ""}
def test_comment_header(self):
self.run_test(
todo0 = [],
edit0 = ["# Reviewable tasks (A:1)", ""],
edit1 = [],
todo1 = [],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
strip_edit0_comments = False
)
def test_slice_review_intervals_required(self):
self.run_test(
todo0 = [],
edit0 = [],
unset = {"TODOTXT_SLICE_REVIEW_INTERVALS"},
expect_warnings = True
)
def test_reviewable_by_age(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(_) i:1 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
)
def test_not_reviewable_by_age(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = [],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:2"},
)
def test_reviewable_by_priority(self):
self.run_test(
todo0 = ["(A) 2000-01-01 a", "(B) 2000-01-01 b"],
edit0 = ["(_) i:1 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:0,B:1"},
)
def test_reviewable_by_no_priority(self):
self.run_test(
todo0 = ["2000-01-01 a", "(B) 2000-01-01 b"],
edit0 = ["(_) i:1 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "_:0,B:1"},
)
def test_unconfigured_priority_ignored(self):
self.run_test(
todo0 = ["(A) 2000-01-01 a", "(B) 2000-01-01 b"],
edit0 = [],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
expect_warnings = True
)
# regression test
def test_unconfigured_no_priority_ignored(self):
self.run_test(
todo0 = ["(A) 2000-01-01 a", "2000-01-01 b"],
edit0 = [],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
expect_warnings = True
)
def test_reviewable_by_start_date(self):
self.run_test(
todo0 = ["1999-12-31 a t:2000-01-01", "1999-12-31 b t:2000-01-02"],
edit0 = ["(_) i:1 a t:2000-01-01"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "_:5"},
)
def test_set_complete_date_does_not_reset_create_date(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(_) i:1 a"],
edit1 = ["x 2000-01-01 (_) i:1 a"],
todo1 = ["x 2000-01-01 1999-12-31 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
)
def test_set_complete_date_clears_start_date(self):
self.run_test(
todo0 = ["1999-12-31 a t:2000-01-01"],
edit0 = ["(_) i:1 a t:2000-01-01"],
edit1 = ["x 2000-01-01 (_) i:1 a t:2000-01-01"],
todo1 = ["x 2000-01-01 1999-12-31 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "_:5"},
)
def test_set_start_date_resets_create_date(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(_) i:1 a"],
edit1 = ["(_) i:1 a t:2001-01-02"],
todo1 = ["(A) 2000-01-01 a t:2001-01-02"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
)
def test_set_start_date_does_not_clear_start_date(self):
self.run_test(
todo0 = ["1999-12-31 a t:2000-01-01"],
edit0 = ["(_) i:1 a t:2000-01-01"],
edit1 = ["(_) i:1 a t:2001-01-02"],
todo1 = ["2000-01-01 a t:2001-01-02"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "_:5"},
)
def test_set_priority_resets_create_date(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(_) i:1 a"],
edit1 = ["(B) i:1 a"],
todo1 = ["(B) 2000-01-01 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
)
def test_set_priority_clears_start_date(self):
self.run_test(
todo0 = ["1999-12-31 a t:2000-01-01"],
edit0 = ["(_) i:1 a t:2000-01-01"],
edit1 = ["(B) i:1 a t:2000-01-01"],
todo1 = ["(B) 2000-01-01 a"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "_:5"},
)
def test_edits_preserved(self):
self.run_test(
todo0 = ["(A) 1999-12-31 a"],
edit0 = ["(_) i:1 a"],
edit1 = ["(_) i:1 b"],
todo1 = ["(A) 1999-12-31 b"],
export = {"TODOTXT_SLICE_REVIEW_INTERVALS": "A:1"},
)
# regression test
def test_insert_hidden(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["a t:2000-01-02"],
todo1 = ["a t:2000-01-02"],
export = {"TODOTXT_DATE_ON_ADD": "0"}
)
# regression test
def test_insert_hidden_with_date(self):
self.run_test(
todo0 = [],
edit0 = [],
edit1 = ["a t:2000-01-02"],
todo1 = ["2000-01-01 a t:2000-01-02"],
export = {"TODOTXT_DATE_ON_ADD": "1"}
)
class SliceFutureTest(AbstractSliceTest, unittest.TestCase):
slice_name = "future"
export = {}
def test_comment_header(self):
self.run_test(
todo0 = [],
edit0 = ["# Future tasks", ""],
edit1 = [],
todo1 = [],
strip_edit0_comments = False
)