def then_messagebus_message(context, message_type): """Verify a specific message is sent.""" def check_dummy(message): """We are just interested in the message data, just the type.""" return True, "" message_found, _ = then_wait(message_type, check_dummy, context) assert message_found, "No matching message received."
def then_anything(context, skill): def check_any_messages(message): debug = '' result = message is not None return (result, debug) passed = then_wait('speak', check_any_messages, context) assert passed, 'No speech received at all'
def then_dialog(context, skill, dialog): def check_dialog(message): utt_dialog = message.data.get('meta', {}).get('dialog') return (utt_dialog == dialog.replace('.dialog', ''), '') passed, debug = then_wait('speak', check_dialog, context) if not passed: assert_msg = debug assert_msg += mycroft_responses(context) assert passed, assert_msg or 'Mycroft didn\'t respond'
def then_exactly(context, skill, text): def check_exact_match(message): utt = message.data['utterance'].lower() debug = 'Comparing {} with expected {}\n'.format(utt, text) result = utt == text.lower() return (result, debug) passed, debug = then_wait('speak', check_exact_match, context) if not passed: assert_msg = debug assert_msg += mycroft_responses(context) assert passed, assert_msg
def then_url_opened(context, url): def check_url_in_msg(message): success = message.data.get('site_url') == url debug_msg = "" if success else "Incorrect url" return (success, debug_msg) passed, debug = then_wait('skill.weblauncher.opening', check_url_in_msg, context) if not passed: assert_msg = debug assert_msg += mycroft_responses(context) assert passed, assert_msg or "Web Launcher did not open the url"
def then_contains(context, text): def check_contains(message): utt = message.data['utterance'].lower() debug = 'Checking if "{}" contains "{}"\n'.format(utt, text) result = text.lower() in utt return (result, debug) passed, debug = then_wait('speak', check_contains, context) if not passed: assert_msg = 'No speech contained the expected content' assert_msg += mycroft_responses(context) assert passed, assert_msg