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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
|
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
#
###############################################################################
import sys
import os
import unittest
import datetime
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase
class TestFilter(TestCase):
@classmethod
def setUpClass(cls):
cls.t = Task()
cls.t("add project:A prio:H +tag one foo")
cls.t("add project:A prio:H two")
cls.t("add project:A three")
cls.t("add prio:H four")
cls.t("add +tag five")
cls.t("add six foo")
cls.t("add prio:L seven bar foo")
def test_list(self):
"""filter - list"""
code, out, err = self.t("list")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertIn("four", out)
self.assertIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_list_projectA(self):
"""filter - list project:A"""
code, out, err = self.t("list project:A")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_priorityH(self):
"""filter - list priority:H"""
code, out, err = self.t("list priority:H")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertNotIn("three", out)
self.assertIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_priority(self):
"""filter - list priority:"""
code, out, err = self.t("list priority:")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
self.assertNotIn("four", out)
self.assertIn("five", out)
self.assertIn("six", out)
self.assertNotIn("seven", out)
def test_list_substring(self):
"""filter - list /foo/"""
code, out, err = self.t("list /foo/")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_list_double_substring(self):
"""filter - list /foo/ /bar/"""
code, out, err = self.t("list /foo/ /bar/")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertIn("seven", out)
def test_list_include_tag(self):
"""filter - list +tag"""
code, out, err = self.t("list +tag")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_exclude_tag(self):
"""filter - list -tag"""
code, out, err = self.t("list -tag")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertIn("four", out)
self.assertNotIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_list_non_existing_tag(self):
"""filter - list -missing"""
code, out, err = self.t("list -missing")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertIn("four", out)
self.assertIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_list_mutually_exclusive_tag(self):
"""filter - list +tag -tag"""
code, out, err = self.t.runError("list +tag -tag")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priorityH(self):
"""filter - list project:A priority:H"""
code, out, err = self.t("list project:A priority:H")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priority(self):
"""filter - list project:A priority:"""
code, out, err = self.t("list project:A priority:")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_substring(self):
"""filter - list project:A /foo/"""
code, out, err = self.t("list project:A /foo/")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_tag(self):
"""filter - list project:A +tag"""
code, out, err = self.t("list project:A +tag")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priorityH_substring(self):
"""filter - list project:A priority:H /foo/"""
code, out, err = self.t("list project:A priority:H /foo/")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priorityH_tag(self):
"""filter - list project:A priority:H +tag"""
code, out, err = self.t("list project:A priority:H +tag")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priorityH_substring_tag(self):
"""filter - list project:A priority:H /foo/ +tag"""
code, out, err = self.t("list project:A priority:H /foo/ +tag")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_list_projectA_priorityH_substring_tag_substring(self):
"""filter - list project:A priority:H /foo/ +tag /baz/"""
code, out, err = self.t.runError("list project:A priority:H /foo/ +tag /baz/")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_regex_list_project(self):
"""filter - rc.regex:on list project ~ '[A-Z]'"""
code, out, err = self.t("rc.regex:on list project ~ \\'[A-Z]\\'")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_regex_list_project_any(self):
"""filter - rc.regex:on list project~."""
code, out, err = self.t("rc.regex:on list project ~ .")
self.assertIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
def test_regex_list_substring(self):
"""filter - rc.regex:on list /fo{2}/"""
code, out, err = self.t("rc.regex:on list /fo{2}/")
self.assertIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_regex_list_double_substring_wildcard(self):
"""filter - rc.regex:on list /f../ /b../"""
code, out, err = self.t("rc.regex:on list /f../ /b../")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertNotIn("six", out)
self.assertIn("seven", out)
def test_regex_list_substring_startswith(self):
"""filter - rc.regex:on list /^s/"""
code, out, err = self.t("rc.regex:on list /^s/")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertNotIn("five", out)
self.assertIn("six", out)
self.assertIn("seven", out)
def test_regex_list_substring_wildcard_startswith(self):
"""filter - rc.regex:on list /^.i/"""
code, out, err = self.t("rc.regex:on list /^.i/")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertIn("five", out)
self.assertIn("six", out)
self.assertNotIn("seven", out)
def test_regex_list_substring_or(self):
"""filter - rc.regex:on list /two|five/"""
code, out, err = self.t("rc.regex:on list /two|five/")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertNotIn("three", out)
self.assertNotIn("four", out)
self.assertIn("five", out)
self.assertNotIn("six", out)
self.assertNotIn("seven", out)
class TestFilterDue(TestCase):
def setUp(self):
self.t = Task()
self.t.config("due", "4")
self.t.config("dateformat", "m/d/Y")
just = datetime.datetime.now() + datetime.timedelta(days=3)
almost = datetime.datetime.now() + datetime.timedelta(days=5)
# NOTE: %-m and %-d are unix only
self.just = just.strftime("%-m/%-d/%Y")
self.almost = almost.strftime("%-m/%-d/%Y")
def test_due_filter(self):
"""due tasks filtered correctly"""
self.t("add one due:{0}".format(self.just))
self.t("add two due:{0}".format(self.almost))
self.t("add three due:today")
code, out, err = self.t("list due:today")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
code, out, err = self.t("list due.is:today")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
class TestBug1110(TestCase):
def setUp(self):
self.t = Task()
def test_status_is_case_insensitive(self):
"""filter - status:Completed / status:completed - behave the same"""
self.t("add ToBeCompleted")
self.t("1 done")
code, out, err = self.t("all status:Completed")
self.assertIn("ToBeCompleted", out)
code, out, err = self.t("all status:completed")
self.assertIn("ToBeCompleted", out)
class TestBug480A(TestCase):
@classmethod
def setUpClass(cls):
cls.t = Task()
cls.t.config("defaultwidth", "0")
cls.t("add one +ordinary")
cls.t("add two +@strange")
def test_long_plus_ordinary(self):
"""filter '@' in tags breaks filters: +ordinary"""
code, out, err = self.t("long +ordinary")
self.assertIn("one", out)
self.assertNotIn("two", out)
def test_long_minus_ordinary(self):
"""filter '@' in tags breaks filters: -ordinary"""
code, out, err = self.t("long -ordinary")
self.assertNotIn("one", out)
self.assertIn("two", out)
def test_long_plus_at_strange(self):
"""filter '@' in tags breaks filters: +@strange"""
code, out, err = self.t("long +@strange")
self.assertNotIn("one", out)
self.assertIn("two", out)
def test_long_minus_at_strange(self):
"""filter '@' in tags breaks filters: -@strange"""
code, out, err = self.t("long -@strange")
self.assertIn("one", out)
self.assertNotIn("two", out)
class TestEmptyFilter(TestCase):
def setUp(self):
self.t = Task()
def test_empty_filter_warning(self):
"""Modify tasks with no filter."""
self.t("add foo")
self.t("add bar")
code, out, err = self.t.runError("modify rc.allow.empty.filter=yes rc.confirmation=no priority:H")
self.assertIn("Command prevented from running.", err)
def test_empty_filter_error(self):
"""Modify tasks with no filter, and disallowed confirmation."""
self.t("add foo")
self.t("add bar")
code, out, err = self.t.runError("modify rc.allow.empty.filter=no priority:H")
self.assertIn("You did not specify a filter, and with the 'allow.empty.filter' value, no action is taken.", err)
class TestFilterPrefix(TestCase):
@classmethod
def setUpClass(cls):
"""Executed once before any test in the class"""
cls.t = Task()
cls.t.config("verbose", "nothing")
cls.t('add project:foo.uno priority:H +tag "one foo"' )
cls.t('add project:foo.dos priority:H "two"' )
cls.t('add project:foo.tres "three"' )
cls.t('add project:bar.uno priority:H "four"' )
cls.t('add project:bar.dos +tag "five"' )
cls.t('add project:bar.tres "six foo"' )
cls.t('add project:bazuno "seven bar foo"')
cls.t('add project:bazdos "eight bar foo"')
def test_list_all(self):
"""No filter shows all tasks."""
code, out, err = self.t('list')
self.assertIn('one', out)
self.assertIn('two', out)
self.assertIn('three', out)
self.assertIn('four', out)
self.assertIn('five', out)
self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
def test_list_project_foo(self):
"""Filter on project name."""
code, out, err = self.t('list project:foo')
self.assertIn('one', out)
self.assertIn('two', out)
self.assertIn('three', out)
self.assertNotIn('four', out)
self.assertNotIn('five', out)
self.assertNotIn('six', out)
self.assertNotIn('seven', out)
self.assertNotIn('eight', out)
def test_list_project_not_foo(self):
"""Filter on not project name."""
code, out, err = self.t('list project.not:foo')
self.assertNotIn('one', out)
self.assertNotIn('two', out)
self.assertNotIn('three', out)
self.assertIn('four', out)
self.assertIn('five', out)
self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
def test_list_project_startswith_bar(self):
"""Filter on project name start."""
code, out, err = self.t('list project.startswith:bar')
self.assertNotIn('one', out)
self.assertNotIn('two', out)
self.assertNotIn('three', out)
self.assertIn('four', out)
self.assertIn('five', out)
self.assertIn('six', out)
self.assertNotIn('seven', out)
self.assertNotIn('eight', out)
def test_list_project_ba(self):
"""Filter on project partial match."""
code, out, err = self.t('list project:ba')
self.assertNotIn('one', out)
self.assertNotIn('two', out)
self.assertNotIn('three', out)
self.assertIn('four', out)
self.assertIn('five', out)
self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
def test_list_description_has_foo(self):
"""Filter on description pattern."""
code, out, err = self.t('list description.has:foo')
self.assertIn('one', out)
self.assertNotIn('two', out)
self.assertNotIn('three', out)
self.assertNotIn('four', out)
self.assertNotIn('five', out)
self.assertIn('six', out)
self.assertIn('seven', out)
self.assertIn('eight', out)
class TestBug480B(TestCase):
def setUp(self):
self.t = Task()
self.t.config("defaultwidth", "0")
self.t("add one +t1")
self.t("add two +t2")
self.t("add three +t3")
def test_numbered_tags(self):
"""filter '-t1 -t2' doesn't work"""
code, out, err = self.t("list -t1")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
code, out, err = self.t("list -t1 -t2")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
code, out, err = self.t.runError("list -t1 -t2 -t3")
self.assertIn("No matches", err)
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
def test_numbered_at_tags(self):
"""filter '-t1 -t2' doesn't work when '@' characters are involved"""
self.t("1 modify +@1")
self.t("2 modify +@2")
self.t("3 modify +@3")
code, out, err = self.t("list -@1")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
code, out, err = self.t("list -@1 -@2")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
code, out, err = self.t.runError("list -@1 -@2 -@3")
self.assertIn("No matches", err)
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
def test_numbered_at_tags_punctuation(self):
"""filter '-t1 -t2' doesn't work with '@' characters and punctuation"""
self.t("1 modify +@foo.1")
self.t("2 modify +@foo.2")
self.t("3 modify +@foo.3")
code, out, err = self.t("list -@foo.1")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertIn("three", out)
code, out, err = self.t("list -@foo.1 -@foo.2")
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertIn("three", out)
code, out, err = self.t.runError("list -@foo.1 -@foo.2 -@foo.3")
self.assertIn("No matches", err)
self.assertNotIn("one", out)
self.assertNotIn("two", out)
self.assertNotIn("three", out)
class TestBug485(TestCase):
@classmethod
def setUp(cls):
cls.t = Task()
cls.t.config("verbose", "nothing")
cls.t("add one due:tomorrow recur:monthly")
cls.t("add two due:tomorrow recur:1month")
def test_filter_recur_monthly(self):
"""filter 'recur:monthly' doesn't list monthly tasks"""
code, out, err = self.t("list recur:monthly")
self.assertIn("one", out)
self.assertIn("two", out)
def test_filter_recur_1month(self):
"""filter 'recur:1month' doesn't list monthly tasks"""
code, out, err = self.t("list recur:1month")
self.assertIn("one", out)
self.assertIn("two", out)
class TestBug489(TestCase):
@classmethod
def setUp(cls):
cls.t = Task()
def test_filter_tagless_tasks(self):
"""tags.none: filters tagless tasks"""
self.t("add with +tag")
self.t("add without")
code, out, err = self.t("list tags.none:")
self.assertNotIn("with ", out)
self.assertIn("without", out)
class TestBug1600(TestCase):
def setUp(self):
self.t = Task()
def test_filter_plus_in_descriptions(self):
"""filter - description contains +"""
self.t("add foobar1")
self.t("add foobar2")
self.t("add foobar+")
code, out, err = self.t("all")
self.assertIn("foobar+", out)
self.assertIn("foobar1", out)
self.assertIn("foobar2", out)
code, out, err = self.t("all description.contains:'foobar\\+'")
self.assertIn("foobar+", out)
self.assertNotIn("foobar1", out)
self.assertNotIn("foobar2", out)
def test_filter_question_in_descriptions(self):
"""filter - description contains ? """
self.t("add foobar1")
self.t("add foo?bar")
code, out, err = self.t("all")
self.assertIn("foobar1", out)
self.assertIn("foo?bar", out)
code, out, err = self.t("all description.contains:'foo\\?bar'")
self.assertIn("foo?bar", out)
self.assertNotIn("foobar1", out)
def test_filter_brackets_in_descriptions(self):
"""filter - description contains [] """
self.t("add [foobar1]")
self.t("add [foobar2]")
code, out, err = self.t("all")
self.assertIn("[foobar1]", out)
self.assertIn("[foobar2]", out)
code, out, err = self.t("all description.contains:'\\[foobar1\\]'")
self.assertIn("[foobar1]", out)
self.assertNotIn("[foobar2]", out)
class TestBug1656(TestCase):
def setUp(self):
self.t = Task()
def test_report_filter_parenthesized(self):
"""default report filter parenthesized"""
self.t('add task1 +work')
self.t('add task2 +work')
self.t('1 done')
# Sanity check, next does not display completed tasks
code, out, err = self.t("next")
self.assertNotIn("task1", out)
self.assertIn("task2", out)
# The or in the filter should not cause ignoring the implicit
# report filter
code, out, err = self.t("next +home or +work")
self.assertNotIn("task1", out)
self.assertIn("task2", out)
class TestRange(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_date_range(self):
"""Verify tasks can be selected by dates ranges"""
self.t("add one due:2009-08-01")
self.t("add two due:2009-08-03")
self.t("add three due:2009-08-05")
code, out, err = self.t("due.after:2009-08-02 due.before:2009-08-05 ls")
self.assertNotIn("one", out)
self.assertIn("two", out)
self.assertNotIn("three", out)
class TestHasHasnt(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_has_hasnt(self):
"""Verify the 'has' and 'hasnt' attribute modifiers"""
self.t("add foo") # 1
self.t("add foo") # 2
self.t("2 annotate bar")
self.t("add foo") # 3
self.t("3 annotate bar")
self.t("3 annotate baz")
self.t("add bar") # 4
self.t("add bar") # 5
self.t("5 annotate foo")
self.t("add bar") # 6
self.t("6 annotate foo")
self.t("6 annotate baz")
self.t("add one") # 7
self.t("7 annotate two")
self.t("7 annotate three")
code, out, err = self.t("description.has:foo long")
self.assertIn("\n 1", out)
self.assertIn("\n 2", out)
self.assertIn("\n 3", out)
self.assertNotIn("\n 4", out)
self.assertIn("\n 5", out)
self.assertIn("\n 6", out)
self.assertNotIn("\n 7", out)
code, out, err = self.t("description.hasnt:foo long")
self.assertNotIn("\n 1", out)
self.assertNotIn("\n 2", out)
self.assertNotIn("\n 3", out)
self.assertIn("\n 4", out)
self.assertNotIn("\n 5", out)
self.assertNotIn("\n 6", out)
self.assertIn("\n 7", out)
class TestBefore(TestCase):
@classmethod
def setUpClass(cls):
"""Executed once before any test in the class"""
cls.t = Task()
cls.t('add foo entry:2008-12-22 start:2008-12-22')
cls.t('add bar entry:2009-04-17 start:2009-04-17')
def test_correctly_recorded_start(self):
"""Verify start dates properly recorded"""
code, out, err = self.t("_get 1.start")
self.assertEqual(out, "2008-12-22T00:00:00\n")
code, out, err = self.t("_get 2.start")
self.assertEqual(out, "2009-04-17T00:00:00\n")
def test_before_none(self):
"""Verify start.before:2008-12-01 yields nothing"""
code, out, err = self.t("start.before:2008-12-01 _ids")
self.assertNotIn("1", out)
self.assertNotIn("2", out)
def test_after_none(self):
"""Verify start.after:2009-05-01 yields nothing"""
code, out, err = self.t("start.after:2009-05-01 _ids")
self.assertNotIn("1", out)
self.assertNotIn("2", out)
def test_before_a(self):
"""Verify start.before:2009-01-01 yields '1'"""
code, out, err = self.t("start.before:2009-01-01 _ids")
self.assertIn("1", out)
self.assertNotIn("2", out)
def test_before_b(self):
"""Verify start.before:2009-05-01 yields '1' and '2'"""
code, out, err = self.t("start.before:2009-05-01 _ids")
self.assertIn("1", out)
self.assertIn("2", out)
def test_after_a(self):
"""Verify start.after:2008-12-01 yields '1' and '2'"""
code, out, err = self.t("start.after:2008-12-01 _ids")
self.assertIn("1", out)
self.assertIn("2", out)
def test_after_b(self):
"""Verify start.after:2009-01-01 yields '2'"""
code, out, err = self.t("start.after:2009-01-01 _ids")
self.assertNotIn("1", out)
self.assertIn("2", out)
class Test1424(TestCase):
def setUp(self):
self.t = Task()
def test_1824_days(self):
"""1424: Check that due:1824d works"""
self.t('add foo due:1824d')
code, out, err = self.t('_get 1.due.year')
# NOTE This test has a possible race condition when run "during" EOY.
# If Taskwarrior is executed at 23:59:59 on new year's eve and the
# python code below runs at 00:00:00 on new year's day, the two will
# disagree on the proper year. Using libfaketime with a frozen time
# or the date set to $year-01-01 might be a good idea here.
plus_1824d = datetime.datetime.today() + datetime.timedelta(days=1824)
self.assertEqual(out, "%d\n" % (plus_1824d.year))
def test_3648_days(self):
"""1424: Check that due:3648d works"""
self.t('add foo due:3648d')
code, out, err = self.t('_get 1.due.year')
# NOTE This test has a possible race condition when run "during" EOY.
# If Taskwarrior is executed at 23:59:59 on new year's eve and the
# python code below runs at 00:00:00 on new year's day, the two will
# disagree on the proper year. Using libfaketime with a frozen time
# or the date set to $year-01-01 might be a good idea here.
plus_3648d = datetime.datetime.today() + datetime.timedelta(days=3648)
self.assertEqual(out, "%d\n" % (plus_3648d.year))
# TODO This does not look right, it adds one task, exports it, and checks the UUID.
# The 'uuid:' filter could be ignored, and this test might pass.
class Test1452(TestCase):
def setUp(self):
self.t = Task()
self.t('add task')
self.task_uuid = self.t.export_one()['uuid']
def test_get_task_by_uuid_with_prefix(self):
"""1452: Tries to filter task simply by it's uuid, using uuid: prefix."""
output = self.t.export_one('uuid:%s' % self.task_uuid)
# Sanity check it is the correct one
self.assertEqual(output['uuid'], self.task_uuid)
def test_get_task_by_uuid_without_prefix(self):
"""1452: Tries to filter task simply by it's uuid, without using uuid: prefix."""
output = self.t.export_one(self.task_uuid)
# Sanity check it is the correct one
self.assertEqual(output['uuid'], self.task_uuid)
class TestBug1456(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_quoted_expressions(self):
"""1456: Verify that a multi-term quoted filter expression works"""
self.t("add zero")
self.t("add one")
self.t("add two")
code, out, err = self.t("'/one/ or /two/' list")
self.assertNotIn("zero", out)
self.assertIn("one", out)
self.assertIn("two", out)
class Test1468(TestCase):
def setUp(self):
self.t = Task()
self.t('add project:home buy milk')
self.t('add project:home mow the lawn')
def test_single_attribute_filter(self):
"""1468: Single attribute filter (project:home)"""
code, out, err = self.t('list project:home')
self.assertEqual(0, code, "Exit code was non-zero ({0})".format(code))
self.assertIn('buy milk', out)
self.assertIn('mow the lawn', out)
def test_attribute_and_search_filter(self):
"""1468: Attribute and implicit search filter (project:home /lawn/)"""
code, out, err = self.t('list project:home /lawn/')
self.assertEqual(0, code, "Exit code was non-zero ({0})".format(code))
self.assertNotIn('buy milk', out)
self.assertIn('mow the lawn', out)
class TestBug1521(TestCase):
@classmethod
def setUpClass(cls):
"""Executed once before any test in the class"""
cls.t = Task()
cls.t.config("verbose", "nothing")
cls.t("add one project:WORK")
cls.t("add two project:HOME")
def setUp(self):
"""Executed before each test in the class"""
def test_project_inequality(self):
"""1521: Verify that 'project.not' works"""
code, out, err = self.t("project.not:WORK list")
self.assertNotIn("one", out)
self.assertIn("two", out)
def test_project_not_equal(self):
"""1521: Verify that 'project !=' works"""
code, out, err = self.t("project != WORK list")
self.assertNotIn("one", out)
self.assertIn("two", out)
class TestBug1609(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_urgency_comparison(self):
"""1609: Test that urgency is filterable"""
self.t("add one project:P due:yesterday +tag1 +tag2")
self.t("add two")
code, out, err = self.t("'urgency<10' next")
self.assertNotIn("one", out)
self.assertIn("two", out)
class TestBug1630(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
self.t("add zero")
self.t("add one due:7d")
self.t("add two due:10d")
def test_attribute_modifier_with_duration(self):
"""1630: Verify that 'due.before:9d' is correctly interpreted"""
code, out, err = self.t("due.before:9d list rc.verbose:nothing")
self.assertNotIn("zero", out)
self.assertIn("one", out)
self.assertNotIn("two", out)
def test_attribute_no_modifier_with_duration(self):
"""1630: Verify that 'due:7d' is correctly interpreted"""
code, out, err = self.t("due:7d list rc.verbose:nothing")
self.assertNotIn("zero", out)
self.assertIn("one", out)
self.assertNotIn("two", out)
class Test1634(TestCase):
def setUp(self):
self.t = Task()
# Setup some tasks due on 2015-07-07
self.t('add due:2015-07-07T00:00:00 ON1')
self.t('add due:2015-07-07T14:34:56 ON2')
self.t('add due:2015-07-07T23:59:59 ON3')
# Setup some tasks not due on 2015-07-07
self.t('add due:2015-07-06T23:59:59 OFF4')
self.t('add due:2015-07-08T00:00:00 OFF5')
self.t('add due:2015-07-08T00:00:01 OFF6')
self.t('add due:2015-07-06T00:00:00 OFF7')
def test_due_match_not_exact(self):
"""1634: Test that due:<date> matches any task that date."""
code, out, err = self.t('due:2015-07-07 minimal')
# Asswer that only tasks ON the date are listed.
self.assertIn("ON1", out)
self.assertIn("ON2", out)
self.assertIn("ON3", out)
# Assert that tasks on other dates are not listed.
self.assertNotIn("OFF4", out)
self.assertNotIn("OFF5", out)
self.assertNotIn("OFF6", out)
self.assertNotIn("OFF7", out)
def test_due_not_match_not_exact(self):
"""1634: Test that due.not:<date> does not match any task that date."""
code, out, err = self.t('due.not:2015-07-07 minimal')
# Assert that task ON the date are not listed.
self.assertNotIn("ON1", out)
self.assertNotIn("ON2", out)
self.assertNotIn("ON3", out)
# Assert that tasks on other dates are listed.
self.assertIn("OFF4", out)
self.assertIn("OFF5", out)
self.assertIn("OFF6", out)
self.assertIn("OFF7", out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4 ft=python
|