def test_fromdatetime(self): rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15)) assert rdt == datetime(2016, 1, 1, 16) assert rdt == RelativeDateTime( clock=lambda: datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15))
def test_relative_datetime_astimezone(self): rdt = RelativeDateTime.fromdatetime( datetime(2016, 1, 1, tzinfo=UTC) ).astimezone( UTCPlusOne ) # noqa assert rdt == datetime(2016, 1, 1, 1, tzinfo=UTCPlusOne)
def test_fromdatetime(self): rdt = RelativeDateTime.fromdatetime( datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15) ) assert rdt == datetime(2016, 1, 1, 16) assert rdt == RelativeDateTime( clock=lambda: datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15) )
def test_relative_datetime_fromdate(self): rdt = RelativeDateTime.fromdate(date(2016, 1, 1)) assert rdt == RelativeDateTime.fromdatetime(datetime(2016, 1, 1))
def test_relativedatetime_today(self, monkeypatch): monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime) assert RelativeDateTime.today() == NOW
def test_relative_datetime_utcnow(self, monkeypatch): monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime) rdt = RelativeDateTime.utcnow(offset=timedelta(days=5)) assert rdt == FakeDateTime.utcnow() + timedelta(days=5)
def test_asdate(self): rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, 15)).as_date() assert rdt == date(2016, 1, 1)
def test_relative_datetime_now(self, monkeypatch): monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime) rdt = RelativeDateTime.now() # just need to know it is close enough assert within_delta(rdt, FakeDateTime.now(), timedelta(seconds=1))
def test_relative_datetime_now_with_tzinfo(self, monkeypatch): monkeypatch.setattr("datestuff.relative.datetime", FakeDateTime) rdt = RelativeDateTime.now(UTC) assert within_delta(rdt, FakeDateTime.now(UTC), timedelta(seconds=1))
def test_asdatetime(self): rdt = RelativeDateTime.fromdatetime( datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15)).as_datetime() assert rdt == datetime(2016, 1, 1, 16)
def test_relativedatetime_today(self, monkeypatch): monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime) assert RelativeDateTime.today() == NOW
def test_replace_with_date_arguments(self): rd = RelativeDateTime.fromdate(date(2016, 1, 1)).replace( year=2015, day=2, month=2 ) assert rd.as_date() == date(2015, 2, 2)
def test_relative_datetime_astimezone(self): rdt = RelativeDateTime.fromdatetime(datetime(2016, 1, 1, tzinfo=UTC)).astimezone( UTCPlusOne) # noqa assert rdt == datetime(2016, 1, 1, 1, tzinfo=UTCPlusOne)
def test_relative_datetime_utcnow(self, monkeypatch): monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime) rdt = RelativeDateTime.utcnow(offset=timedelta(days=5)) assert rdt == FakeDateTime.utcnow() + timedelta(days=5)
def test_relative_datetime_now_with_tzinfo(self, monkeypatch): monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime) rdt = RelativeDateTime.now(UTC) assert within_delta(rdt, FakeDateTime.now(UTC), timedelta(seconds=1))
def test_relative_datetime_now(self, monkeypatch): monkeypatch.setattr('datestuff.relative.datetime', FakeDateTime) rdt = RelativeDateTime.now() # just need to know it is close enough assert within_delta(rdt, FakeDateTime.now(), timedelta(seconds=1))
def test_replace_with_offset_argument(self): rd = RelativeDateTime.fromdate(TODAY).replace(offset=timedelta(days=5)) assert rd == RelativeDateTime.fromdate(TODAY, offset=timedelta(days=5))
def test_asdatetime(self): rdt = RelativeDateTime.fromdatetime( datetime(2016, 1, 1, 15, 45), offset=timedelta(minutes=15) ).as_datetime() assert rdt == datetime(2016, 1, 1, 16)