Passed
Push — development/test ( 24302c...f5ca2a )
by Daniel
01:16
created

TestParameterHandling.test_interpret_known_expression()   A

Complexity

Conditions 4

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nop 1
dl 0
loc 25
rs 9.376
c 0
b 0
f 0
1
"""
2
Testing key methods from Parameter Handling class
3
"""
4
from datetime import datetime
5
from sources.common.BasicNeeds import BasicNeeds
6
from sources.common.FileOperations import FileOperations
7
from sources.db_extractor.ParameterHandling import ParameterHandling
8
import unittest
9
10
11
class TestParameterHandling(unittest.TestCase):
12
13
    def test_interpret_known_expression(self):
14
        fo = FileOperations()
15
        bn = BasicNeeds()
16
        # load testing values from JSON file
17
        # where all cases are grouped
18
        json_structure = fo.fn_open_file_and_get_content('expressions.json')
19
        # flatten out all testing values
20
        pair_values = []
21
        index_counter = 0
22
        for current_expression_group in json_structure.items():
23
            for current_expression in current_expression_group[1]:
24
                pair_values.append(index_counter)
25
                pair_values[index_counter] = current_expression
26
                index_counter += 1
27
        # parse through all pair of values and run the test
28
        ph = ParameterHandling()
29
        for current_pair in pair_values:
30
            reference_date = datetime.strptime(current_pair['reference_date'], '%Y-%m-%d')
31
            expression_parts = current_pair['expression'].split('_')
32
            value_to_assert = ph.interpret_known_expression(reference_date, expression_parts, 1)
33
            self.assertEqual(value_to_assert, current_pair['expected'],
34
                             'Provided value was "' + current_pair['reference_date']
35
                             + '", Expression was "' + current_pair['expression'] + '" '
36
                             + '", Expected was "' + current_pair['expected'] + '" '
37
                             + 'but received was "' + value_to_assert + '"...')
38
39
40
if __name__ == '__main__':
41
    unittest.main()
42
43