-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
92 lines (67 loc) · 4.54 KB
/
test.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
UnitTest Module
....................................................................................................
MIT License
Copyright (c) 2021-2023 AUT Iran, Mohammad H Forouhesh
Copyright (c) 2021-2022 MetoData.ai, Mohammad H Forouhesh
....................................................................................................
This module serves as unit testing for various functionalities in the code.
"""
import unittest
from tracking_policy_agendas.api import downloader
from tracking_policy_agendas.classifiers.pa_clf import PAClf
from tracking_policy_agendas.classifiers.xgb_clf import XgbClf
from tracking_policy_agendas.classifiers.naive_bayes_clf import GNBClf
from tracking_policy_agendas.classifiers.lasso_clf import LassoClf
class XgbTestCase(unittest.TestCase):
def setUp(self) -> None:
self.clf = XgbClf(text_array=None, labels=None, load_path='xgb_vaccine')
def test_xgb_api(self) -> None:
self.assertRaises(Exception, downloader, path='wrong-path')
def test_xgb_soundness(self) -> None:
self.assertEqual(self.clf['تزریق دوز سوم واکسن هم تصویب شد'], self.clf['کرونا با ماسک و واکسن هم از بین نمیرود'])
self.assertNotEqual(self.clf['واکسیناسیون عمومی کزاز در ریشه کنی این بیماری بسیار مثمر ثمر بوده است'],
self.clf['تزریق دوز سوم واکسن کرونا هم تصویب شد'])
def test_xgb_completeness(self) -> None:
self.assertEqual(self.clf.predict('دوز سوم واکسن کرونا'), 1)
self.assertEqual(self.clf['رئيسجمهور جمهوری اسلامی'], 0)
self.assertEqual(self.clf['بورس نماد اقتصاد بحران زدهی ایران'], 0)
class PATestCase(unittest.TestCase):
def setUp(self) -> None:
self.clf = PAClf(text_array=None, labels=None, load_path='pa_vaccine')
def test_pa_api(self) -> None:
self.assertRaises(Exception, downloader, path='wrong-path')
def test_pa_soundness(self) -> None:
self.assertEqual(self.clf['تزریق دوز سوم واکسن هم تصویب شد'],
self.clf['کرونا با ماسک و واکسن هم از بین نمیرود'])
self.assertNotEqual(self.clf['واکسیناسیون عمومی کزاز در ریشه کنی این بیماری بسیار مثمر ثمر بوده است'],
self.clf['تزریق دوز سوم واکسن کرونا هم تصویب شد'])
def test_pa_completeness(self) -> None:
self.assertEqual(self.clf.predict('دوز سوم واکسن کرونا'), 1)
self.assertEqual(self.clf['بورس نماد اقتصاد بحران زدهی ایران'], 0)
class LassoTestCase(unittest.TestCase):
def setUp(self) -> None:
self.clf = LassoClf(text_array=None, labels=None, load_path='lasso_vaccine')
def test_lasso_api(self) -> None:
self.assertRaises(Exception, downloader, path='wrong-path')
def test_lasso_soundness(self) -> None:
self.assertEqual(self.clf['تزریق دوز سوم واکسن هم تصویب شد'],
self.clf['کرونا با ماسک و واکسن هم از بین نمیرود'])
self.assertNotEqual(self.clf['واکسیناسیون عمومی کزاز در ریشه کنی این بیماری بسیار مثمر ثمر بوده است'],
self.clf['تزریق دوز سوم واکسن کرونا هم تصویب شد'])
def test_lasso_completeness(self) -> None:
self.assertEqual(self.clf.predict('دوز سوم واکسن کرونا'), 1)
class GNBTestCase(unittest.TestCase):
def setUp(self) -> None:
self.clf = GNBClf(text_array=None, labels=None, load_path='gnb_vaccine')
def test_gnb_api(self) -> None:
self.assertRaises(Exception, downloader, path='wrong-path')
def test_gnb_soundness(self) -> None:
self.assertEqual(self.clf['تزریق دوز سوم واکسن کرونا هم تصویب شد'],
self.clf['کرونا با ماسک و واکسن هم از بین نمیرود'])
def test_gnb_completeness(self) -> None:
self.assertEqual(self.clf.predict('دوز سوم واکسن کرونا'), 1)
self.assertEqual(self.clf['رئيسجمهور جمهوری اسلامی'], 0)
self.assertEqual(self.clf['بورس نماد اقتصاد بحران زدهی ایران'], 0)
if __name__ == '__main__':
unittest.main()