def seconds(time):
    '''Given %H:%M:%S -> seconds. Hours can be arbitrarily large.'''
    try:
        hours, minutes, seconds = [int(f) for f in time.split(':')]
    except ValueError:
        msg = 'expecting format %H:%M:%S, not {0}'.format(time)
        raise ValueError(msg)

    assert_bounded('minutes', 0, 59, minutes)
    assert_bounded('seconds', 0, 59, seconds)
    return hours * 3600 + minutes * 60 + seconds
Пример #2
0
def seconds(time):
    '''Given %H:%M:%S -> seconds. Hours can be arbitrarily large.'''
    try:
        hours, minutes, seconds = [int(f) for f in time.split(':')]
    except ValueError:
        msg = 'expecting format %H:%M:%S, not {0}'.format(time)
        raise ValueError(msg)

    assert_bounded('minutes', 0, 59, minutes)
    assert_bounded('seconds', 0, 59, seconds)
    return hours * 3600 + minutes * 60 + seconds
Пример #3
0
def _validate_hourly(interval, day_of_week, hour, minute):
    assert_bounded('Hourly interval', 1, 23, interval)
    assert_is_none('Day of week', day_of_week)
    assert_is_none('Hour', hour)
    assert_is_none('Minute', minute)
Пример #4
0
 def _validate(self, frequency, interval, day_of_week, hour, minute):
     """Ensures that schedule args are valid, checking
     all the corner cases and all the boundaries."""
     assert_bounded('Frequency', 0, 4, frequency)
     _validate_fn[frequency](interval, day_of_week, hour, minute)
Пример #5
0
 def test_assert_bounded_works(self):
     [asserts.assert_bounded('test', 1, 3, i) for i in range(1, 4)]
Пример #6
0
 def test_assert_bounded_throws_when_below_bounds(self):
     with self.assertRaises(ValueError):
         asserts.assert_bounded('test', 1, 3, 0)