def test_parse_expr_missing_brackets(self): expr = parse_expr(tokenise('true=false or true=true))'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('true=false or true=false))'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('true=true or true=false))'))[0] self.assertTrue(expr(None))
def test_parse_expr_accessing_missing_params(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise('flagged'))[0] self.assertFalse(expr(Folder(name="aabbccdd"))) expr = parse_expr(tokenise('due=today'), now=tue)[0] self.assertFalse(expr(Folder(name="aabbccdd")))
def test_parse_expr_accessing_missing_params (self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise ('flagged'))[0] self.assertFalse(expr (Folder(name="aabbccdd"))) expr = parse_expr(tokenise ('due=today'),now=tue)[0] self.assertFalse(expr (Folder(name="aabbccdd")))
def test_parse_expr_missing_brackets (self): expr = parse_expr(tokenise ('true=false or true=true))'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('true=false or true=false))'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('true=true or true=false))'))[0] self.assertTrue(expr (None))
def test_bug_2013_04_27(self): expr = parse_expr(tokenise('(type=Folder) and !name=".*Folder 2"'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) self.assertFalse(expr(Folder(name="xxx Folder 2"))) expr = parse_expr(tokenise('(type=Folder) and name!=".*Folder 2"'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) self.assertFalse(expr(Folder(name="xxx Folder 2")))
def test_bug_2013_04_27 (self): expr = parse_expr(tokenise ('(type=Folder) and !name=".*Folder 2"'))[0] self.assertTrue(expr (Folder(name="Miscellaneous"))) self.assertFalse(expr (Folder(name="xxx Folder 2"))) expr = parse_expr(tokenise ('(type=Folder) and name!=".*Folder 2"'))[0] self.assertTrue(expr (Folder(name="Miscellaneous"))) self.assertFalse(expr (Folder(name="xxx Folder 2")))
def test_parse_expr_not (self): expr = parse_expr(tokenise ('!true'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('!(true)'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('(!(true))'))[0] self.assertFalse(expr (None))
def test_bug_2013_04_28 (self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise ("flagged or true"), now=tue)[0] self.assertTrue(expr (Project())) expr = parse_expr(tokenise ("flagged or due=today"), now=tue)[0] self.assertFalse(expr (Project())) self.assertTrue(expr (Project(flagged=True))) self.assertTrue(expr (Project(date_due=tue)))
def test_bug_2013_04_28(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise("flagged or true"), now=tue)[0] self.assertTrue(expr(Project())) expr = parse_expr(tokenise("flagged or due=today"), now=tue)[0] self.assertFalse(expr(Project())) self.assertTrue(expr(Project(flagged=True))) self.assertTrue(expr(Project(date_due=tue)))
def test_parse_expr_not(self): expr = parse_expr(tokenise('!true'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('!(true)'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('(!(true))'))[0] self.assertFalse(expr(None))
def test_bug_2013_04_24 (self): expr = parse_expr(tokenise ('(type="Folder") and (name!="^Misc")'))[0] self.assertFalse(expr (Folder(name="Miscellaneous"))) expr = parse_expr(tokenise ('(type="Project") and (name="Misc")'))[0] self.assertTrue(expr (Project(name="Miscellaneous"))) self.assertFalse(expr (Project(name="xxx"))) expr = parse_expr(tokenise ('((type="Project") and (name="Misc"))'))[0] self.assertTrue(expr (Project(name="Miscellaneous"))) self.assertFalse(expr (Project(name="xxx"))) self.assertFalse(expr (Folder(name="Misc")))
def test_bug_2013_04_24(self): expr = parse_expr(tokenise('(type="Folder") and (name!="^Misc")'))[0] self.assertFalse(expr(Folder(name="Miscellaneous"))) expr = parse_expr(tokenise('(type="Project") and (name="Misc")'))[0] self.assertTrue(expr(Project(name="Miscellaneous"))) self.assertFalse(expr(Project(name="xxx"))) expr = parse_expr(tokenise('((type="Project") and (name="Misc"))'))[0] self.assertTrue(expr(Project(name="Miscellaneous"))) self.assertFalse(expr(Project(name="xxx"))) self.assertFalse(expr(Folder(name="Misc")))
def test_bug_2013_04_26 (self): expr = parse_expr(tokenise ('text=^Work$|^Miscellaneous$'))[0] self.assertFalse(expr (Folder(name="Misc"))) self.assertTrue(expr (Folder(name="Miscellaneous"))) expr = parse_expr(tokenise ('(type=Folder)'))[0] self.assertTrue(expr (Folder(name="Miscellaneous"))) expr = parse_expr(tokenise ('(type=Folder)and(text=^Work$|^Miscellaneous$)'))[0] self.assertFalse(expr (Folder(name="Misc"))) self.assertTrue(expr (Folder(name="Miscellaneous")))
def test_parse_expr_not_equals(self): expr = parse_expr(tokenise('true != true'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('true != false'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('false != true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('false != false'))[0] self.assertFalse(expr(None))
def test_bug_2013_04_26(self): expr = parse_expr(tokenise('text=^Work$|^Miscellaneous$'))[0] self.assertFalse(expr(Folder(name="Misc"))) self.assertTrue(expr(Folder(name="Miscellaneous"))) expr = parse_expr(tokenise('(type=Folder)'))[0] self.assertTrue(expr(Folder(name="Miscellaneous"))) expr = parse_expr( tokenise('(type=Folder)and(text=^Work$|^Miscellaneous$)'))[0] self.assertFalse(expr(Folder(name="Misc"))) self.assertTrue(expr(Folder(name="Miscellaneous")))
def test_parse_expr_not_equals (self): expr = parse_expr(tokenise ('true != true'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('true != false'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('false != true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('false != false'))[0] self.assertFalse(expr (None))
def test_parse_expr_date(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') wed = datetime.strptime('Apr 10 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise ('today'), type_required=STRING_TYPE, now=tue)[0] self.assertEquals ("today", expr(None)) expr = parse_expr(tokenise ('today'), type_required = DATE_TYPE, now=tue)[0] self.assertEquals ("2013-04-09", date_range_to_str (expr(None))) expr = parse_expr(tokenise ('"last tues"'), type_required = DATE_TYPE, now=tue)[0] self.assertEquals ("2013-04-02", date_range_to_str (expr(None))) expr = parse_expr(tokenise ('due = today'), now=tue)[0] self.assertTrue (expr(Task(name="", date_due=tue))) expr = parse_expr(tokenise ('due = start'), now=tue)[0] self.assertTrue (expr(Task(name="", date_due=tue, date_to_start=tue))) self.assertFalse (expr(Task(name="", date_due=tue, date_to_start=wed))) self.assertFalse (expr(Task(name="", date_due=tue)))
def test_parse_expr_flagged (self): expr = parse_expr(tokenise ('flagged'))[0] self.assertTrue(expr (Task(flagged=True))) self.assertFalse(expr (Task(flagged=False))) expr = parse_expr(tokenise ('flagged = true'))[0] self.assertTrue(expr (Task(flagged=True))) self.assertFalse(expr (Task(flagged=False))) expr = parse_expr(tokenise ('true = flagged'))[0] self.assertTrue(expr (Task(flagged=True))) self.assertFalse(expr (Task(flagged=False))) expr = parse_expr(tokenise ('!flagged'))[0] self.assertFalse(expr (Task(flagged=True))) self.assertTrue(expr (Task(flagged=False)))
def test_bug_2013_04_28_2(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise("flagged or (due='to tomorrow')"), now=tue)[0] self.assertFalse(expr(Task())) self.assertTrue(expr(Task(flagged=True))) self.assertTrue(expr(Task(date_due=tue)))
def test_parse_expr_flagged(self): expr = parse_expr(tokenise('flagged'))[0] self.assertTrue(expr(Task(flagged=True))) self.assertFalse(expr(Task(flagged=False))) expr = parse_expr(tokenise('flagged = true'))[0] self.assertTrue(expr(Task(flagged=True))) self.assertFalse(expr(Task(flagged=False))) expr = parse_expr(tokenise('true = flagged'))[0] self.assertTrue(expr(Task(flagged=True))) self.assertFalse(expr(Task(flagged=False))) expr = parse_expr(tokenise('!flagged'))[0] self.assertFalse(expr(Task(flagged=True))) self.assertTrue(expr(Task(flagged=False)))
def test_parse_expr_date(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') wed = datetime.strptime('Apr 10 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise('today'), type_required=STRING_TYPE, now=tue)[0] self.assertEquals("today", expr(None)) expr = parse_expr(tokenise('today'), type_required=DATE_TYPE, now=tue)[0] self.assertEquals("2013-04-09", date_range_to_str(expr(None))) expr = parse_expr(tokenise('"last tues"'), type_required=DATE_TYPE, now=tue)[0] self.assertEquals("2013-04-02", date_range_to_str(expr(None))) expr = parse_expr(tokenise('due = today'), now=tue)[0] self.assertTrue(expr(Task(name="", date_due=tue))) expr = parse_expr(tokenise('due = start'), now=tue)[0] self.assertTrue(expr(Task(name="", date_due=tue, date_to_start=tue))) self.assertFalse(expr(Task(name="", date_due=tue, date_to_start=wed))) self.assertFalse(expr(Task(name="", date_due=tue)))
def test_parse_expr_brackets (self): expr = parse_expr(tokenise ('(true)'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('(false)'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise (' ( false ) '))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('(false or true)'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('(false) or (true)'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('((false) or (true))'))[0] self.assertTrue(expr (None))
def test_parse_expr_brackets(self): expr = parse_expr(tokenise('(true)'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('(false)'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise(' ( false ) '))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('(false or true)'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('(false) or (true)'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('((false) or (true))'))[0] self.assertTrue(expr(None))
def test_parse_expr_or (self): expr = parse_expr(tokenise ('true or true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('true or false'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('false or true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('false or false'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('false or false or false'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('false or false or true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('false or true or false'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('true or false or false'))[0] self.assertTrue(expr (None))
def test_parse_expr_and (self): expr = parse_expr(tokenise ('true and true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('true and false'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('false and true'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('false and false'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('true and true and true'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('true and true and false'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('true and false and true'))[0] self.assertFalse(expr (None)) expr = parse_expr(tokenise ('false and true and true'))[0] self.assertFalse(expr (None))
def test_parse_expr_or(self): expr = parse_expr(tokenise('true or true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('true or false'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('false or true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('false or false'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('false or false or false'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('false or false or true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('false or true or false'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('true or false or false'))[0] self.assertTrue(expr(None))
def test_parse_expr_and(self): expr = parse_expr(tokenise('true and true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('true and false'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('false and true'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('false and false'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('true and true and true'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('true and true and false'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('true and false and true'))[0] self.assertFalse(expr(None)) expr = parse_expr(tokenise('false and true and true'))[0] self.assertFalse(expr(None))
def test_parse_expr_type(self): expr = parse_expr(tokenise ('type="Task"'))[0] self.assertTrue(expr (Task(flagged=True))) self.assertFalse(expr (Project(flagged=True)))
def test_parse_expr_string (self): expr = parse_expr(tokenise ('"xxx" = "xxx"'))[0] self.assertTrue(expr (None)) expr = parse_expr(tokenise ('"xxx" = "yyy"'))[0] self.assertFalse(expr (None))
def test_parse_expr_string_regexp(self): expr = parse_expr(tokenise('name="bb"'))[0] self.assertTrue(expr(Task(name="aabbccdd"))) self.assertFalse(expr(Task(name="zzz")))
def test_parse_expr_unquoted_string_literal(self): expr = parse_expr(tokenise('name=aabbccdd'))[0] self.assertTrue(expr(Task(name="aabbccdd"))) self.assertFalse(expr(Task(name="zzz")))
def test_parse_expr_status(self): expr = parse_expr(tokenise('status="done"'))[0] self.assertTrue(expr(Project(status="done"))) self.assertFalse(expr(Project(status="active")))
def test_parse_expr_type(self): expr = parse_expr(tokenise('type="Task"'))[0] self.assertTrue(expr(Task(flagged=True))) self.assertFalse(expr(Project(flagged=True)))
def test_parse_expr_unquoted_string_literal(self): expr = parse_expr(tokenise ('name=aabbccdd'))[0] self.assertTrue(expr (Task(name="aabbccdd"))) self.assertFalse(expr (Task(name="zzz")))
def test_parse_expr_any(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise('due = any'))[0] self.assertFalse(expr(Task(name=""))) self.assertTrue(expr(Task(name="", date_due=tue)))
def test_parse_expr_false (self): expr = parse_expr(tokenise ('false'))[0] self.assertFalse(expr (None))
def test_bug_2013_04_28_2 (self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise ("flagged or (due='to tomorrow')"), now=tue)[0] self.assertFalse(expr (Task())) self.assertTrue(expr (Task(flagged=True))) self.assertTrue(expr (Task(date_due=tue)))
def test_parse_expr_string(self): expr = parse_expr(tokenise('"xxx" = "xxx"'))[0] self.assertTrue(expr(None)) expr = parse_expr(tokenise('"xxx" = "yyy"'))[0] self.assertFalse(expr(None))
def test_parse_expr_status(self): expr = parse_expr(tokenise ('status="done"'))[0] self.assertTrue(expr (Project(status="done"))) self.assertFalse(expr (Project(status="active")))
def test_parse_expr_false(self): expr = parse_expr(tokenise('false'))[0] self.assertFalse(expr(None))
def test_parse_expr_any(self): tue = datetime.strptime('Apr 9 2013 11:33PM', '%b %d %Y %I:%M%p') expr = parse_expr(tokenise ('due = any'))[0] self.assertFalse (expr(Task(name=""))) self.assertTrue (expr(Task(name="", date_due=tue)))
def test_parse_expr_string_regexp(self): expr = parse_expr(tokenise ('name="bb"'))[0] self.assertTrue(expr (Task(name="aabbccdd"))) self.assertFalse(expr (Task(name="zzz")))
def test_parse_expr_note_filter(self): expr = parse_expr(tokenise ('note=123'))[0] self.assertTrue(expr (Task(note=TestNote("aaaa123bbb\nccc456ddd")))) self.assertTrue(expr (Task(note=TestNote("aaaazzzbbb\nccc123ddd")))) self.assertFalse(expr (Task(note=TestNote("z\y\z")))) self.assertFalse(expr (Task()))
def test_parse_expr_true(self): expr = parse_expr(tokenise('true'))[0] self.assertTrue(expr(None))
def test_parse_expr_note_filter(self): expr = parse_expr(tokenise('note=123'))[0] self.assertTrue(expr(Task(note=TestNote("aaaa123bbb\nccc456ddd")))) self.assertTrue(expr(Task(note=TestNote("aaaazzzbbb\nccc123ddd")))) self.assertFalse(expr(Task(note=TestNote("z\y\z")))) self.assertFalse(expr(Task()))
def test_parse_expr_true (self): expr = parse_expr(tokenise ('true'))[0] self.assertTrue(expr (None))