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_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_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_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_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_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_proxy_boolness(self): assert bool(RelativeDate.fromdate(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_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_textual_representations(self): target = date(2016, 3, 8) subject = RelativeDate.fromdate(target) assert str(subject) == str(target)