def test_opening_timeout():
    # Door is closed
    mock_driver = MockDriver()
    door_model = Door("Test door", mock_driver, 0.2, 0.1, 0.2)
    door_model.set_new_state('Opening')

    # The upper switch will not close before timeout is reached
    time.sleep(0.3)

    assert door_model.state.__class__.__name__ == "IntermediateState"
def test_intermediate_to_open():
    # Door is closed
    mock_driver = MockDriver()
    door_model = Door("Test door", mock_driver, 0.2, 0.1, 0.2)
    door_model.set_new_state('Intermediate')

    # The upper switch closed
    mock_driver.upper_limit_switch = True
    signal(SIGNAL_UPPER_SWITCH_CHANGED).send(mock_driver)

    assert door_model.state.__class__.__name__ == "OpenState"
def test_closing():
    # Door is closed
    mock_driver = MockDriver()
    door_model = Door("Test door", mock_driver, 0.2, 0.1, 0.2)
    door_model.set_new_state('Closing')

    # The lower switch closed
    mock_driver.lower_limit_switch = True
    signal(SIGNAL_LOWER_SWITCH_CHANGED).send(mock_driver)

    assert door_model.state.__class__.__name__ == "ClosedState"
    time.sleep(0.3)
    assert door_model.state.__class__.__name__ == "ClosedState"