def testRoundTo15Minutes_Down(self): timedelta = date.TimeDelta(days=1, hours=10, minutes=7) self.assertEqual(date.TimeDelta(days=1, hours=10), timedelta.round(minutes=15))
def testMillisecondsInOneSecond(self): timedelta = date.TimeDelta(seconds=1) self.assertEqual(1000, timedelta.milliseconds())
def testMillisecondsInOneDay(self): timedelta = date.TimeDelta(days=1) self.assertEqual(24*60*60*1000, timedelta.milliseconds())
def testRoundTo30Minutes_AlwaysUp(self): timedelta = date.TimeDelta(days=1, hours=10, minutes=14) self.assertEqual(date.TimeDelta(days=1, hours=10, minutes=30), timedelta.round(minutes=30, alwaysUp=True))
def testRoundTo1Hour_AlwaysUp(self): timedelta = date.TimeDelta(days=1, hours=10, minutes=1) self.assertEqual(date.TimeDelta(days=1, hours=11), timedelta.round(hours=1, alwaysUp=True))
def testDuration(self): self.assertEqual(date.TimeDelta(days=1), self.effort.duration())
def testPlannedStartDateDayBeforeYesterday(self): self.task.setPlannedStartDateTime(self.now - date.TimeDelta(hours=48)) self.task.setCompletionDateTime(self.now) self.assertEqual(self.now + date.ONE_DAY, self.task.plannedStartDateTime())
def testZeroTime(self): self.assertEqual('', render.timeSpent(date.TimeDelta()))
def testTenHours(self): self.assertEqual('10:00:00', render.timeSpent(date.TimeDelta(hours=10)))
def testOneDayLateWhenActive(self): timeLeft = date.TimeDelta(days=-1) self.assertEqual('-1 day, 0:00', render.timeLeft(timeLeft, False))
def testOneDayLateWhenCompleted(self): timeLeft = date.TimeDelta(days=-1) self.assertEqual('', render.timeLeft(timeLeft, True))
def testTwoDaysLeftWhenCompleted(self): timeLeft = date.TimeDelta(days=2) self.assertEqual('', render.timeLeft(timeLeft, True))
def testTwoDaysLeftWhenActive(self): timeLeft = date.TimeDelta(days=2) self.assertEqual('2 days, 0:00', render.timeLeft(timeLeft, False))
def __snooze(self, taskWithReminder): minutesToSnooze = self.settings.getint('view', 'defaultsnoozetime') taskWithReminder.snoozeReminder( date.TimeDelta(minutes=minutesToSnooze))
def testFindStartDate(self): testString = 'This is a date start[' + date.DateTime.now().replace( second=0, microsecond=0).strftime('%Y-%m-%d %H:%M') + ']' cmpDate = date.DateTime.now().replace(second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M')) testString = 'This is a date start[' + date.DateTime.now().replace( second=0, microsecond=0).strftime('%Y-%m-%d %H:%M') + ']' cmpDate = (date.DateTime.now() + date.TimeDelta(days=1)).replace( second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertNotEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M')) testString = 'This is a date start[2013-13-12]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date start[2013-12-32]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date start[2013-02-29]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date start[20131-12-24]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual(answer[0], None, 'Nej') testString = 'This is a date start[2013-121-24]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date start[20131-12-241]' answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date start ' + date.DateTime.now().replace( second=0, microsecond=0).strftime('%Y-%m-%d %H:%M') cmpDate = date.DateTime.now().replace(second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date Thursday 10:00' cmpDate = (date.DateTime.now() + date.TimeDelta( days=(3 - date.DateTime.now().weekday()) % 7 + 1)).replace( hour=10, minute=0, second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date Thursday' cmpDate = (date.DateTime.now() + date.TimeDelta( days=(3 - date.DateTime.now().weekday()) % 7 + 1)).replace( hour=0, minute=0, second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date 10:00' cmpDate = date.DateTime.today().replace(hour=10, minute=0, second=0, microsecond=0) answer = quickAddParser.Parser().findStartDate(testString) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S'))
def testNegativeHours(self): self.assertEqual('-1:00:00', render.timeSpent(date.TimeDelta(hours=-1)))
def testChangeStart_WithinPeriod(self): self.taskList.append(self.task1) self.task1.addEffort(self.effort1period1a) self.effort1period1a.setStart(self.effort1period1a.getStart() + \ date.TimeDelta(seconds=1)) self.assertEqual(2, len(self.effortAggregator))
def testNegativeSeconds(self): self.assertEqual('-0:00:01', render.timeSpent(date.TimeDelta(seconds=-1)))
def testMarkCompletedSetsNewReminderIfItWasSetPreviously(self): reminder = self.now + date.TimeDelta(seconds=10) self.task.setReminder(reminder) self.task.setCompletionDateTime() self.assertEqual(self.createRecurrence()(reminder), self.task.reminder())
def testNoTimeLeftWhenActive(self): timeLeft = date.TimeDelta() self.assertEqual('0:00', render.timeLeft(timeLeft, False))
def testPlannedStartAndDueDateInThePast(self): self.task.setPlannedStartDateTime(self.now - date.TimeDelta(hours=48)) self.task.setDueDateTime(self.yesterday) self.task.setCompletionDateTime(self.now) self.assertEqual(self.now, self.task.plannedStartDateTime()) self.assertEqual(self.tomorrow, self.task.dueDateTime())
def testNoTimeLeftWhenCompleted(self): self.assertEqual('', render.timeLeft(date.TimeDelta(), True))
def testRoundTo1Hour_Up(self): timedelta = date.TimeDelta(days=1, hours=10, minutes=30) self.assertEqual(date.TimeDelta(days=1, hours=11), timedelta.round(hours=1))
def testSortByBudgetDescending(self): self.sorter.sortBy('budget') self.sorter.sortAscending(False) self.task1.setBudget(date.TimeDelta(100)) self.assertEqual([self.task1, self.task2], list(self.sorter))
def testHours(self): timedelta = date.TimeDelta(hours=2, minutes=15) self.assertEqual(2.25, timedelta.hours())
def testBudget_MoreThan24Hour(self): self.task.setBudget(date.TimeDelta(hours=25)) self.tasksWrittenAndRead = task.TaskList(self.readAndWrite()[0]) self.assertAttributeWrittenAndRead(self.task, 'budget')
def testMillisecondsInOneHour(self): timedelta = date.TimeDelta(hours=1) self.assertEqual(60*60*1000, timedelta.milliseconds())
def testFindEndDate(self): startDate = date.DateTime(2013, 12, 21, 15, 0) testString = 'This is a date end[2013-12-25 15:00]' cmpDate = (date.DateTime(2013, 12, 25, 15, 0)) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M')) testString = 'This is a date end[' + date.DateTime.now().replace( second=0, microsecond=0).strftime('%Y-%m-%d %H:%M') + ']' cmpDate = (date.DateTime.now() + date.TimeDelta(days=1)).replace( second=0, microsecond=0) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertNotEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M')) testString = 'This is a date end[2013-13-12]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date end[2013-12-32]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date end[2013-02-29]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: None ") testString = 'This is a date end[20131-12-24]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: " + startDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date end[2013-121-24]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: " + startDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date end[20131-12-241]' answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], None, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M') if answer[0] is not None else 'None' + " Should be: " + startDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date 2013-12-25 10:00' cmpDate = date.DateTime(2013, 12, 25, 10, 0) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date Thursday 10:00' cmpDate = date.DateTime(2013, 12, 26, 10, 0).replace(second=0, microsecond=0) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date Thursday' cmpDate = cmpDate = date.DateTime(2013, 12, 26, 0, 0).replace(second=0, microsecond=0) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S')) testString = 'This is a date 21:00' cmpDate = startDate.replace(hour=21, minute=0) answer = quickAddParser.Parser().findEndDate(testString, startDate) self.assertEqual( answer[0], cmpDate, 'Parsed: ' + testString + ' Answer: ' + answer[0].strftime('%Y-%m-%d %H:%M:%S') + " Cmpdate: " + cmpDate.strftime('%Y-%m-%d %H:%M:%S'))
def testMillisecondsInOneMicrosecond(self): timedelta = date.TimeDelta(microseconds=1) self.assertEqual(0, timedelta.milliseconds())
def testRoundTo5Minutes_Big(self): timedelta = date.TimeDelta(days=10, minutes=10, seconds=30) self.assertEqual(date.TimeDelta(days=10, minutes=10), timedelta.round(minutes=5))