forked from paulovn/python-aiml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_encoding.py
More file actions
49 lines (36 loc) · 1.47 KB
/
test_encoding.py
File metadata and controls
49 lines (36 loc) · 1.47 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
# -*- coding: utf-8 -*-
from __future__ import print_function
import time
import os.path
import unittest
import sys
from aiml import Kernel
class TestEncoding( unittest.TestCase ):
longMessage = True
def setUp(self):
self.k = Kernel()
self.k.bootstrap( learnFiles='encoding.aiml',
chdir=os.path.dirname(__file__) )
def tearDown(self):
del self.k
def _testTag(self, input_, outputList, name=None):
"""Test by feeding the Kernel 'input'. If the result
matches any of the strings in 'outputList', the test passes.
"""
print( "Testing <" + (name or input_) + ">", end='\n' )
response = self.k._cod.dec( self.k.respond( self.k._cod.enc(input_) ) )
self.assertIn( response, outputList, msg="input=%s"%input_ )
def test01_utf8( self ):
'''Test literal pattern'''
self._testTag( u'pattern with eñe', [u"pattern #1 matched!"])
def test02_utf8( self ):
'''Test star pattern'''
self._testTag( u'pattern with Á', [u"pattern #2 matched: Á"])
def test03_noencoding( self ):
'''Test unencoded strings'''
self.k.setTextEncoding( False )
self._testTag( u'pattern with eñe', [u"pattern #1 matched!"])
self._testTag( u'pattern with Á', [u"pattern #2 matched: Á"])
def test04_iso8859( self ):
self.k.setTextEncoding( 'iso-8859-1' )
self._testTag( u'pattern with Á', [u"pattern #2 matched: Á"])