def test_days_slice(): rate = Rate('rate(2 days)') rate.now = datetime(year=2018, month=2, day=11, hour=12) expected = [ datetime(year=2018, month=2, day=13), datetime(year=2018, month=2, day=15), ] assert rate.get_next(count=2) == expected
def test_day_floor(): rate = Rate('rate(3 day)') rate.now = datetime(year=2018, month=2, day=11, hour=12, minute=30, second=30) expected = datetime(year=2018, month=2, day=11) assert rate._get_unit_floor() == expected
def test_minute_back(): rate = Rate('rate(5 minute)') rate.now = datetime(year=2018, month=2, day=11, hour=12, minute=30, second=20) expected = [datetime(year=2018, month=2, day=11, hour=12, minute=25)] assert rate.get_previous() == expected
def test_hours_back_slice(): rate = Rate('rate(2 hours)') rate.now = datetime(year=2018, month=2, day=11, hour=10, minute=30, second=20) expected = [ datetime(year=2018, month=2, day=11, hour=6), datetime(year=2018, month=2, day=11, hour=4), datetime(year=2018, month=2, day=11, hour=2), ] assert rate.get_previous(count=3, start=2) == expected
def test_day(): rate = Rate('rate(1 day)') rate.now = datetime(year=2018, month=2, day=11, hour=12) expected = [datetime(year=2018, month=2, day=12)] assert rate.get_next() == expected
def test_invalid_day(): rate = Rate('rate(1 day)') rate.now = datetime(year=2018, month=2, day=11, hour=12) with pytest.raises(ValueError): result = rate.get_next(1, 2)