Skip to content

Commit

Permalink
move unittests to padacioso repo
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Oct 14, 2024
1 parent 01c3c53 commit 07ea433
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import unittest

from ovos_utils.messagebus import FakeBus

from ovos_bus_client.message import Message
from padacioso import IntentContainer
from padacioso.opm import PadaciosoPipeline


class UtteranceIntentMatchingTest(unittest.TestCase):
def get_service(self, fuzz=True):
intent_service = PadaciosoPipeline(FakeBus(), {"fuzz": fuzz})
# register test intents
filename = "/tmp/test.intent"
with open(filename, "w") as f:
f.write("this is a test\ntest the intent\nexecute test")
rxfilename = "/tmp/test2.intent"
with open(rxfilename, "w") as f:
f.write("tell me about {thing}\nwhat is {thing}")
data = {'file_name': filename, 'lang': 'en-US', 'name': 'test'}
intent_service.register_intent(Message("padatious:register_intent", data))
data = {'file_name': rxfilename, 'lang': 'en-US', 'name': 'test2'}
intent_service.register_intent(Message("padatious:register_intent", data))
return intent_service

def test_padacioso_intent(self):
intent_service = self.get_service(fuzz=False)

for container in intent_service.containers.values():
self.assertIsInstance(container, IntentContainer)

# exact match
intent = intent_service.calc_intent("this is a test", "en-US")
self.assertEqual(intent.name, "test")

# fuzzy match - failure case
intent = intent_service.calc_intent("this test", "en-US")
self.assertIsNone(intent)

# regex match
intent = intent_service.calc_intent("tell me about Mycroft", "en-US")
self.assertEqual(intent.name, "test2")
self.assertEqual(intent.matches, {'thing': 'Mycroft'})

# fuzzy regex match - failure case
utterance = "tell me everything about Mycroft"
intent = intent_service.calc_intent(utterance, "en-US")
self.assertIsNone(intent)

def test_padacioso_fuzz_intent(self):
intent_service = self.get_service(fuzz=True)

# fuzzy match - success
intent = intent_service.calc_intent("this is test", "en-US")
self.assertEqual(intent.name, "test")
self.assertTrue(intent.conf <= 0.8)

# fuzzy regex match - success
utterance = "tell me everything about Mycroft"
intent = intent_service.calc_intent(utterance, "en-US")
self.assertEqual(intent.name, "test2")
self.assertEqual(intent.matches, {'thing': 'Mycroft'})
self.assertEqual(intent.sent, utterance)
self.assertTrue(intent.conf <= 0.8)

0 comments on commit 07ea433

Please sign in to comment.