Exemplo n.º 1
0
    def test_initialization(self):
        # test all valid earliest and latest combos
        GOOD_EARLIEST_LATEST = (
            (None, None),
            (date(2013, 5, 10), None),
            (datetime(2013, 5, 10), None),
            (None, date(2013, 5, 10)),
            (None, datetime(2013, 5, 10)),
            (date(2013, 5, 10), date(2013, 5, 11)),
            (datetime(2013, 5, 10), datetime(2013, 5, 11)),
            (datetime(2013, 5, 10), date(2013, 5, 11)),
            (date(2013, 5, 10), datetime(2013, 5, 11)),
            (date(2013, 5, 10), date(2013, 5, 10)),
        )

        for earliest, latest in GOOD_EARLIEST_LATEST:
            dates.TimePeriod(earliest, latest)

        BAD_EARLIEST_LATEST = (
            (date(2013, 5, 11), date(2013, 5, 10)),
        )

        for earliest, latest in BAD_EARLIEST_LATEST:
            with pytest.raises(ValueError):
                dates.TimePeriod(earliest, latest)
Exemplo n.º 2
0
    def test_initialization_not_some_contained(self):
        periods = [
            dates.TimePeriod(date(2013, 5, 10), date(2013, 5, 15)),
            dates.TimePeriod(date(2013, 5, 8), date(2013, 5, 16)),
        ]

        dtp = dates.DiscontinuousTimePeriod(
            *periods
        )

        assert dtp._periods == [periods[1]]
Exemplo n.º 3
0
    def test_initialization_overlaps(self):
        periods = [
            dates.TimePeriod(date(2013, 5, 8), date(2013, 5, 15)),
            dates.TimePeriod(date(2013, 5, 10), date(2013, 5, 16)),
        ]

        dtp = dates.DiscontinuousTimePeriod(
            *periods
        )

        assert dtp._periods == [dates.TimePeriod(date(2013, 5, 8), date(2013, 5, 16))]
Exemplo n.º 4
0
    def test_initialization_all_noncontinous(self):
        periods = [
            dates.TimePeriod(date(2013, 5, 10), date(2013, 5, 15)),
            dates.TimePeriod(date(2013, 5, 20), date(2013, 5, 25)),
            dates.TimePeriod(date(2013, 5, 26), date(2013, 5, 26)),
        ]
        dtp = dates.DiscontinuousTimePeriod(
            *periods
        )

        assert set(dtp._periods) == set(periods)
Exemplo n.º 5
0
    def test_overlaps_overlap(self):
        tp1 = dates.TimePeriod(
            date(2013, 5, 11),
            date(2013, 5, 17),
        )
        tp2 = dates.TimePeriod(
            date(2013, 5, 16),
            date(2013, 5, 21)
        )

        assert tp1.overlaps(tp2)
        assert tp2.overlaps(tp1)
Exemplo n.º 6
0
    def test_eq(self):
        assert dates.TimePeriod(None, None) == dates.TimePeriod(None, None)
        assert dates.TimePeriod(date.today(), None) == dates.TimePeriod(date.today(), None)

        assert dates.TimePeriod(None, None) != dates.TimePeriod(date.today(), None)
Exemplo n.º 7
0
    def test_verbose_function(self):
        with mock.patch("utils.dates.TimePeriod.__contains__") as cpatch:
            dates.TimePeriod(None, None).contains(mock.sentinel.CONTAIN)

            cpatch.assert_called_once_with(mock.sentinel.CONTAIN)
Exemplo n.º 8
0
 def contains_month(self):
     return dates.TimePeriod(
         date(date.today().year, date.today().month, 1),
         date(date.today().year + 1, (date.today().month % 12) + 1, 1) - timedelta(days=1),
     )
Exemplo n.º 9
0
 def contains_past(self):
     return dates.TimePeriod(None, date.today() - timedelta(days=1))
Exemplo n.º 10
0
 def contains_future(self):
     return dates.TimePeriod(date.today() + timedelta(days=1), None)
Exemplo n.º 11
0
 def contains_all(self):
     return dates.TimePeriod(None, None)