def test_last_week_of_month_on_offset(self, n, weekday, date, tz): # GH 19036, GH 18977 _adjust_dst was incorrect for LastWeekOfMonth offset = LastWeekOfMonth(n=n, weekday=weekday) ts = Timestamp(date, tz=tz) slow = (ts + offset) - offset == ts fast = offset.is_on_offset(ts) assert fast == slow
def test_constructor(self): with pytest.raises(ValueError, match="^N cannot be 0"): LastWeekOfMonth(n=0, weekday=1) with pytest.raises(ValueError, match="^Day"): LastWeekOfMonth(n=1, weekday=-1) with pytest.raises(ValueError, match="^Day"): LastWeekOfMonth(n=1, weekday=7)
def test_offset(self): # Saturday last_sat = datetime(2013, 8, 31) next_sat = datetime(2013, 9, 28) offset_sat = LastWeekOfMonth(n=1, weekday=5) one_day_before = last_sat + timedelta(days=-1) assert one_day_before + offset_sat == last_sat one_day_after = last_sat + timedelta(days=+1) assert one_day_after + offset_sat == next_sat # Test On that day assert last_sat + offset_sat == next_sat # Thursday offset_thur = LastWeekOfMonth(n=1, weekday=3) last_thurs = datetime(2013, 1, 31) next_thurs = datetime(2013, 2, 28) one_day_before = last_thurs + timedelta(days=-1) assert one_day_before + offset_thur == last_thurs one_day_after = last_thurs + timedelta(days=+1) assert one_day_after + offset_thur == next_thurs # Test on that day assert last_thurs + offset_thur == next_thurs three_before = last_thurs + timedelta(days=-3) assert three_before + offset_thur == last_thurs two_after = last_thurs + timedelta(days=+2) assert two_after + offset_thur == next_thurs offset_sunday = LastWeekOfMonth(n=1, weekday=WeekDay.SUN) assert datetime(2013, 7, 31) + offset_sunday == datetime(2013, 8, 25)
def test_repr(self): assert (repr(LastWeekOfMonth( n=2, weekday=1)) == "<2 * LastWeekOfMonths: weekday=1>")
def test_is_on_offset(self, case): weekday, dt, expected = case offset = LastWeekOfMonth(weekday=weekday) assert offset.is_on_offset(dt) == expected