tests.RequestHandlerTest.testWrongSentence()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1
Metric Value
cc 1
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 1
rs 9.4286
1 1
from unittest import TestCase
2 1
from ppp_datamodel.communication import Request
3 1
from ppp_datamodel import Triple, Resource, Missing, Sentence
4 1
from ppp_libmodule.tests import PPPTestCase
5
6 1
from ppp_spell_checker import app
7
8 1
class RequestHandlerTest(PPPTestCase(app)):
9 1
    def testCorrectSentence(self):
10 1
        original = 'Who is the president of the United States?'
11 1
        j = {'id': '1', 'language': 'en', 'measures': {}, 'trace': [],
12
             'tree': {'type': 'sentence', 'value': original}}
13 1
        answer = self.request(j)
14 1
        self.assertEqual(len(answer), 0, answer)
15
16 1
    def testWrongSentence(self):
17 1
        original = 'Who is the pesident of the United States?'
18 1
        expected = 'Who is the president of the United States?'
19 1
        j = {'id': '1', 'language': 'en', 'measures': {}, 'trace': [],
20
             'tree': {'type': 'sentence', 'value': original}}
21 1
        answer = self.request(j)
22 1
        self.assertEqual(len(answer), 1, answer)
23 1
        self.assertEqual(answer[0].tree, Sentence(value=expected))
24 1
        self.assertEqual(answer[0].measures['relevance'],1/8)
25 1
        self.assertEqual(answer[0].language,'en')
26
27 1
    def testOtherLanguage(self):
28 1
        original = 'ornithorinque'
29 1
        expected = 'ornithorynque'
30 1
        j = {'id': '1', 'language': 'fr', 'measures': {}, 'trace': [],
31
            'tree': {'type': 'sentence', 'value': original}}
32 1
        answer = self.request(j)
33 1
        self.assertEqual(len(answer), 1, answer)
34 1
        self.assertEqual(answer[0].tree, Sentence(value=expected))
35 1
        self.assertEqual(answer[0].language,'fr')
36
37 1
    def testIrrelevantInput(self):
38 1
        original = 'Who is the president of the United States?'
39 1
        j = {'id': '1', 'language': 'en', 'measures': {}, 'trace': [],
40
             'tree': {'type': 'resource', 'value': original}}
41 1
        answer = self.request(j)
42
        self.assertEqual(len(answer), 0, answer)
43