diff --git a/archivemail b/archivemail index 2e5ec10..0d1e0df 100755 --- a/archivemail +++ b/archivemail @@ -1104,9 +1104,6 @@ def is_younger_than_days(time_message, min_days): min_days -- minimum number of days before message is considered old """ time_now = time.time() - if time_message > time_now: - vprint("warning: message has date in the future") - return False secs_old_min = (min_days * 24 * 60 * 60) days_old = (time_now - time_message) / 24 / 60 / 60 vprint("message is %.2f days old" % days_old) diff --git a/test_archivemail b/test_archivemail index 4f90519..4256743 100755 --- a/test_archivemail +++ b/test_archivemail @@ -544,6 +544,47 @@ class TestIsTooOld(unittest.TestCase): assert not archivemail.is_older_than_days(time_message=time_msg, max_days=1) +########## archivemail.is_younger_than_days() unit testing ################# + +class TestIsTooYoung(unittest.TestCase): + def testVeryNotYoung(self): + """with min_days=360, should be false for these dates > 1 year""" + ctime = time.time() + for years in range(1, 10): + time_msg = ctime - (years * 365 * 24 * 60 * 60) + assert not archivemail.is_younger_than_days(time_message=time_msg, + min_days=360) + + def testNotYoung(self): + """with min_days=14, should be false for these dates > 14 days""" + ctime = time.time() + for days in range(14, 360): + time_msg = ctime - (days * 24 * 60 * 60) + assert not archivemail.is_younger_than_days(time_message=time_msg, + min_days=14) + + def testJustNotYoung(self): + """with min_days=1, should be false for these dates >= 1 day""" + ctime = time.time() + for minutes in range(0, 61): + time_msg = ctime - (25 * 60 * 60) + (minutes * 60) + assert not archivemail.is_younger_than_days(time_message=time_msg, + min_days=1) + + def testYoung(self): + """with min_days=9, should be true for these dates < 9 days""" + for days in range(0, 9): + time_msg = time.time() - (days * 24 * 60 * 60) + assert archivemail.is_younger_than_days(time_message=time_msg, + min_days=9) + + def testJustYoung(self): + """with min_days=1, should be true for these hours <= 1 day""" + for minutes in range(0, 60): + time_msg = time.time() - (23 * 60 * 60) - (minutes * 60) + assert archivemail.is_younger_than_days(time_message=time_msg, + min_days=1) + ########## archivemail.parse_imap_url() unit testing ################# class TestParseIMAPUrl(unittest.TestCase):