Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix converse and snooze #110

Open
wants to merge 11 commits into
base: 20.08
Choose a base branch
from
129 changes: 129 additions & 0 deletions test/behave/alarms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file got dropped in the wrong place and should be overwriting test/behave/steps/alarms.py?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

from behave import given, then

from mycroft.audio import wait_while_speaking

from test.integrationtests.voight_kampff import emit_utterance, wait_for_dialog


@given('an alarm is set for {alarm_time}')
def given_set_alarm(context, alarm_time):
emit_utterance(context.bus, 'set an alarm for {}'.format(alarm_time))
time.sleep(3)
wait_for_dialog(context.bus, ['alarm.scheduled.for.time'])
context.bus.clear_messages()


@given('there are no previous alarms set')
def given_no_alarms(context):
followups = ['ask.cancel.alarm.plural',
'ask.cancel.desc.alarm',
'ask.cancel.desc.alarm.recurring']
no_alarms = ['alarms.list.empty']
cancelled = ['alarm.cancelled.desc',
'alarm.cancelled.desc.recurring',
'alarm.cancelled.multi',
'alarm.cancelled.recurring']

#print('\nASKING QUESTION')
emit_utterance(context.bus, 'cancel all alarms')
for i in range(10):
wait_while_speaking()
for message in context.bus.get_messages('speak'):
if message.data.get('meta', {}).get('dialog') in followups:
#print("\nWaiting before saying yes ...")
time.sleep(2)
emit_utterance(context.bus, 'yes')
rc = wait_for_dialog(context.bus, cancelled)
#print('\nWere we understood--->rc= %s' % (rc,))
context.bus.clear_messages()
return
elif message.data.get('meta', {}).get('dialog') in no_alarms:
context.bus.clear_messages()
return
time.sleep(1)
context.bus.clear_messages()


@given('an alarm is expired and beeping')
def given_expired_alarm(context):
got_msg = False
emit_utterance(context.bus, 'set an alarm for 1 minute from now')

# drain any existing messages
for message in context.bus.get_messages('mycroft.alarm.beeping'):
pass

ctr = 0
while ctr < 60 and not got_msg:
time.sleep(1)

# wait for msg = beeping
for message in context.bus.get_messages('mycroft.alarm.beeping'):
#print("\n\nDETECT BEEPING MSG !!!\n\n")
got_msg = True

ctr += 1

context.bus.clear_messages()
assert got_msg, "Error, did not get beeping message!"


@then('"mycroft-alarm" should stop beeping')
def then_stop_beeping(context):
# TODO Implement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a message that would be emitted when the beep is stopped in code eg mycroft.alarm.silenced? Is that worthwhile even though we can't definitely say "there is no beeping sound being output"

We should also call it from the methods below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I actually added just this to indicate beeping has started in the skill proper. I am not sure why you would need to know when the beeping stopped as well (those methods below I believe rely on the new message I already added for beeping started if I am not mistaken), however, this is something that would probably need to go in the audio service as we have no idea when beeping stops and they are variable length.

pass


@then('"mycroft-alarm" should stop beeping and start beeping again in 10 minutes')
def then_stop_and_start_beeping(context):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could merge the 5 and 10 minute variations of this step by extracting the period as a variable:

@then('"mycroft-alarm" should stop beeping and start beeping again in {snooze_duration}')
def then_stop_and_start_beeping(context, snooze_duration):

start_time = time.time()
got_msg = False

# drain any existing messages
for message in context.bus.get_messages('mycroft.alarm.beeping'):
pass

ctr = 0
while ctr < 12 and not got_msg:
time.sleep(60)

# wait for msg = beeping
for message in context.bus.get_messages('mycroft.alarm.beeping'):
got_msg = True

ctr += 1

elapsed = time.time() - start_time
context.bus.clear_messages()
#assert got_msg and elapsed > 5*60, "Error, did not get beeping message!"
assert got_msg, "Error, did not get beeping message!"


@then('"mycroft-alarm" should stop beeping and start beeping again in 5 minutes')
def then_stop_and_start_beeping(context):
start_time = time.time()
got_msg = False

# drain any existing messages
for message in context.bus.get_messages('mycroft.alarm.beeping'):
pass

ctr = 0
while ctr < 7 and not got_msg:
time.sleep(60)

# wait for msg = beeping
for message in context.bus.get_messages('mycroft.alarm.beeping'):
got_msg = True

ctr += 1

elapsed = time.time() - start_time
context.bus.clear_messages()
# TODO assert got msg and > 3 minutes!
#assert got_msg and elapsed > 3*60, "Error, did not get beeping message!"
assert got_msg, "Error, did not get beeping message!"