def test_get_day_of_month(): # get_day_of_month is not directly exposed; we test it via roll_yearday dt = datetime(2017, 11, 15) with pytest.raises(ValueError): # To hit the raising case we need month == dt.month and n > 0 liboffsets.roll_yearday(dt, n=3, month=11, day_opt='foo')
def test_get_day_of_month_error(): # get_day_of_month is not directly exposed. # We test it via roll_yearday. dt = datetime(2017, 11, 15) day_opt = "foo" with pytest.raises(ValueError, match=day_opt): # To hit the raising case we need month == dt.month and n > 0. liboffsets.roll_yearday(dt, n=3, month=11, day_opt=day_opt)
def test_roll_yearday(): # Copied from doctest examples month = 3 day_opt = 'start' # `other` will be compared to March 1 other = datetime(2017, 2, 10) # before March 1 assert liboffsets.roll_yearday(other, 2, month, day_opt) == 1 assert liboffsets.roll_yearday(other, -7, month, day_opt) == -7 assert liboffsets.roll_yearday(other, 0, month, day_opt) == 0 other = Timestamp('2014-03-15', tz='US/Eastern') # after March 1 assert liboffsets.roll_yearday(other, 2, month, day_opt) == 2 assert liboffsets.roll_yearday(other, -7, month, day_opt) == -6 assert liboffsets.roll_yearday(other, 0, month, day_opt) == 1 month = 6 day_opt = 'end' # `other` will be compared to June 30 other = datetime(1999, 6, 29) # before June 30 assert liboffsets.roll_yearday(other, 5, month, day_opt) == 4 assert liboffsets.roll_yearday(other, -7, month, day_opt) == -7 assert liboffsets.roll_yearday(other, 0, month, day_opt) == 0 other = Timestamp(2072, 8, 24, 6, 17, 18) # after June 30 assert liboffsets.roll_yearday(other, 5, month, day_opt) == 5 assert liboffsets.roll_yearday(other, -7, month, day_opt) == -6 assert liboffsets.roll_yearday(other, 0, month, day_opt) == 1
def test_roll_yearday2(other, expected, n): month = 6 day_opt = "end" # `other` will be compared to June 30. assert liboffsets.roll_yearday(other, n, month, day_opt) == expected[n]
def test_roll_yearday(other, expected, n): month = 3 day_opt = "start" # `other` will be compared to March 1. assert liboffsets.roll_yearday(other, n, month, day_opt) == expected[n]