Пример #1
0
async def test_callbacks_intent(mocker):
    """Test intent callbacks."""
    app = HermesApp("Test NluIntent", mqtt_client=mocker.MagicMock())

    # Mock intent callback and apply on_intent decorator.
    intent_handler = mocker.MagicMock()
    app.on_intent(INTENT_NAME)(intent_handler)

    intent_handler2 = mocker.MagicMock()
    app.on_intent(INTENT_NAME2, INTENT_NAME3)(intent_handler2)

    # Simulate app.run() without the MQTT client.
    app._subscribe_callbacks()

    # Simulate detected intent GetTime.
    await app.on_raw_message(INTENT_TOPIC, NLU_INTENT.to_json())
    # Check whether intent_handler has been called with the right Rhasspy Hermes object.
    intent_handler.assert_called_once_with(NLU_INTENT)
    intent_handler2.assert_not_called()

    # Simulate intent GetTemperature.
    intent_handler.reset_mock()
    intent_handler2.reset_mock()
    await app.on_raw_message(INTENT_TOPIC2, NLU_INTENT2.to_json())
    # Check whether intent_handler2 has been called with the right Rhasspy Hermes object.
    intent_handler2.assert_called_once_with(NLU_INTENT2)
    intent_handler.assert_not_called()

    # Simulate intent GetWeather.
    intent_handler.reset_mock()
    intent_handler2.reset_mock()
    # Check whether intent_handler2 has been called with the right Rhasspy Hermes object.
    await app.on_raw_message(INTENT_TOPIC3, NLU_INTENT3.to_json())
    intent_handler2.assert_called_once_with(NLU_INTENT3)
    intent_handler.assert_not_called()
async def test_callbacks_intent_not_recognized(mocker):
    """Test intent not recognized callbacks."""
    app = HermesApp("Test intentNotRecognized", mqtt_client=mocker.MagicMock())

    # Mock callback and apply on_intent_not_recognized decorator.
    inr = mocker.MagicMock()
    app.on_intent_not_recognized(inr)

    # Simulate app.run() without the MQTT client.
    app._subscribe_callbacks()

    # Simulate intent not recognized message.
    await app.on_raw_message(INR_TOPIC, INR.to_json())

    # Check whether callback has been called with the right Rhasspy Hermes object.
    inr.assert_called_once_with(INR)
Пример #3
0
async def test_callbacks_hotword(mocker):
    """Test hotword callbacks."""
    app = HermesApp("Test HotwordDetected", mqtt_client=mocker.MagicMock())

    # Mock wake callback and apply on_hotword decorator.
    wake = mocker.MagicMock()
    app.on_hotword(wake)

    # Simulate app.run() without the MQTT client.
    app._subscribe_callbacks()

    # Check whether callback has been added to the app.
    assert len(app._callbacks_hotword) == 1
    assert app._callbacks_hotword[0] == wake

    # Simulate detected hotword.
    await app.on_raw_message(HOTWORD_TOPIC, HOTWORD_PAYLOAD)

    # Check whether callback has been called with the right Rhasspy Hermes object.
    wake.assert_called_once_with(HotwordDetected.from_json(HOTWORD_PAYLOAD))
Пример #4
0
async def test_callbacks_hotword(mocker):
    """Test hotword callbacks."""
    app = HermesApp("Test HotwordDetected", mqtt_client=mocker.MagicMock())

    # Mock wake callback and apply on_hotword decorator.
    wake = mocker.MagicMock()
    app.on_hotword(wake)

    # Simulate app.run() without the MQTT client.
    app._subscribe_callbacks()

    # Simulate detected hotword.
    await app.on_raw_message(HOTWORD_TOPIC, HOTWORD.to_json())

    # Check whether callback has been called with the right Rhasspy Hermes object.
    wake.assert_called_once_with(HOTWORD)

    # Simulate another detected hotword.
    wake.reset_mock()
    await app.on_raw_message(HOTWORD_TOPIC2, HOTWORD2.to_json())

    # Check whether callback has been called with the right Rhasspy Hermes object.
    wake.assert_called_once_with(HOTWORD2)