Example #1
0
 def test_probability_outside_period_friday_once_hourly(self):
     rate_for_weekend_days = WeekdaysOccurrenceRate(start=5,
                                                    end=6,
                                                    hourly_rate=1)
     self.assertEqual(
         rate_for_weekend_days.probability(time=datetime(year=1970,
                                                         month=1,
                                                         day=2,
                                                         hour=0,
                                                         minute=0),
                                           interval=1), 0)
Example #2
0
 def test_probability_within_period_sunday_once_hourly(self):
     rate_for_weekend_days = WeekdaysOccurrenceRate(start=5,
                                                    end=6,
                                                    hourly_rate=1)
     self.assertEqual(
         rate_for_weekend_days.probability(time=datetime(year=1970,
                                                         month=1,
                                                         day=4,
                                                         hour=6,
                                                         minute=0),
                                           interval=1),
         1 / SECONDS_IN_AN_HOUR)
Example #3
0
 def test_get_monday_last_midnight_start_of_month_and_year(self):
     rate_for_weekend_days = WeekdaysOccurrenceRate(start=5,
                                                    end=6,
                                                    hourly_rate=1)
     self.assertEqual(
         rate_for_weekend_days._get_last_monday_midnight(
             datetime(year=1970, month=1, day=3, hour=6, minute=0)),
         datetime(year=1969,
                  month=12,
                  day=29,
                  hour=0,
                  minute=0,
                  second=0,
                  microsecond=0))
Example #4
0
 def test_occurs_with_only_weekday_probability_non_matching_period(self):
     hourly_calendar_probability = CalendarOccurrenceRates(
         weekdays=[WeekdaysOccurrenceRate(start=5, end=6, hourly_rate=1.0)])
     time_within_period = datetime(year=1970,
                                   month=1,
                                   day=1,
                                   hour=5,
                                   minute=30)
     self.assertFalse(
         hourly_calendar_probability.occurs(
             time=time_within_period,
             interval=SECONDS_IN_AN_HOUR,
         ))