Esempio n. 1
0
def test_store(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]

    scheduler.set_schedule(test_date, test_schedule)

    assert scheduler.get_schedule(test_date) == test_schedule
Esempio n. 2
0
def test_not_in_time(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]

    scheduler.set_schedule(test_date, test_schedule)

    test_time = time(11, 35, 11)

    assert not scheduler.in_schedule(test_date, test_time)
Esempio n. 3
0
def test_in_time_dt_overload(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]

    scheduler.set_schedule(test_date, test_schedule)

    test_dt = datetime(2018, 2, 28, 12, 17, 5)

    assert scheduler.in_schedule_dt(test_dt)
Esempio n. 4
0
def test_multiple_store(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]

    test_date2 = date(2018, 3, 1)
    test_schedule2 = ["9:00:00-11:59:59"]

    scheduler.set_schedule(test_date, test_schedule)
    scheduler.set_schedule(test_date2, test_schedule2)

    assert scheduler.get_schedule(test_date) == test_schedule
    assert scheduler.get_schedule(test_date2) == test_schedule2
Esempio n. 5
0
def test_get_all(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]
    test_date2 = date(2018, 3, 5)
    test_schedule2 = ["11:00:00-12:00:00", "12:05:00-12:30:30"]

    scheduler.set_schedule(test_date, test_schedule)
    scheduler.set_schedule(test_date2, test_schedule2)

    all_schedules = scheduler.get_all_schedules()

    assert len(all_schedules) == 2
    assert all_schedules[test_date] == test_schedule
    assert all_schedules[test_date2] == test_schedule2
Esempio n. 6
0
def test_delete(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]

    scheduler.set_schedule(test_date, test_schedule)

    test_time = time(10, 35, 11)

    assert scheduler.in_schedule(test_date, test_time)

    scheduler.delete_schedule(test_date)

    assert scheduler.get_schedule(test_date) == []
    assert not scheduler.in_schedule(test_date, test_time)
Esempio n. 7
0
def test_override(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)
    test_schedule = ["10:00:00-11:00:00", "12:00:00-12:30:30"]
    test_schedule_2 = ["15:00:00-17:00:00"]

    scheduler.set_schedule(test_date, test_schedule)

    test_time = time(10, 35, 11)

    assert scheduler.in_schedule(test_date, test_time)

    scheduler.set_schedule(test_date, test_schedule_2)

    assert scheduler.get_schedule(test_date) == test_schedule_2
    assert not scheduler.in_schedule(test_date, test_time)
Esempio n. 8
0
def test_empty(common_mock):
    scheduler = scheduling.Scheduler()

    test_date = date(2018, 2, 28)

    assert scheduler.get_schedule(test_date) == []
Esempio n. 9
0
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)

formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)

logger.addHandler(handler)

BATTERY_PATH = "/sys/devices/platform/legoev3-battery/power_supply/legoev3-battery/voltage_now"
speed = config.relative_speed
should_move_road = False
stuck = False
lines_to_move = 0
scheduler = scheduling.Scheduler()
commands_to_send = []

bc = btc.BluetoothCommunicator(config.uuid, logger)


def bluetooth_listener(delay):
    global should_move_road, commands_to_send, lines_to_move

    while True:
        sleep(delay)
        try:
            if not bc.connected:
                logger.info("Device not connected, trying to connect")
                bc.connect()
        except: