Coverage for test/end2end/test_lang_detect.py: 100%
49 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
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 TestLangDisambiguation(TestCase):
12 def setUp(self):
13 LOG.set_level("DEBUG")
14 self.minicroft = get_minicroft([]) # reuse for speed, but beware if skills keeping internal state
16 def tearDown(self):
17 if self.minicroft:
18 self.minicroft.stop()
19 LOG.set_level("CRITICAL")
21 def test_stt_lang(self):
22 session = Session("123")
23 session.lang = "en-US"
24 message = Message("recognizer_loop:utterance",
25 {"utterances": ["hello world"], "lang": session.lang},
26 {"session": session.serialize()})
27 lang_keys = {
28 "stt_lang": "ca-ES", # lang detection from audio plugin
29 "request_lang": "pt-PT", # lang tagged in source message (wake word config)
30 "detected_lang": "nl-NL" # lang detection from utterance (text) plugin
31 }
32 message.context.update(lang_keys)
33 message.context["valid_langs"] = list(lang_keys.values())
34 test = End2EndTest(
35 minicroft=self.minicroft,
36 skill_ids=[],
37 eof_msgs=["ovos.utterance.handled"],
38 flip_points=["recognizer_loop:utterance"],
39 source_message=message,
40 expected_messages=[
41 message,
42 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
43 Message("complete_intent_failure", {"lang": lang_keys["stt_lang"]}),
44 Message("ovos.utterance.handled", {}),
45 ]
46 )
48 test.execute()
51 def test_lang_text_detection(self):
52 session = Session("123")
53 session.lang = "en-US"
54 message = Message("recognizer_loop:utterance",
55 {"utterances": ["hello world"], "lang": session.lang},
56 {"session": session.serialize()})
57 lang_keys = {
58 "detected_lang": "nl-NL" # lang detection from utterance (text) plugin
59 }
60 message.context.update(lang_keys)
61 message.context["valid_langs"] = list(lang_keys.values())
62 test = End2EndTest(
63 minicroft=self.minicroft,
64 skill_ids=[],
65 eof_msgs=["ovos.utterance.handled"],
66 flip_points=["recognizer_loop:utterance"],
67 source_message=message,
68 expected_messages=[
69 message,
70 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
71 Message("complete_intent_failure", {"lang": lang_keys["detected_lang"]}),
72 Message("ovos.utterance.handled", {}),
73 ]
74 )
76 test.execute()
78 def test_metadata_preferred_over_text_detection(self):
79 session = Session("123")
80 session.lang = "en-US"
81 message = Message("recognizer_loop:utterance",
82 {"utterances": ["hello world"], "lang": session.lang},
83 {"session": session.serialize()})
84 lang_keys = {
85 "request_lang": "pt-PT", # lang tagged in source message (wake word config)
86 "detected_lang": "nl-NL" # lang detection from utterance (text) plugin
87 }
88 message.context.update(lang_keys)
89 message.context["valid_langs"] = list(lang_keys.values())
90 test = End2EndTest(
91 minicroft=self.minicroft,
92 skill_ids=[],
93 eof_msgs=["ovos.utterance.handled"],
94 flip_points=["recognizer_loop:utterance"],
95 source_message=message,
96 expected_messages=[
97 message,
98 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
99 Message("complete_intent_failure", {"lang": lang_keys["request_lang"]}),
100 Message("ovos.utterance.handled", {}),
101 ]
102 )
104 test.execute()
106 def test_invalid_lang_detection(self):
107 session = Session("123")
108 session.lang = "en-US"
109 message = Message("recognizer_loop:utterance",
110 {"utterances": ["hello world"], "lang": session.lang},
111 {"session": session.serialize()})
112 lang_keys = {
113 "detected_lang": "nl-NL"
114 }
115 message.context.update(lang_keys)
116 message.context["valid_langs"] = [session.lang] # no nl-NL
117 test = End2EndTest(
118 minicroft=self.minicroft,
119 skill_ids=[],
120 eof_msgs=["ovos.utterance.handled"],
121 flip_points=["recognizer_loop:utterance"],
122 source_message=message,
123 expected_messages=[
124 message,
125 Message("mycroft.audio.play_sound", {"uri": "snd/error.mp3"}),
126 Message("complete_intent_failure", {"lang": session.lang}),
127 Message("ovos.utterance.handled", {}),
128 ]
129 )
131 test.execute()