Passed
Push — development/test ( 6383cd...222d55 )
by Daniel
02:57
created

TestParameterHandling   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

1 Method

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