mirror of
https://github.com/MarkParker5/STARK.git
synced 2024-11-24 08:12:13 +02:00
test background with context
This commit is contained in:
parent
23fa5ba075
commit
af10c9df19
@ -60,7 +60,7 @@ def commands_context_flow() -> tuple[CommandsContext, CommandsContextDelegateMoc
|
||||
|
||||
@manager.new('lorem * dolor')
|
||||
def lorem():
|
||||
return Response(text = 'Lorem!')
|
||||
return Response(text = 'Lorem!', voice = 'Lorem!')
|
||||
|
||||
@manager.new('hello', hidden = True)
|
||||
def hello_context(**params):
|
||||
@ -112,15 +112,6 @@ def commands_context_flow() -> tuple[CommandsContext, CommandsContextDelegateMoc
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background multiple contexts')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_multiple_contexts(handler: ResponseHandler):
|
||||
|
||||
|
||||
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background needs input')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_needs_input(handler: ResponseHandler):
|
||||
@ -138,6 +129,13 @@ def commands_context_flow() -> tuple[CommandsContext, CommandsContextDelegateMoc
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
@manager.new('background with context')
|
||||
@manager.background(Response(text = 'Starting long background task', voice = 'Starting long background task'))
|
||||
def background_multiple_contexts(handler: ResponseHandler):
|
||||
time.sleep(0.01)
|
||||
text = voice = 'Finished long background task'
|
||||
return Response(text = text, voice = voice, commands = [hello_context, bye_context], parameters = {'name': 'John'})
|
||||
|
||||
@manager.new('background remove response')
|
||||
@manager.background(Response(text = 'Starting long background task'))
|
||||
def background_remove_response():
|
||||
|
@ -81,7 +81,7 @@ def test_background_inactive_needs_input(voice_assistant):
|
||||
# receive context output
|
||||
voice_assistant.commands_context._check_threads()
|
||||
|
||||
# voice assistant should receive all but not say anything
|
||||
# voice assistant should save all responses for later
|
||||
assert len(voice_assistant._responses) == 8
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 8
|
||||
voice_assistant.speech_synthesizer.results.clear()
|
||||
@ -106,7 +106,28 @@ def test_background_inactive_needs_input(voice_assistant):
|
||||
assert voice_assistant.speech_synthesizer.results.pop(0).text == response
|
||||
|
||||
def test_background_inactive_with_context(voice_assistant):
|
||||
pass
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('background with context')
|
||||
assert len(voice_assistant.commands_context._threads) == 1
|
||||
|
||||
# force inactive mode by settings zero time
|
||||
voice_assistant._last_interaction_time = datetime.fromtimestamp(0)
|
||||
|
||||
# wait for thread to finish
|
||||
voice_assistant.commands_context._threads[0].thread.join()
|
||||
|
||||
# receive context output
|
||||
voice_assistant.commands_context._check_threads()
|
||||
|
||||
# voice assistant should play all (including adding context) and save all responses for later
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 2 # 2 = first and returned
|
||||
assert len(voice_assistant._responses) == 1 # first response is not saved because it plays immediately
|
||||
assert len(voice_assistant.commands_context._context_queue) == 2
|
||||
voice_assistant.speech_synthesizer.results.clear()
|
||||
|
||||
# interact to disable inactive mode, voice assistant should reset context, repeat responses and add response context
|
||||
voice_assistant.speech_recognizer_did_receive_final_result('lorem ipsum dolor')
|
||||
assert len(voice_assistant.speech_synthesizer.results) == 2
|
||||
assert len(voice_assistant.commands_context._context_queue) == 2
|
||||
|
||||
def test_background_inactive_remove_response(voice_assistant):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user