-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
53 lines (44 loc) · 1.41 KB
/
tests.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
import unittest
import pandas as pd
import pandas.util.testing as pdt
from utils import Formatter
# utils
class TestFormatter(unittest.TestCase):
def setUp(self):
self.string_as_list = """R80b,R80b
680
2
R87,R88,R89
1k
3
R2,R5,R8
1.8k
24"""
self.correct = [
'R80b,R80b', '680', '2',
'R87,R88,R89', '1k', '3',
'R2,R5,R8', '1.8k', '24'
]
self.df = pd.DataFrame(
data={
'Location': ['R80b,R80b', 'R87,R88,R89', 'R2,R5,R8'],
'Part': ['680', '1k', '1.8k'],
'Quantity': ['2', '3', '24']
}
)
def test_to_list(self):
"""Test string is properly split into list."""
result = Formatter.to_list(self.string_as_list)
self.assertEqual(result, self.correct)
def test_to_list_as_string(self):
"""Test string is properly split into joined list as type str."""
correct = ' '.join(self.correct)
result = Formatter.to_list(self.string_as_list, as_string=True)
self.assertEqual(result, correct)
self.assertIsInstance(result, str)
def test_create_frame(self):
"""Test correct DataFrame is produced."""
result = Formatter.create_frame(self.string_as_list)
pdt.assert_frame_equal(result, self.df)
if __name__ == '__main__':
unittest.main()