-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest__checkers.py
65 lines (40 loc) · 1.77 KB
/
test__checkers.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
import unittest
from unittest.mock import MagicMock
import pandas as pd
from cfnow._checkers import _check_factual, _check_vars, _check_prob_func
class TestScriptBase(unittest.TestCase):
def test__check_factual_not_pd_series(self):
factual = [0, 1, 2, 3, 4]
with self.assertRaises(TypeError):
_check_factual(factual)
def test__check_factual_is_pd_series(self):
factual = pd.Series([0, 1, 2, 3, 4])
_check_factual(factual)
def test__check_vars_missing_factual_and_feat_types(self):
factual = pd.Series({'a': 1, 'c': 1})
feat_types = {'a': 'num', 'b': 'num'}
with self.assertRaises(AssertionError):
_check_vars(factual, feat_types)
def test__check_vars_missing_factual(self):
factual = pd.Series({'a': 1})
feat_types = {'a': 'num', 'b': 'num'}
with self.assertRaises(AssertionError):
_check_vars(factual, feat_types)
def test__check_vars_missing_feat_types(self):
factual = pd.Series({'a': 1, 'c': 1})
feat_types = {'a': 'num'}
with self.assertRaises(AssertionError):
_check_vars(factual, feat_types)
def test__check_vars_correct(self):
factual = pd.Series({'a': 1, 'b': 1, 'c': 1})
feat_types = {'a': 'num', 'b': 'num', 'c': 'num'}
_check_vars(factual, feat_types)
def test__check_prob_func_error(self):
factual = pd.Series({'a': 1, 'b': 1})
model_predict_proba = MagicMock()
model_predict_proba.side_effect = Exception()
with self.assertRaises(Exception):
_check_prob_func(factual, model_predict_proba)
def test__check_prob_func_correct(self):
factual = pd.Series({'a': 1, 'b': 1})
model_predict_proba = MagicMock()