def test_subtracting_timedelta_from_relative_date_changes_offset(self): subject = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) assert subject - timedelta(days=1) == RelativeDate( clock=FakeDate.today) assert timedelta(days=1) - subject == RelativeDate( clock=FakeDate.today)
def test_relative_dates_compare_underlying_date(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) assert off_by_one == off_by_one assert off_by_one != RelativeDate(timedelta(0), clock=FakeDate.today) assert off_by_one != RelativeDate.fromdate(date(2015, 1, 1), timedelta(days=1))
def test_adding_two_relative_dates_adds_offsets(self): off_by_one = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) off_by_two = RelativeDate(offset=timedelta(days=2), clock=FakeDate.today) assert off_by_one + off_by_two == RelativeDate(timedelta(days=3), clock=FakeDate.today)
def test_proxy_attr_access_to_underlying_date(self): subject = RelativeDate.fromdate(date(2016, 3, 8)) target = date(2016, 3, 8) assert subject.year == target.year assert subject.day == target.day assert subject.month == target.month
def test_radd_with_unaccounted_type(self): class Thing(object): def __radd__(self, other): return other + timedelta(days=5) assert RelativeDate.fromdate(date(2016, 1, 1)) + Thing() == date( 2016, 1, 6)
def test_textual_representations(self): target = date(2016, 3, 8) subject = RelativeDate.fromdate(target) assert str(subject) == str(target)
def test_subtracting_date_from_relative_date_gives_timedelta(self): off_by_one = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) assert off_by_one - TODAY == timedelta(days=1) assert TODAY - off_by_one == timedelta(days=1)
def test_subtracting_relative_date_from_relative_data_changes_offset(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) assert off_by_one - off_by_one == RelativeDate(clock=FakeDate.today)
def test_proxy_boolness(self): assert bool(RelativeDate.fromdate(TODAY))
def test_relative_date_rich_comparisons(self, target, op): subject = RelativeDate(clock=FakeDate.today) assert op(subject, target)
def test_today(self, monkeypatch): monkeypatch.setattr('datestuff.relative.date', FakeDate) rd = RelativeDate.today(offset=timedelta(days=5)) assert rd == FakeDate.today() + timedelta(days=5)
def test_replace_with_date_arguments(self): rd = RelativeDate.fromdate(date(2016, 1, 1)).replace(year=2015, day=2, month=2) assert rd.as_date() == date(2015, 2, 2)
def test_today(self, monkeypatch): monkeypatch.setattr("datestuff.relative.date", FakeDate) rd = RelativeDate.today(offset=timedelta(days=5)) assert rd == FakeDate.today() + timedelta(days=5)
def test_relative_at_interaction(self): offset = timedelta(days=4) subject = RelativeDate(offset=offset, clock=FakeDate.today) assert subject == (FakeDate.today() + offset)
class TestRelativeDate(object): def test_relative_at_interaction(self): offset = timedelta(days=4) subject = RelativeDate(offset=offset, clock=FakeDate.today) assert subject == (FakeDate.today() + offset) def test_relative_dates_compare_underlying_date(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) assert off_by_one == off_by_one assert off_by_one != RelativeDate(timedelta(0), clock=FakeDate.today) assert off_by_one != RelativeDate.fromdate(date(2015, 1, 1), timedelta(days=1)) def test_adding_two_relative_dates_adds_offsets(self): off_by_one = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) off_by_two = RelativeDate(offset=timedelta(days=2), clock=FakeDate.today) assert off_by_one + off_by_two == RelativeDate(timedelta(days=3), clock=FakeDate.today) def test_adding_timedelta_adds_to_offset(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) off_by_three = RelativeDate(timedelta(days=3), clock=FakeDate.today) assert off_by_one + timedelta(days=2) == off_by_three assert timedelta(days=2) + off_by_one == off_by_three @pytest.mark.parametrize( 'target,op', [(YESTERDAY, operator.gt), (YESTERDAY, operator.ge), (RelativeDate(timedelta(days=-1), clock=FakeDate.today), operator.gt), (RelativeDate(timedelta(days=-1), clock=FakeDate.today), operator.ge), (TOMORROW, operator.le), (TOMORROW, operator.lt), (RelativeDate(timedelta(days=1), clock=FakeDate.today), operator.le), (RelativeDate(timedelta(days=1), clock=FakeDate.today), operator.lt), (RelativeDate(timedelta(days=2), clock=FakeDate.today), operator.ne)]) def test_relative_date_rich_comparisons(self, target, op): subject = RelativeDate(clock=FakeDate.today) assert op(subject, target) def test_subtracting_timedelta_from_relative_date_changes_offset(self): subject = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) assert subject - timedelta(days=1) == RelativeDate( clock=FakeDate.today) assert timedelta(days=1) - subject == RelativeDate( clock=FakeDate.today) def test_subtracting_relative_date_from_relative_data_changes_offset(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) assert off_by_one - off_by_one == RelativeDate(clock=FakeDate.today) def test_subtracting_date_from_relative_date_gives_timedelta(self): off_by_one = RelativeDate(offset=timedelta(days=1), clock=FakeDate.today) assert off_by_one - TODAY == timedelta(days=1) assert TODAY - off_by_one == timedelta(days=1) def test_proxy_formatting_call_to_underlying_date(self): pattern = "{0:%Y-%m-%d}" assert pattern.format( RelativeDate(clock=FakeDate.today)) == pattern.format(TODAY) def test_textual_representations(self): target = date(2016, 3, 8) subject = RelativeDate.fromdate(target) assert str(subject) == str(target) def test_proxy_boolness(self): assert bool(RelativeDate.fromdate(TODAY)) def test_proxy_attr_access_to_underlying_date(self): subject = RelativeDate.fromdate(date(2016, 3, 8)) target = date(2016, 3, 8) assert subject.year == target.year assert subject.day == target.day assert subject.month == target.month def test_today(self, monkeypatch): monkeypatch.setattr('datestuff.relative.date', FakeDate) rd = RelativeDate.today(offset=timedelta(days=5)) assert rd == FakeDate.today() + timedelta(days=5) def test_as_date(self, monkeypatch): monkeypatch.setattr('datestuff.relative.date', FakeDate) rd = RelativeDate.today() assert rd.as_date() == FakeDate.today() def test_replace_with_date_arguments(self): rd = RelativeDate.fromdate(date(2016, 1, 1)).replace(year=2015, day=2, month=2) assert rd.as_date() == date(2015, 2, 2) def test_replace_with_offset_argument(self): rd = RelativeDate.fromdate(TODAY).replace(offset=timedelta(days=5)) assert rd == RelativeDate.fromdate(TODAY, offset=timedelta(days=5)) def test_radd_with_unaccounted_type(self): class Thing(object): def __radd__(self, other): return other + timedelta(days=5) assert RelativeDate.fromdate(date(2016, 1, 1)) + Thing() == date( 2016, 1, 6)
def test_sub_relative_delta_instances(self): rd = RelativeDate.fromdate(date(2016, 1, 1), offset=relativedelta(days=1)) assert rd - rd == RelativeDate.fromdate(date(2016, 1, 1), offset=relativedelta())
def test_relative_delta_with_relative_date(self): rd = RelativeDate.fromdate(date(2000, 1, 1), offset=relativedelta(years=16)) assert rd == date(2016, 1, 1)
def test_replace_with_offset_argument(self): rd = RelativeDate.fromdate(TODAY).replace(offset=timedelta(days=5)) assert rd == RelativeDate.fromdate(TODAY, offset=timedelta(days=5))
def test_radd_with_unaccounted_type(self): class Thing(object): def __radd__(self, other): return other + timedelta(days=5) assert RelativeDate.fromdate(date(2016, 1, 1)) + Thing() == date(2016, 1, 6)
def test_as_date(self, monkeypatch): monkeypatch.setattr('datestuff.relative.date', FakeDate) rd = RelativeDate.today() assert rd.as_date() == FakeDate.today()
def test_as_date(self, monkeypatch): monkeypatch.setattr("datestuff.relative.date", FakeDate) rd = RelativeDate.today() assert rd.as_date() == FakeDate.today()
def test_sub_relative_delta_instances(self): rd = RelativeDate.fromdate(date(2016, 1, 1), offset=relativedelta(days=1)) assert rd - rd == RelativeDate.fromdate( date(2016, 1, 1), offset=relativedelta() )
def test_adding_timedelta_adds_to_offset(self): off_by_one = RelativeDate(timedelta(days=1), clock=FakeDate.today) off_by_three = RelativeDate(timedelta(days=3), clock=FakeDate.today) assert off_by_one + timedelta(days=2) == off_by_three assert timedelta(days=2) + off_by_one == off_by_three
def test_proxy_formatting_call_to_underlying_date(self): pattern = "{0:%Y-%m-%d}" assert pattern.format( RelativeDate(clock=FakeDate.today)) == pattern.format(TODAY)