-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest_skills_util.py
More file actions
94 lines (80 loc) · 3.05 KB
/
test_skills_util.py
File metadata and controls
94 lines (80 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import unittest
import json
from assistant_skill_analysis.utils import skills_util, lang_utils
class TestSkillsUtil(unittest.TestCase):
"""Test for skills utils module"""
@classmethod
def setUpClass(cls):
cls.skill_file = open(
"tests/resources/test_workspaces/skill-Customer-Care-Sample.json", "r"
)
cls.action_skill_file = open(
"tests/resources/test_workspaces/customer_care_sample_action_skill.json",
"r",
)
cls.lang_util = lang_utils.LanguageUtility("en")
def test_extract_action_workspace_data(self):
skill_json = json.load(self.action_skill_file)
(
workspace_pd,
workspace_vocabulary,
entities,
intent_action_map,
) = skills_util.extract_workspace_data(skill_json, self.lang_util)
self.assertTrue(workspace_pd is not None, "Extract workspace failed")
self.assertEqual(
len(workspace_pd["intent"].unique()), 7, "Extract workspace failed"
)
# check correct number of entities parsed
self.assertEqual(7, len(entities))
# check intent to action mapping working expectedly
self.assertEqual(
"Where are you located?", intent_action_map["action_11419_intent_44259"]
)
self.assertEqual("Thank you", intent_action_map["action_12038_intent_13364"])
self.assertEqual("Goodbye", intent_action_map["action_22890_intent_48257"])
self.assertEqual(
"Schedule An Appointment", intent_action_map["action_27164_intent_22860"]
)
self.assertEqual(
"What are your hours?", intent_action_map["action_33190_intent_33203"]
)
self.assertEqual(
"What can I do?", intent_action_map["action_5042_intent_38841"]
)
self.assertEqual("Fallback", intent_action_map["fallback_connect_to_agent"])
def test_extract_workspace_data(self):
skill_json = json.load(self.skill_file)
workspace_pd, workspace_vocabulary, _, _ = skills_util.extract_workspace_data(
skill_json, self.lang_util
)
self.assertTrue(workspace_pd is not None, "Extract workspace failed")
self.assertEqual(
len(workspace_pd["intent"].unique()), 9, "Extract workspace failed"
)
def test_parse_intent_from_action_condition(self):
data = {
"intent": "action_10017_intent_27671"
}
self.assertEqual(
skills_util._get_intent_name_from_action_condition(data), "action_10017_intent_27671"
)
data = {
"and": [
{
"intent": "action_15841_intent_20012"
},
{
"expression": "false"
}
]
}
self.assertEqual(
skills_util._get_intent_name_from_action_condition(data), "action_15841_intent_20012"
)
@classmethod
def tearDownClass(cls):
cls.skill_file.close()
cls.action_skill_file.close()
if __name__ == "__main__":
unittest.main()