コード例 #1
0
    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)
コード例 #2
0
    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))
コード例 #3
0
    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)
コード例 #4
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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
コード例 #5
0
    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
コード例 #6
0
    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)
コード例 #7
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    def test_textual_representations(self):
        target = date(2016, 3, 8)
        subject = RelativeDate.fromdate(target)

        assert str(subject) == str(target)
コード例 #8
0
    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)
コード例 #9
0
    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)
コード例 #10
0
 def test_proxy_boolness(self):
     assert bool(RelativeDate.fromdate(TODAY))
コード例 #11
0
    def test_relative_date_rich_comparisons(self, target, op):
        subject = RelativeDate(clock=FakeDate.today)

        assert op(subject, target)
コード例 #12
0
    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)
コード例 #13
0
    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)
コード例 #14
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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)
コード例 #15
0
    def test_relative_at_interaction(self):
        offset = timedelta(days=4)
        subject = RelativeDate(offset=offset, clock=FakeDate.today)

        assert subject == (FakeDate.today() + offset)
コード例 #16
0
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)
コード例 #17
0
    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())
コード例 #18
0
    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)
コード例 #19
0
    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))
コード例 #20
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
 def test_proxy_boolness(self):
     assert bool(RelativeDate.fromdate(TODAY))
コード例 #21
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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)
コード例 #22
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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)
コード例 #23
0
    def test_as_date(self, monkeypatch):
        monkeypatch.setattr('datestuff.relative.date', FakeDate)
        rd = RelativeDate.today()

        assert rd.as_date() == FakeDate.today()
コード例 #24
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    def test_as_date(self, monkeypatch):
        monkeypatch.setattr("datestuff.relative.date", FakeDate)
        rd = RelativeDate.today()

        assert rd.as_date() == FakeDate.today()
コード例 #25
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
 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()
     )
コード例 #26
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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))
コード例 #27
0
    def test_textual_representations(self):
        target = date(2016, 3, 8)
        subject = RelativeDate.fromdate(target)

        assert str(subject) == str(target)
コード例 #28
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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)
コード例 #29
0
    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
コード例 #30
0
ファイル: test_relative.py プロジェクト: justanr/datestuff
    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))
コード例 #31
0
    def test_proxy_formatting_call_to_underlying_date(self):
        pattern = "{0:%Y-%m-%d}"

        assert pattern.format(
            RelativeDate(clock=FakeDate.today)) == pattern.format(TODAY)