Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
 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)