Coverage for test/end2end/test_cancel_plugin.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-17 13:44 +0000

1from unittest import TestCase 

2 

3from ovos_bus_client.message import Message 

4from ovos_bus_client.session import Session 

5from ovos_utils.log import LOG 

6from ovoscope import End2EndTest, get_minicroft 

7 

8 

9class TestCancelIntentMidSentence(TestCase): 

10 

11 def setUp(self): 

12 LOG.set_level("DEBUG") 

13 self.skill_id = "ovos-skill-hello-world.openvoiceos" 

14 self.minicroft = get_minicroft([self.skill_id]) 

15 

16 def tearDown(self): 

17 if self.minicroft: 

18 self.minicroft.stop() 

19 LOG.set_level("CRITICAL") 

20 

21 def test_cancel_match(self): 

22 session = Session("123") 

23 session.lang = "en-US" 

24 message = Message("recognizer_loop:utterance", 

25 {"utterances": ["can you tell me the...ummm...oh, nevermind that"], "lang": session.lang}, 

26 {"session": session.serialize(), "source": "A", "destination": "B"}) 

27 

28 # utterance cancelled -> no complete_intent_failure 

29 test = End2EndTest( 

30 minicroft=self.minicroft, 

31 skill_ids=[self.skill_id], 

32 source_message=message, 

33 final_session=session, 

34 expected_messages=[ 

35 message, 

36 Message("mycroft.audio.play_sound", {"uri": "snd/cancel.mp3"}), 

37 Message("ovos.utterance.cancelled", {}), 

38 Message("ovos.utterance.handled", {}), 

39 

40 ] 

41 ) 

42 

43 test.execute(timeout=10) 

44 

45 # ensure hello world doesnt match either 

46 message = Message("recognizer_loop:utterance", 

47 {"utterances": ["hello world cancel command"], "lang": "en-US"}, 

48 {"session": session.serialize(), "source": "A", "destination": "B"}) 

49 

50 test = End2EndTest( 

51 minicroft=self.minicroft, 

52 skill_ids=[self.skill_id], 

53 source_message=message, 

54 expected_messages=[ 

55 message, 

56 Message("mycroft.audio.play_sound", {"uri": "snd/cancel.mp3"}), 

57 Message("ovos.utterance.cancelled", {}), 

58 Message("ovos.utterance.handled", {}), 

59 

60 ] 

61 ) 

62 

63 test.execute(timeout=10) 

64