Exemplo n.º 1
0
    def test_overlaps(self):
        first = ScheduledCharge.between(dateparser.parse('23:00'),
                                        dateparser.parse('01:00 tomorrow'))
        second = ScheduledCharge.between(dateparser.parse('00:30 tomorrow'),
                                         dateparser.parse('02:00 tomorrow'))

        assert first.overlaps(second) is True
        assert second.overlaps(first) is False
Exemplo n.º 2
0
    def test_between(self):
        sc = ScheduledCharge.between(dateparser.parse('17:00'),
                                     dateparser.parse('21:00'))

        assert sc.start_time == 'T17:00Z'
        assert sc.duration == 240

        sc2 = ScheduledCharge.between(dateparser.parse('23:05'),
                                      dateparser.parse('03:31 tomorrow'))

        assert sc2.start_time == 'T23:00Z'
        assert sc2.finish_time == 'T03:30Z'
        assert sc2.duration == 270

        with pytest.raises(RuntimeError,
                           match=r"Expected start to be a datetime.*"):
            ScheduledCharge.between('23:00',
                                    dateparser.parse('03:30 tomorrow'))

        with pytest.raises(RuntimeError,
                           match=r"Expected end to be a datetime.*"):
            ScheduledCharge.between(dateparser.parse('23:00'),
                                    '03:30 tomorrow')

        with pytest.raises(RuntimeError,
                           match='Start time should be before end time'):
            ScheduledCharge.between(dateparser.parse('23:00'),
                                    dateparser.parse('03:30'))