[383a81]: / development / testcase / simple_test.py

Download this file

77 lines (65 with data), 2.8 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
import os
import sys
import random
import string
import asyncio
import unittest
from rasa.model import get_model
from rasa.nlu.test import run_evaluation
from rasa.core.test import test as core_test
path = './production/rasa-server/rasa/'
sys.path.append(path)
class TestRasaMethods(unittest.TestCase):
model_path = './production/rasa-server/rasa/models/'
unpacked_model = get_model(model_path)
tmp_name = ''.join(random.choices(
string.ascii_uppercase + string.digits, k=10))
"""
NLU TEST
"""
nlu_model = os.path.join(unpacked_model, "nlu")
# Normal NLU tests data
test_data = './development/testcase/nlu_test.yml'
async_test_result = run_evaluation(test_data,
nlu_model,
successes=True,
errors=True,
output_directory=f'/tmp/{tmp_name}',
disable_plotting=True,
report_as_dict=True,
)
test_result = asyncio.run(async_test_result)
# Test f1_score of intents
def test_f1_intent(self):
threshold = 1
test_result = self.test_result
# Check if intent extractor is in the pipeline
if test_result['intent_evaluation'] is not None:
# Check if multiple intent extractors are in the pipeline
if 'report' not in test_result['intent_evaluation']:
for intent in test_result['intent_evaluation']:
f1_score = test_result['intent_evaluation'][intent]['f1_score']
print(f1_score)
self.assertTrue(f1_score >= threshold)
else:
f1_score = test_result['intent_evaluation']['f1_score']
print(f1_score)
self.assertTrue(f1_score >= threshold)
# Test f1_score of entities
def test_f1_entity(self):
threshold = 1
test_result = self.test_result
# Check if entity extractor is in the pipeline
if test_result['entity_evaluation'] is not None:
# Check if multiple entity extractors are in the pipeline
if 'report' not in test_result['entity_evaluation']:
f1_score = test_result['entity_evaluation']['RegexEntityExtractor']['f1_score']
print(f1_score)
self.assertTrue(f1_score >= threshold)
else:
f1_score = test_result['entity_evaluation']['f1_score']
print(f1_score)
self.assertTrue(f1_score >= threshold)
if __name__ == '__main__':
# Run tests
unittest.main()