forked from jbesomi/texthero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.py
76 lines (53 loc) · 1.62 KB
/
test_helpers.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
"""
Unit-tests for the helper module.
"""
import pandas as pd
import numpy as np
from . import PandasTestCase
import doctest
import unittest
import warnings
from texthero import _helper
"""
Doctests.
"""
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(_helper))
return tests
"""
Test Decorators.
"""
class TestHelpers(PandasTestCase):
"""
handle_nans.
"""
def test_handle_nans(self):
s = pd.Series(["Test", np.nan, pd.NA])
@_helper.handle_nans(replace_nans_with="This was a NAN")
def f(s):
return s
s_true = pd.Series(["Test", "This was a NAN", "This was a NAN"])
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.assertEqual(f(s), s_true)
with self.assertWarns(Warning):
f(s)
def test_handle_nans_no_nans_in_input(self):
s = pd.Series(["Test"])
@_helper.handle_nans(replace_nans_with="This was a NAN")
def f(s):
return s
s_true = pd.Series(["Test"])
self.assertEqual(f(s), s_true)
# This is not in test_indexes.py as it requires a custom test case.
def test_handle_nans_index(self):
s = pd.Series(["Test", np.nan, pd.NA], index=[4, 5, 6])
@_helper.handle_nans(replace_nans_with="This was a NAN")
def f(s):
return s
s_true = pd.Series(
["Test", "This was a NAN", "This was a NAN"], index=[4, 5, 6]
)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.assertTrue(f(s).index.equals(s_true.index))