Passed
Push — development/test ( ce11cc...42d9fd )
by Daniel
03:05
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 os, FileOperations
6
from common.ParameterHandling import ParameterHandling
7
import unittest
8
9
10
class TestParameterHandling(unittest.TestCase):
11
12
    def test_interpret_known_expression(self):
13
        class_fo = FileOperations()
14
        # load testing values from JSON file
15
        # where all cases are grouped
16
        json_structure = class_fo.fn_open_file_and_get_content(
17
            os.path.join(os.path.dirname(__file__),  'expressions.json'))
18
        # flatten out all testing values
19
        pair_values = []
20
        for crt_list in json_structure.values():
21
            pair_values += crt_list
22
        # parse through all pair of values and run the test
23
        class_ph = ParameterHandling()
24
        for current_pair in pair_values:
25
            reference_format = '%Y-%m-%d'
26
            if 'reference_format' in current_pair:
27
                reference_format = current_pair['reference_format']
28
            reference_date = datetime.strptime(current_pair['reference_value'], reference_format)
29
            expression_parts = current_pair['expression'].split('_')
30
            if 'start-iso-weekday' not in current_pair:
31
                current_pair['start-iso-weekday'] = 1
32
            value_to_assert = class_ph.interpret_known_expression(
33
                reference_date, expression_parts, current_pair['start-iso-weekday'])
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