Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # useful methods to measure time performance by small pieces of code |
||
2 | from codetiming import Timer |
||
3 | # package facilitating Data Frames manipulation |
||
4 | import pandas |
||
5 | from sources.common.FileOperations import FileOperations |
||
6 | from common.LoggingNeeds import LoggingNeeds |
||
7 | from common.DataManipulator import DataManipulator |
||
8 | import unittest |
||
9 | import re |
||
10 | |||
11 | |||
12 | class TestDataManipulator(unittest.TestCase): |
||
13 | |||
14 | def test_add_and_shift_column(self): |
||
15 | class_ln = LoggingNeeds() |
||
16 | class_ln.initiate_logger('None', __file__) |
||
17 | timer = Timer(__file__, text='Time spent is {seconds}', logger=class_ln.logger.debug) |
||
18 | class_fo = FileOperations() |
||
19 | # load testing values from JSON file where all cases are grouped |
||
20 | json_structure = class_fo.fn_open_file_and_get_content('series.json') |
||
21 | for crt_series in json_structure: |
||
22 | in_data_frame = pandas.DataFrame(crt_series['Given']) |
||
23 | class_dm = DataManipulator() |
||
24 | out_data_frame = class_dm.fn_add_and_shift_column(class_ln.logger, timer, in_data_frame, [ |
||
25 | crt_series['Parameters'] |
||
26 | ]) |
||
27 | out_data_frame[['Column_New']] = out_data_frame[['Column_New']]\ |
||
28 | .apply(lambda x: int(x) if re.match('^[+-]*[0-9]+(\.{1}0*)*$', str(x)) else x) |
||
29 | expected_data_frame = pandas.DataFrame(crt_series['Expected']) |
||
30 | self.assertDictEqual(out_data_frame.to_dict(), expected_data_frame.to_dict()) |
||
31 |