def test_time_period_friendly_name(self, fixture): start_date = helpers.parse_isodate(fixture.start) relative = helpers.parse_isodate(fixture.relative) tp = TimePeriod(fixture.resolution, 0, start_date) got = tp._friendly_date_relative_to(relative) self.assertEqual(fixture.expected, got)
def test_time_period_from_index(self, fixture): start, when, resolution, result, date = fixture start_date = helpers.parse_isodate(start) when_date = helpers.parse_isodate(when) if result is not throws: tp_date = helpers.parse_isodate(date) exp = TimePeriod(resolution, result, tp_date) self.assertEqual(TimePeriod.from_index(start_date, resolution, result), exp)
def test_time_period_from_date(self, fixture): start, when, resolution, result, date = fixture start_date = helpers.parse_isodate(start) when_date = helpers.parse_isodate(when) if result is throws: with self.assertRaises(ValueError): TimePeriod.from_date(start_date, resolution, when_date) else: tp_date = helpers.parse_isodate(date) exp = TimePeriod(resolution, result, tp_date) self.assertEqual(TimePeriod.from_date(start_date, resolution, when_date), exp)
def test_cannot_record_negative_value(self): today = datetime.date.today() h = Habit(description="Brush my teeth", start=today, user=self.user, resolution='day') t = TimePeriod('day', 0, today) with self.assertRaises(ValueError): h.record(t, -10)