concordia-preprocessor/tests/preprocess_tests.py
2019-06-26 12:17:07 +02:00

49 lines
2.1 KiB
Python
Executable File

#!/usr/bin/python3
import requests, json, unittest
class PreprocessorTest(unittest.TestCase):
preprocessor_url = 'http://127.0.0.1:10002/preprocess'
def do_preprocess(self, data):
response = requests.post(url = self.preprocessor_url, json = data)
return json.loads(response.text)
def testAgltWithLemmatization(self):
data = {'language':'pl', 'lemmatize':True, 'sentences':['naprawiłeś już samochody?']}
result = self.do_preprocess(data)['processed_sentences'][0]
self.assertEqual(result['normalized'],'naprawiłeś już samochody?')
self.assertEqual(result['tokens'],'naprawić już samochód')
self.assertEqual(result['borders'], [0, 10, 11, 14, 15, 24])
def testAgltWithoutLemmatization(self):
data = {'language':'pl', 'lemmatize':False, 'sentences':['naprawiłeś już samochody?']}
result = self.do_preprocess(data)['processed_sentences'][0]
self.assertEqual(result['normalized'],'naprawiłeś już samochody?')
self.assertEqual(result['tokens'],'naprawiłeś już samochody')
self.assertEqual(result['borders'], [0, 10, 11, 14, 15, 24])
def testIncompleteRequestLanguage(self):
data = {'lemmatize':False, 'sentences':['naprawiłeś już samochody?']}
response = requests.post(url = self.preprocessor_url, json = data)
self.assertEqual(response.status_code, 400)
json_result = json.loads(response.text)
self.assertEqual(json_result['error'], 'Missing parameter: language')
def testIncompleteRequestLemmatize(self):
data = {'language':'pl', 'sentences':['naprawiłeś już samochody?']}
response = requests.post(url = self.preprocessor_url, json = data)
self.assertEqual(response.status_code, 400)
json_result = json.loads(response.text)
self.assertEqual(json_result['error'], 'Missing parameter: lemmatize')
def testIncompleteRequestSentences(self):
data = {'language':'pl', 'lemmatize':False}
response = requests.post(url = self.preprocessor_url, json = data)
self.assertEqual(response.status_code, 400)
json_result = json.loads(response.text)
self.assertEqual(json_result['error'], 'Missing parameter: sentences')
if __name__ == '__main__':
unittest.main()