def test_round_range(): start, end, interval = _get_constrained_date_range({"statsPeriod": "2d"}) assert start == datetime(2018, 12, 9, 4, tzinfo=pytz.utc) assert end == datetime(2018, 12, 11, 4, tzinfo=pytz.utc) start, end, interval = _get_constrained_date_range({ "statsPeriod": "2d", "interval": "1d" }) assert start == datetime(2018, 12, 10, tzinfo=pytz.utc) assert end == datetime(2018, 12, 12, tzinfo=pytz.utc)
def test_inclusive_end(): start, end, interval = _get_constrained_date_range( { "start": "2021-02-24T00:00:00", "end": "2021-02-25T00:00:00", "interval": "1h" }, ) assert start == datetime(2021, 2, 24, tzinfo=pytz.utc) assert end == datetime(2021, 2, 25, 1, tzinfo=pytz.utc)
def test_round_exact(): start, end, interval = _get_constrained_date_range( { "start": "2021-01-12T04:06:16", "end": "2021-01-17T08:26:13", "interval": "1d" }, ) assert start == datetime(2021, 1, 12, tzinfo=pytz.utc) assert end == datetime(2021, 1, 18, tzinfo=pytz.utc)
def test_invalid_interval(): with pytest.raises(InvalidParams): start, end, interval = _get_constrained_date_range({"interval": "0d"})