Coverage for test/end2end/test_adapt.py: 100%
47 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-17 13:44 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-17 13:44 +0000
1from unittest import TestCase
2from copy import deepcopy
3from ovos_bus_client.message import Message
4from ovos_bus_client.session import Session
5from ovos_utils.log import LOG
7from ovoscope import End2EndTest, get_minicroft
10class TestAdaptIntent(TestCase):
12 def setUp(self):
13 LOG.set_level("DEBUG")
14 self.skill_id = "ovos-skill-hello-world.openvoiceos"
15 self.minicroft = get_minicroft([self.skill_id]) # reuse for speed, but beware if skills keeping internal state
17 def tearDown(self):
18 if self.minicroft:
19 self.minicroft.stop()
20 LOG.set_level("CRITICAL")
22 def test_adapt_match(self):
23 session = Session("123")
24 session.lang = "en-US"
25 session.pipeline = ['ovos-adapt-pipeline-plugin-high']
26 message = Message("recognizer_loop:utterance",
27 {"utterances": ["hello world"], "lang": session.lang},
28 {"session": session.serialize(), "source": "A", "destination": "B"})
30 final_session = deepcopy(session)
31 final_session.active_skills = [(self.skill_id, 0.0)]
33 test = End2EndTest(
34 minicroft=self.minicroft,
35 skill_ids=[self.skill_id],
36 source_message=message,
37 final_session=final_session,
38 activation_points=[f"{self.skill_id}:HelloWorldIntent"],
39 # keep_original_src=[f"{self.skill_id}.activate"], # TODO
40 expected_messages=[
41 message,
42 Message(f"{self.skill_id}.activate",
43 data={},
44 context={"skill_id": self.skill_id}),
45 Message(f"{self.skill_id}:HelloWorldIntent",
46 data={"utterance": "hello world", "lang": session.lang},
47 context={"skill_id": self.skill_id}),
48 Message("mycroft.skill.handler.start",
49 data={"name": "HelloWorldSkill.handle_hello_world_intent"},
50 context={"skill_id": self.skill_id}),
51 Message("speak",
52 data={"utterance": "Hello world",
53 "lang": session.lang,
54 "expect_response": False,
55 "meta": {
56 "dialog": "hello.world",
57 "data": {},
58 "skill": self.skill_id
59 }},
60 context={"skill_id": self.skill_id}),
61 Message("mycroft.skill.handler.complete",
62 data={"name": "HelloWorldSkill.handle_hello_world_intent"},
63 context={"skill_id": self.skill_id}),
64 Message("ovos.utterance.handled",
65 data={},
66 context={"skill_id": self.skill_id}),
67 ]
68 )
70 test.execute(timeout=10)
72 def test_skill_blacklist(self):
73 session = Session("123")
74 session.lang = "en-US"
75 session.pipeline = ['ovos-adapt-pipeline-plugin-high']
76 session.blacklisted_skills = [self.skill_id]
77 message = Message("recognizer_loop:utterance",
78 {"utterances": ["hello world"], "lang": session.lang},
79 {"session": session.serialize(), "source": "A", "destination": "B"})
81 test = End2EndTest(
82 minicroft=self.minicroft,
83 skill_ids=[self.skill_id],
84 source_message=message,
85 final_session=session,
86 expected_messages=[
87 message,
88 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
89 Message("complete_intent_failure", {}),
90 Message("ovos.utterance.handled", {})
91 ]
92 )
94 test.execute(timeout=10)
96 def test_intent_blacklist(self):
97 session = Session("123")
98 session.lang = "en-US"
99 session.pipeline = ['ovos-adapt-pipeline-plugin-high']
100 session.blacklisted_intents = [f"{self.skill_id}:HelloWorldIntent"]
101 message = Message("recognizer_loop:utterance",
102 {"utterances": ["hello world"], "lang": session.lang},
103 {"session": session.serialize(), "source": "A", "destination": "B"})
105 test = End2EndTest(
106 minicroft=self.minicroft,
107 skill_ids=[self.skill_id],
108 source_message=message,
109 final_session=session,
110 expected_messages=[
111 message,
112 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
113 Message("complete_intent_failure", {}),
114 Message("ovos.utterance.handled", {})
115 ]
116 )
118 test.execute(timeout=10)
120 def test_padatious_no_match(self):
121 session = Session("123")
122 session.lang = "en-US"
123 session.pipeline = ["ovos-padatious-pipeline-plugin-high"]
124 message = Message("recognizer_loop:utterance",
125 {"utterances": ["hello world"], "lang": session.lang},
126 {"session": session.serialize(), "source": "A", "destination": "B"})
128 test = End2EndTest(
129 minicroft=self.minicroft,
130 skill_ids=[self.skill_id],
131 final_session=session,
132 source_message=message,
133 expected_messages=[
134 message,
135 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
136 Message("complete_intent_failure", {}),
137 Message("ovos.utterance.handled", {})
138 ]
139 )
141 test.execute(timeout=10)