コード例 #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
コード例 #2
0
    def test_spans_midnight(self):
        before_midnight = ScheduledCharge('T23:30Z', 15)
        assert before_midnight.spans_midnight is False

        at_midnight = ScheduledCharge('T23:45Z', 15)
        assert at_midnight.spans_midnight is True

        after_midnight = ScheduledCharge('T23:45Z', 30)
        assert after_midnight.spans_midnight is True
コード例 #3
0
    def test_finish_time(self):
        at_midnight = ScheduledCharge('T23:45Z', 15)
        assert at_midnight.finish_time == 'T00:00Z'
        assert at_midnight.finish_time_minutes == 0

        after_midnight = ScheduledCharge('T23:45Z', 30)
        assert after_midnight.finish_time == 'T00:15Z'
        assert after_midnight.finish_time_minutes == 15

        same_day = ScheduledCharge('T12:00Z', 60)
        assert same_day.finish_time == 'T13:00Z'
        assert same_day.finish_time_minutes == (13 * 60)
コード例 #4
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'))
コード例 #5
0
    def test_validation(self):
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid start time.*"):
            ScheduledCharge('1200', 15).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid start time.*"):
            ScheduledCharge(1200, 15).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid start time.*"):
            ScheduledCharge('T24:00Z', 15).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid start time.*"):
            ScheduledCharge('T12:04Z', 15).validate()

        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid duration.*"):
            ScheduledCharge('T12:00Z', 14).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid duration.*"):
            ScheduledCharge('T12:00Z', 16).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid duration.*"):
            ScheduledCharge('T12:00Z', -1).validate()
        with pytest.raises(InvalidScheduleException,
                           match=r".*not a valid duration.*"):
            ScheduledCharge('T12:00Z', '15').validate()
コード例 #6
0
ファイル: schedule.py プロジェクト: robertaramar/pyze
def edit(schedules, vehicle, parsed_args):
    if parsed_args.id:
        schd_id = parsed_args.id
    else:
        schd_id = 1

    schedule = schedules[schd_id]

    for day in DAYS:
        if hasattr(parsed_args, day):
            day_value = getattr(parsed_args, day)

            if day_value:
                start_time, duration = parse_day_value(day_value)

                if not parsed_args.utc:
                    start_time = remove_offset(start_time)

                schedule[day] = ScheduledCharge(start_time, duration)

    print('Setting new schedule (ID {}):'.format(schedule.id))
    print_schedule(schedule, parsed_args.utc)
    vehicle.set_charge_schedules(schedules)
    print(
        'It may take some time before these changes are reflected in your vehicle.'
    )
コード例 #7
0
    def test_set_item(self):
        cs = ChargeSchedule()

        sch = ScheduledCharge('T07:30Z', 120)

        with pytest.raises(RuntimeError, match=r".*not a valid day"):
            cs['florsday'] = sch

        with pytest.raises(RuntimeError,
                           match=r"Expected ScheduledCharge, got.*"):
            cs['friday'] = 1138

        cs['friday'] = sch
        assert cs['friday'] == sch
コード例 #8
0
ファイル: schedule.py プロジェクト: neutrino85/pyze
def edit(schedule, vehicle, parsed_args):
    for day in DAYS:
        if hasattr(parsed_args, day):
            day_value = getattr(parsed_args, day)

            if day_value:
                start_time, duration = parse_day_value(day_value)

                if not parsed_args.utc:
                    start_time = remove_offset(start_time)

                schedule[day] = ScheduledCharge(start_time, duration)

    print('Setting new schedule:')
    print_schedule(schedule, parsed_args.utc)
    vehicle.set_charge_schedule(schedule)
    print(
        'It may take some time before these changes are reflected in your vehicle.'
    )
コード例 #9
0
def edit_schedule(schedules, vehicle, parsed_args):
    if hasattr(parsed_args, 'id'):
        schd_id = parsed_args['id']
    else:
        schd_id = 1

    schedule = schedules[schd_id]

    for day in DAYS:
        if hasattr(parsed_args, day):
            day_value = getattr(parsed_args, day)

            if day_value:
                start_time, duration = parse_day_value(day_value)

                if not parsed_args.utc:
                    start_time = remove_offset(start_time)

                schedule[day] = ScheduledCharge(start_time, duration)