def test_skillShouldOpenMailToWithRecipient(self, webbrowser_open_function): sentences = [ "compose an email to [email protected]", "email [email protected]", "send an email to [email protected]", "write an email to [email protected]" ] expected_url = "mailto:[email protected]" mock_user_interaction_service = create_autospec( spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"SendEmailSkill did not recognize sentence='{sentence}'\nud: {ud}" ) self.skill.execute_for_command(skill_input, mock_assistant_services) webbrowser_open_function.assert_called_with(expected_url)
def test_skillShouldRecognizeCommand(self): verbs = ["use"] for verb in verbs: ud = ParsedUniversalDependencies(verb=verb) skill_input = SkillInput(ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"ChangeAssistantVoiceSkill did not recognize verb='{verb}'")
def test_skillShouldRecognizeCommand(self): verbs = ["find", "where is"] for verb in verbs: ud = ParsedUniversalDependencies(verb=verb) skill_input = SkillInput(ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"RoomFinderSkill did not recognize verb='{verb}'")
def test_skillShouldRecognizeCommand(self): verbs = ["schedule", "remind", "remind about", "plan"] for verb in verbs: ud = ParsedUniversalDependencies(verb=verb) skill_input = SkillInput(ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"AddCalendarEventSkill did not recognize verb='{verb}'")
def test_skillShouldRecognizeSentence(self): sentences = ["use a male voice", "use a female voice"] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"ChangeAssistantVoiceSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldNotRecognizeSentencesAskingAboutCurrentSchedule(self): sentences = ["tell me my schedule", "what is my schedule"] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertFalse( self.skill.matches_command(skill_input), f"AddCalendarEventSkill recognized sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeSentence(self): sentences = [cmd + " https://www.ltu.edu/" for cmd in self.cmd_list] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"OpenWebsiteSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeSentence(self): sentences = ["tell me my schedule", "what is my schedule"] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"TellScheduleSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeSentenceWithoutRecipient(self): sentences = ["compose an email", "send an email", "write an email"] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"SendEmailSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeCommand(self): verbs = ["what is", "tell"] nouns = ["time"] for verb in verbs: for noun in nouns: ud = ParsedUniversalDependencies(verb=verb, noun=noun) skill_input = SkillInput(ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"TellTimeSkill did not recognize verb='{verb}' and noun='{noun}'")
def test_skillShouldRecognizeCommand(self): verbs = [ "email", "compose", "compose to", "send", "send to", "write", "write to" ] for verb in verbs: ud = ParsedUniversalDependencies(verb=verb) skill_input = SkillInput(ud, False) self.assertTrue(self.skill.matches_command(skill_input), f"SendEmailSkill did not recognize verb='{verb}'")
def test_skillShouldRecognizeSentence(self): sentences = [ "plan an event", "remind me about an event", "schedule an event" ] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"AddCalendarEventSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeCommand(self): verbs = [ "start", "open", "go", "go to", "browse", "browse to", "launch", "take to", "show" ] for verb in verbs: ud = ParsedUniversalDependencies(verb=verb) skill_input = SkillInput(ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"OpenWebsiteSkill did not recognize verb='{verb}'")
def test_skillShouldRecognizeSentence(self): sentences = [ "find A101", "find room A101", "where is A101", "where is room A101" ] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"RoomFinderSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRecognizeSentence(self): sentences = [ "call me Bob", "My name is Bob" ] for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) self.assertTrue( self.skill.matches_command(skill_input), f"ChangeUserNameSkill did not recognize sentence='{sentence}'\nud: {ud}" )
def test_skillShouldRejectMissingRoomNumber(self): sentence = "where is room" expected_output_speech = "Sorry, I don't think you provided me with a valid room number." ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) mock_user_interaction_service = create_autospec( spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service self.skill.execute_for_command(skill_input, mock_assistant_services) mock_assistant_services.user_interaction_service.speak.assert_called_with( expected_output_speech, False)
def test_skillShouldGiveCorrectOutput(self): sentence = "where is room A101" expected_output_speech = "Your room is in the Architecture Building on floor 1." ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) mock_user_interaction_service = create_autospec( spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service self.skill.execute_for_command(skill_input, mock_assistant_services) mock_assistant_services.user_interaction_service.speak.assert_called_with( expected_output_speech, False)
def test_skillShouldGreetUserWithNewName(self): sentence = "Call me Bob." expected_output_speech = "Pleased to meet you, Bob!" ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) mock_settings_services = create_autospec(spec=SettingsServiceBase) mock_user_interaction_service = create_autospec(spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.settings_service.return_value = mock_settings_services mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service self.skill.execute_for_command(skill_input, mock_assistant_services) mock_assistant_services.user_interaction_service.speak.assert_called_with(expected_output_speech, True)
def test_skillShouldSaveNewUsername(self): sentence = "Call me Bob." ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) mock_settings_services = create_autospec(spec=SettingsServiceBase) mock_user_interaction_service = create_autospec(spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.settings_service.return_value = mock_settings_services mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service self.skill.execute_for_command(skill_input, mock_assistant_services) # TODO: Figure out how to check that the property setter is being called with the expected value. # mock_assistant_services.settings_service.set_username.assert_called_with("Bob") mock_assistant_services.settings_service.save_settings.assert_called_with()
def identify_and_run_command(sentence: str, ud: ParsedUniversalDependencies, services: AssistantServicesBase, verbose: bool = False) -> bool: """Parse the command and take an action. Returns True if the command is understood, and False otherwise.""" skill_input = SkillInput(sentence, ud, verbose) # Print parameters for debugging purposes print(' * Universal dependencies:\n ' + (str(skill_input.dependencies) if skill_input.dependencies is not None else "(None)")) print(' * verb: ' + (skill_input.verb if skill_input.verb is not None else "(None)")) print(' * verb_object: ' + (skill_input.verb_object if skill_input.verb_object is not None else "(None)")) print(' * alternate_noun: ' + (skill_input.alternate_noun if skill_input.alternate_noun is not None else "(None)")) print(' * adjective: ' + (skill_input.adjective if skill_input.adjective is not None else "(None)")) skill = _select_skill_for_input(skill_input) if skill is not None: skill.execute_for_command(skill_input, services) return True return False
def identify_and_run_command( ud: ParsedUniversalDependencies, user_interaction_service: UserInteractionServiceBase, verbose: bool = False) -> bool: """Parse the command and take an action. Returns True if the command is understood, and False otherwise.""" skill_input = SkillInput(ud, verbose) # Print parameters for debugging purposes print('\tverb: ' + (skill_input.verb if skill_input.verb is not None else "(None)")) print('\tverb_object: ' + (skill_input.verb_object if skill_input. verb_object is not None else "(None)")) print('\talternate_noun: ' + (skill_input.alternate_noun if skill_input. alternate_noun is not None else "(None)")) print('\tadjective: ' + (skill_input.adjective if skill_input. adjective is not None else "(None)")) skill = _select_skill_for_input(skill_input) if skill is not None: skill.execute_for_command(skill_input, user_interaction_service) return True return False
def test_skillShouldOpenCorrectWebsites(self, webbrowser_open_function): failure_count = 0 mock_user_interaction_service = create_autospec( spec=UserInteractionServiceBase) mock_assistant_services = create_autospec(spec=AssistantServicesBase) mock_assistant_services.user_interaction_service.return_value = mock_user_interaction_service for website in self._supported_websites: sentences = [ cmd + " " + site_name for cmd in self.cmd_list for site_name in website.request_names ] expected_output_speech = f"Opening {website.site_name}..." for sentence in sentences: ud = Parse(sentence) skill_input = SkillInput(sentence, ud, False) try: self.assertTrue( self.skill.matches_command(skill_input), f"OpenWebsiteSkill did not recognize sentence='{sentence}'\nud: {ud}" ) self.skill.execute_for_command(skill_input, mock_assistant_services) mock_assistant_services.user_interaction_service.speak.assert_called_with( expected_output_speech, False) webbrowser_open_function.assert_called_with( website.site_url) except AssertionError as e: print( f"OpenWebsiteSkill did not recognize website name for sentence='{sentence}'\n\tud: {ud}\n{str(e)}" ) failure_count += 1 self.assertEqual( failure_count, 0, f"There were {str(failure_count)} failure(s) in this test.")