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_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_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_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 = ["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_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_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 process_command(interaction_service: UserInteractionServiceBase, optional_message: str = None): """Processes a command, either supplied as a parameter or obtained from user interaction.""" if optional_message: sentence = optional_message print(f"Text input provided: {optional_message}") else: (success, sentence) = interaction_service.greet_user_and_ask_for_command( settings.username.capitalize()) if not success: interaction_service.tell_user_could_not_be_heard(speak_service) return ud = Parse(sentence) if not assistantdb.identify_and_run_command(ud, interaction_service): interaction_service.tell_user_command_was_not_understood(speak_service)
def process_command(services: AssistantServicesBase, optional_message: str = None, verbose: bool = False): """Processes a command, either supplied as a parameter or obtained from user interaction.""" if optional_message: sentence = optional_message print(f"Text input provided: {optional_message}") else: (success, sentence ) = services.user_interaction_service.greet_user_and_ask_for_command( services.settings_service.username.capitalize()) if not success: services.user_interaction_service.tell_user_could_not_be_heard() return ud = Parse(sentence) if not skill_selection.identify_and_run_command(sentence, ud, services, verbose): services.user_interaction_service.tell_user_command_was_not_understood( )
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.")