def test_volume(self, start_blocking, makeVolumioApiCall): volumio = Volumio() hermes = Mock() custom_slot_value = CustomValue("50") slot_value = SlotValue(1, custom_slot_value) nlu_slot = NluSlot(1, slot_value, "fünfzig", "volume", "volume", 15, 22) slots_list = SlotsList() slots_list.append(nlu_slot) slot_map = dict([(nlu_slot.slot_name, slots_list)]) slots = SlotMap(slot_map) intent_message = IntentMessage( "testId", [], "testSiteId", "lautstärke auf fünfzig", IntentClassifierResult("Hodor:Volume", 1), slots) volumio.master_intent_callback(hermes, intent_message) hermes.publish_end_session.assert_called_once_with("testId", "") hermes.publish_start_session_notification.assert_called_once_with( "testSiteId", "Ok, Lautstärke ist jetzt bei 50", "")
def test_helper_method_access(): from hermes_python.ontology.dialogue import SlotsList, NluSlot, SlotMap, SlotValue, CustomValue custom_value_slot = CustomValue("Hello world") nlu_slot = NluSlot(0.1, SlotValue(1, custom_value_slot), "test", "test", "test_slot", 0, 0) slots = SlotMap({"test_slot": SlotsList()}) slots.test_slot.append(nlu_slot) assert type(slots.test_slot.first()) is CustomValue
def test_get_date_from_intent_without_date(self): """ Test whether the function get_date returns an empty string if an intent doesn't contain a date. """ slot_map = SlotMap({}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening", intent, slot_map) self.assertEqual(tools.get_date(intent_message), "")
def test_get_date_from_intent_with_time(self): """ Test whether the function get_date returns the data in the intent if it contains an instant time value. """ calendar_date_value = InstantTimeValue("2018-10-31 00:00:00" " +01:00", "grain", "precision") slot_map = SlotMap( {"calendar_date": SlotsList([NluSlot(calendar_date_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening today", intent, slot_map) self.assertEqual(tools.get_date(intent_message), "20181031")
def test_get_calendar_from_intent_without_calendar(self): """ Test whether the function get_calendar returns the default calendar if the intent doesn't have a calendar. """ slot_map = SlotMap({}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening today", intent, slot_map) # No calendar in intent message, no default calendar # -> no calendar self.assertEqual(tools.get_calendar(intent_message, ""), "") # No calendar in intent message, default calendar thai # -> default calendar thai self.assertEqual(tools.get_calendar(intent_message, "thai"), "thai")
def test_get_date_from_intent_with_interval(self): """ Test whether the function get_date returns the start date in the intent if it contains a time interval. """ calendar_date_value = TimeIntervalValue( "2018-11-05 18:00:00" " +01:00", "2018-11-06 00:00:00" " +01:00") slot_map = SlotMap( {"calendar_date": SlotsList([NluSlot(calendar_date_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening this night", intent, slot_map) self.assertEqual(tools.get_date(intent_message), "20181105")
def test_get_calendar_from_intent_with_calendar(self): """ Test whether the function get_calendar returns the calendar in the intent, even if a default calendar is set. """ calendar_file_value = CustomValue("computer") slot_map = SlotMap( {"calendar_file": SlotsList([NluSlot(calendar_file_value)])}) intent = IntentClassifierResult("koan:Event", 1.0) intent_message = IntentMessage("session_id", "custom_data", "site_id", "what is happening today in computers", intent, slot_map) # Calendar computer in intent message, no default calendar # -> calendar computer self.assertEqual(tools.get_calendar(intent_message, ""), "computer") # Calendar computer in intent message, default calendar thai # -> calendar computer self.assertEqual(tools.get_calendar(intent_message, "thai"), "computer")