-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
79 lines (62 loc) · 2.11 KB
/
Copy pathtesting.py
File metadata and controls
79 lines (62 loc) · 2.11 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
import unittest
import test, app
import nltk
from nltk.tokenize import word_tokenize
import json
class TestGetRAD(unittest.TestCase):
def test_word_classifier(self):
keyword = 'I coughed a lot and vomited. I also have a headache.'
words = word_tokenize(keyword)
# returns tag name of part of speech
tag_block = nltk.pos_tag(words)
print(tag_block)
# returns stemmed word
t = test.word_classify(tag_block[1][1], tag_block[1][0])
self.assertEqual(t, 'cough')
def test_return_value(self):
# returns 0 if argument is not symptom word
r = test.get_rad_value('happy')
self.assertEqual(r, 0)
# returns RAD value if argument is symptom word existed in dataset
r = test.get_rad_value('fever')
self.assertTrue(0 < r < 1)
class TestSteps(unittest.TestCase):
symptom_list = []
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def tearDown(self):
pass
def setUp(self):
# creates a test client
self.app = app.app.test_client()
# propagate the exceptions to the test client
self.app.testing = True
def test_step1(self):
symptom_string = 'I have a headache and cough.'
req = '/step1?symptom='
req += symptom_string
res = self.app.get(req)
self.symptom_list = json.loads(res.data)
# assert the response data
self.assertEqual(res.data, b'{"symptoms":["headache","cough"]}\n')
def test_step3(self):
self.symptom_list = ["headache", "cough"]
str = ''
for s in self.symptom_list:
str += s + ','
req = '/step3?symptom='
req += str
res = self.app.get(req)
rad_value = json.loads(res.data)
rad_value = rad_value['rad'][0]
rad_value = json.loads(rad_value)
for s in rad_value.keys():
# assert the RAD value of each symptom exists
# print(s, ': ', rad_value[s])
self.assertTrue(rad_value[s] > 0)
if __name__ == '__main__':
unittest.main()